I'm having a problem in backtesting mode.

It shows : 'NoneType' object has no attribute 'Close'

  at OnData

    if  self.window[0].Close < self.stop_price:

   at Python.Runtime.PythonException.ThrowLastAsClrException()

   at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 39

However, I am doing a check by data.ContainsKey



#region imports
from AlgorithmImports import *
#endregion
class AdaptableTanCormorant(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 5, 21)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddEquity("AAPL", Resolution.Minute)
        self.stop_price = None
        self.target_price = None
        #self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen('SPY', 30), 
           # self.open_daily_check)
        self.window = RollingWindow[TradeBar](3) 
        self.date_=None
            
        
        return 

    def OnData(self,  data: Slice):
        if not data.ContainsKey("AAPL"):
                return
        
        self.window.Add(data["AAPL"])
        
        


        if not self.Portfolio.Invested and self.window.IsReady:
            first_bar=self.window[0]
            second_bar=self.window[1]
            third_bar=self.window[2]
            if first_bar.Low == second_bar.Low and second_bar.Low == third_bar.Low:
                self.SetHoldings('AAPL',1)
            
            self.stop_price = first_bar.Low - (first_bar.High - first_bar.Low)
            self.target_price = first_bar.High + (first_bar.High - first_bar.Low)*2
        
        if self.Portfolio.Invested:
            if  self.window[0].Close < self.stop_price:
                self.Liquidate()
                self.stop_price = None
                self.target_price = None
                
    
            

 

 

Author