Hello all! I wrote this simple also trying to backtest breakouts with different variations of volume divergence from the mean of the current bar as a confirmation but I am making a mistake and have exhausted my resources trying to figure out what I'm doing wrong. As always thank you to everyone in the community for all the help so far, I appreciate it! I have attached my code here below, 

 

# region imports
from AlgorithmImports import *
# endregion

class SleepyBlueSeahorse(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2010, 1, 1) 
        self.SetEndDate(2011, 1, 1) 
        self.SetCash(100000) 
        self.AddEquity("SPY", Resolution.Minute)

        self.tradeBarWindow = RollingWindow[TradeBar](2)

        self.ema = self.EMA("SPY", 30,  MovingAverageType.Exponential, Resolution.Minute, Field.Volume)

        self.max = self.MAX("SPY", 1, Resolution.Daily)
        self.min = self.MIN("SPY", 1, Resolution.Daily)


        
        

        self.Schedule.On(self.DateRules.EveryDay("SPY"), 
                 self.TimeRules.BeforeMarketClose("SPY", 10), 
                 self.EveryDayBeforeMarketClose)

        self.SetWarmup(timedelta(days=2))

    def OnData(self, data: Slice):
        if self.IsWarmingUp:
            return

        self.tradeBarWindow.Add(data["SPY"])
        price = self.Securities["SPY"].Price
        if not self.tradeBarWindow.IsReady:
            return
        

        if self.Time.hour >= 10 and self.Time.hour < 13 and not self.Portfolio.Invested:
            if price > self.max.Current.Value and self.tradeBarWindow[1].Close < self.max.Current.Value:
                if data["SPY"].Volume > self.ema.Current.Value:
                    self.MarketOrder("SPY", 100)
            if price < self.min.Current.Value and self.tradeBarWindow[1].Close > self.min.Current.Value:
                if data["SPY"].Volume > self.ema.Current.Value:
                    self.MarketOrder("SPY", -100)
    def EveryDayBeforeMarketClose(self):
        self.Liquidate()