I am trying to get the high and low of the trading day on SPY just before trading ends at 3:30pm or 3:45pm.  Therefore i thought that a consolidator could do the job.

I tried to modify the template consolidator algo to my porpose with no success after many iterations, many of them are still commented out.

I tried every 6 hours, 465min and other values.

I also tried to aggregate 15, 30 minutes consolidator  but this did not work either.

I must be close, can someone help?

See code below.


def Initialize(self):
        self.SetStartDate(2015, 2, 1)  
        self.SetEndDate(2015, 2, 14)
        self.AddEquity("SPY", Resolution.Minute)
        #self.AddEquity("SPY", Resolution.Hour)

        #thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=465))
        thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(hours=3))
        #thirtyMinuteConsolidator = TradeBarConsolidator(TimeSpan.FromHours(6))
   #thirtyMinuteConsolidator = TradeBarConsolidator(TimeSpan.FromMinutes(465))

        thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler
        self.SubscriptionManager.AddConsolidator("SPY", thirtyMinuteConsolidator)
        oneDayConsolidator = TradeBarConsolidator(timedelta(minutes=30))
        threeCountConsolidator = TradeBarConsolidator(15)
three_oneDayBar=SequentialConsolidator(oneDayConsolidator,  threeCountConsolidator)
       three_oneDayBar.DataConsolidated += self.ThreeDayBarConsolidatedHandler
        self.SubscriptionManager.AddConsolidator("SPY", three_oneDayBar)

    def ThirtyMinuteBarHandler(self, sender, bar):
        '''This is our event handler for our 30-minute trade bar defined above in Initialize(). So each time the consolidator produces a new 30-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 ThreeDayBarConsolidatedHandler(self, sender, consolidated):
        self.Log(f"{consolidated.Time} >> Plotting!")
        #self.Plot(consolidated.Symbol, "3HourBar", consolidated.Close)
        self.Debug(str(self.Time) + " " + str(consolidated.Close))
    def OnData(self, data):
        self.data = data