# region imports
from AlgorithmImports import *
# endregion

class EmotionalSkyBlueSalmon(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 8, 1)  # Set Start Date
        self.SetEndDate(2022, 8, 5)
        self.SetCash(100000)  # Set Strategy Cash
        self.spy = self.AddEquity("SPY", Resolution.Minute, extendedMarketHours=False).Symbol
        self.spyRTH = self.AddEquity("SPY", Resolution.Minute, extendedMarketHours=False).Symbol
        #consolidate daily bar and rolling window
        self.rollingWindow = RollingWindow[TradeBar](2)
        self.rollingWindowRTH = RollingWindow[TradeBar](2)
        self.Consolidate(self.spy, Resolution.Daily, self.CustomBarHandler)
        self.Consolidate(self.spyRTH, Resolution.Daily, self.CustomBarHandlerRTH)    
        

    def OnData(self, data):
        if not self.rollingWindow.IsReady:
            return
        
        high = self.rollingWindowRTH[0].High
        highExt = self.rollingWindow[0].High
        low = self.rollingWindow[0].Low
        closeExt = self.rollingWindow[0].Close
        close = self.rollingWindowRTH[0].Close

        

        self.Log("High:" + str(high))
        self.Log("High:" + str(highExt))
        self.Log("Low:" + str(low))
        self.Log("Close:" + str(close))
        self.Log("EXTClose:" + str(closeExt))
       


    def CustomBarHandler(self, bar):
        self.rollingWindow.Add(bar)
        

    def CustomBarHandlerRTH(self, barRTH):
        self.rollingWindowRTH.Add(barRTH)
        


 

Hey,

I am trying to find the previous day high, low, and close but for the high/low I want to include pre/post market hours. For the Close I want it to actually be the close price at 4 PM. I feel like there is probably a much easier solution, but I tried to create two equities for SPY (one with extended hours and one without) then consolidate both to daily resolutions and use rolling windows to identify the datapoints needed. 

Unfortunately the code attached isn't working as I expected. I tried calculating a high/low with and without extended hours but it is always pulling back the same price for each. 

Any ideas on what I'm doing wrong or more efficient ways to get the same result?

Thanks for any help!

 

 

Author