Hi, I am new to quant connect and was trying my first simple algorithm backtesting code (it is very simple code), shown below 

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

    def Initialize(self):
        self.SetStartDate(2024, 1, 1)  # Set Start Date
        self.SetEndDate(2025, 1, 1) # Set End Date
        self.SetCash(100000)  # Set Strategy Cash
        
        spy = self.AddEquity("SPY", Resolution.Daily)
        # self.AddForex, self.AddFuture...
        
        spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
        
        self.spy = spy.Symbol
        
        self.SetBenchmark("SPY")
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        
        self.entryPrice = 0
        self.period = timedelta(31)
        self.nextEntryTime = self.Time


    def OnData(self, data):
        #if not self.spy in data:
        if not data.contains_key(self.spy):
            return
        price = data.Bars[self.spy].Close
        #price = data[self.spy].Close
        # price = self.Securities[self.spy].Close
        
        if not self.Portfolio.Invested:
            if self.nextEntryTime <= self.Time:
                self.SetHoldings(self.spy, 1)
                # self.MarketOrder(self.spy, int(self.Portfolio.Cash / price) )
                self.Log("BUY SPY @" + str(price))
                self.entryPrice = price
        
        elif self.entryPrice * 1.1 < price or self.entryPrice * 0.90 > price:
            self.Liquidate()
            self.Log("SELL SPY @" + str(price))
            self.nextEntryTime = self.Time + self.period

However when I built and run backtesting, it pops runtime error shown below:
 

Runtime Error: 'SPY' wasn't found in the TradeBars object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("SPY")
  at OnData
    price = data.Bars[self.spy].Close
            ~~~~~~~~~^^^^^^^^^^
 in main.py: line 29

 

It looks it is unhappy about line 29, for unknown reason. 

 

would you mind help me? 

Ahmed