Trying to code an example algo after taking all of the boot camps.  I am stuck having a problem updating the rolling window with a consolidator bar.  I am getting a typeError which I assume means the consolidated bar doesn't match the "quotebar" attribute.    Am I correct?  If so, how would I go about fixing this?  Also another dumb question:  This example I am trying to edit here doesn't seem to parse the futures chain and pick the one with the most volume as the bootcamp example did.  How is the backtest working?   Thanks in advance!  

class BreakOutExample(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 12, 1) # Set Start Date
self.SetEndDate(2020, 12, 31) # Set End Date
self.SetCash(1000000) # Set Strategy Cash
# Subscribe and set our expiry filter for the futures chain
future = self.AddFuture(Futures.Indices.SP500EMini)
# future.SetFilter(timedelta(0), timedelta(182))
self.consolidators = dict()

self.window = RollingWindow[TradeBar](3)

dailyhigh = 0
dailylow = 0

def OnDataConsolidated(self, bar):
self.window.Add(bar.Symbol)
symbol = bar.Symbol
price = self.Securities[symbol].Close

#Debug Testing
#self.Debug(" Bar Close " + str(bar.High))
#self.Debug(" Bar Time Hour " + str(bar.Time.hour))
#self.Debug(" Bar Time Min " + str(bar.Time.minute))

dailyhigh = max(window[0].High, window[1].High, window[2].High)
self.Debug(" Daily High is now: " + str(dailyhigh))
dailylow = min(window[0].Low, window[1].Low, window[2].Low)
self.Debug(" Daily Low is now: " + str(dailylow))

if price >= dailyhigh:
self.SetHoldings(symbol, 1)
if price <= dailylow:
self.SetHoldings(symbol,-1)


def OnSecuritiesChanged(self, changes):
for security in changes.AddedSecurities:
symbol = security.Symbol
consolidator = self.Consolidate(symbol, timedelta(minutes=3), self.OnDataConsolidated)
self.consolidators[symbol] = consolidator

for security in changes.RemovedSecurities:
symbol = security.Symbol
consolidator = self.consolidators.pop(symbol)
self.SubscriptionManager.RemoveConsolidator(symbol, consolidator)
consolidator.DataConsolidated -= self.OnDataConsolidated
if security.Invested:
self.Liquidate(symbol, 'Remove from Futures Chains')

 

Author