I have a consolidator tradeBar window (rollingBAR) that gets updated daily.
My strategy runs on a minute timeframe.
I want to run some logic before the market opens, so I scheduled an event 10 minutes before the market opens.
The problem comes when I try to evaluate the data on the tradeBar window. It seems gets updated with 1 day difference. So basically if I'm firing the event to start 2011-01-21 09:20:00, the last bar on my consolidated window is 2011-01-19 00:00:00 - 2011-01-20 00:00:00; while I'd expect to be 1 more bar in it.
What time the consolidator gets updated? and how can I achieve the data is updated till the last available bar (so basically the day before, and not 2 days before?).

Thanks in advance for any help.

class GLDTradingMomentumAlphaModel(AlphaModel): def __init__(self, algorithm, resolution = Resolution.Daily, primary = "GLD"): self.resolution = resolution self.primary = primary self.symbolDataBySymbol = {} self.lookback = 200 self.predictionInterval = Time.Multiply(Extensions.ToTimeSpan(self.resolution), 4) resolutionString = Extensions.GetEnumString(resolution, Resolution) self.Name = '{0}({1}-{2})'.format(self.__class__.__name__, resolutionString, primary) algorithm.Schedule.On(algorithm.DateRules.EveryDay(self.primary), algorithm.TimeRules.AfterMarketOpen(self.primary, -10), self.evaluateDailyStrategy) self.algo = algorithm def evaluateDailyStrategy(self): insights = [] for symbol in self.symbolDataBySymbol: if symbol.Value == self.primary: primaryData = self.symbolDataBySymbol[symbol] if (primaryData.rsi2.IsReady == False) or (primaryData.macd.IsReady == False): return if not self.algo.Portfolio.Invested and (primaryData.rollingRSI[0] > 55 and primaryData.rollingRSI[1] > 55 and primaryData.rollingRSI[2] > 55 and primaryData.macd.Current.Value > 0): insights.append(Insight.Price(self.primary, self.predictionInterval, InsightDirection.Up, None, None, None, 1)) elif self.algo.Portfolio.Invested and (primaryData.rollingRSI[0] > 90 and primaryData.rollingRSI[1] > 90): insights.append(Insight.Price(self.primary, timedelta(seconds = 1), InsightDirection.Flat, None, None, None, 1)) self.algo.EmitInsights(Insight.Group(insights)) def Update(self, algorithm, data): return [] def OnSecuritiesChanged(self, algorithm, changes): for security in changes.AddedSecurities: symbol = security.Symbol if not symbol in self.symbolDataBySymbol: self.symbolDataBySymbol[symbol] = SymbolData(symbol, self.lookback, algorithm, security, self.resolution) for removed in changes.RemovedSecurities: symbolData = self.symbolDataBySymbol.pop(removed.Symbol, None) if symbolData is not None: algorithm.SubscriptionManager.RemoveConsolidator(removed.Symbol, symbolData.Consolidator) class SymbolData: def __init__(self, symbol, lookback, algorithm, security, resolution): self.Symbol = symbol self.rsi2 = RelativeStrengthIndex(2, MovingAverageType.Simple) self.macd = MovingAverageConvergenceDivergence(10,20, 9, MovingAverageType.Exponential) self.rollingRSI = RollingWindow[float](3) self.rollingBAR = RollingWindow[TradeBar](2) self.Consolidator = algorithm.ResolveConsolidator(symbol, resolution) algorithm.RegisterIndicator(security.Symbol, self.rsi2, self.Consolidator) algorithm.RegisterIndicator(security.Symbol, self.macd, self.Consolidator) algorithm.Consolidate(security.Symbol, resolution, lambda x: self.rollingRSI.Add(x.Close)) algorithm.Consolidate(security.Symbol, resolution, lambda x: self.rollingBAR.Add(x))

 

Author