Overall Statistics
Total Trades
73
Average Win
0%
Average Loss
-0.01%
Compounding Annual Return
-0.169%
Drawdown
0.500%
Expectancy
-1
Net Profit
-0.507%
Sharpe Ratio
-1.783
Probabilistic Sharpe Ratio
0.000%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.002
Beta
0
Annual Standard Deviation
0.001
Annual Variance
0
Information Ratio
-0.754
Tracking Error
0.228
Treynor Ratio
29.071
Total Fees
$73.00
import numpy as np
from clr import AddReference
AddReference("System")
AddReference("NodaTime")
AddReference("QuantConnect.Algorithm")
AddReference("QuantConnect.Indicators")
AddReference("QuantConnect.Common")
from datetime import datetime, timedelta
from System import *
from NodaTime import DateTimeZone
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Brokerages import *
from QuantConnect.Data.Market import *
from datetime import timedelta



class DataConsolidationAlgorithm(QCAlgorithm):
    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        self.SetCash(30000)
        self.StopRisk = 1
        
     
        if self.Portfolio.TotalUnrealizedProfit > 599.99: #take profit
           self.Liquidate()
           
        self.SetStartDate(2018,1,1)  #Set Start Date
        self.SetEndDate(2021,1,1)   #Set End Date
        # Find more symbols here: http://quantconnect.com/data
        self.AddEquity("BOXL", Resolution.Minute)
        self.ema = self.EMA("BOXL", 30,  MovingAverageType.Simple, Resolution.Minute)
        self.vwap = self.VWAP("BOXL", 30, Resolution.Minute)
        # define our 5 minute trade bar consolidator. we can
        # access the 5 minute bar from the DataConsolidated events
        fiveMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=5))

        # attach our event handler. The event handler is a function that will
        # be called each time we produce a new consolidated piece of data.
        
        # this call adds our 5-minute consolidator to
        # the manager to receive updates from the engine
        self.SubscriptionManager.AddConsolidator("BOXL", fiveMinuteConsolidator)

    def fiveMinuteBarHandler(self, sender, bar):
        '''This is our event handler for our 5-minute trade bar defined above in Initialize(). So each time the consolidator produces a new 5-minute bar, this function will be called automatically. The sender parameter will be the instance of the IDataConsolidator that invoked the event '''
        self.Debug(str(self.Time) + " " + str(bar))
    
    
    
    def OnData(self, data):
        if not self.ema.IsReady:
            return
        if not self.vwap.IsReady:
            return
        ema = self.ema.Current.Value
        vwap = self.vwap.Current.Value
        if ema > vwap and not self.Portfolio['BOXL'].IsLong:
            self.MarketOrder("BOXL",1)
        
        if ema < vwap and not self.Portfolio['BOXL'].IsShort:
            self.MarketOrder("BOXL",-1)