Hello All,

I am trying to create a very simple test algorithm which buys one share of "SPY" six trading periods after the price closes at 302.01 (this occurred on 7/26/2019). I am doing this just to try to understand the basics of coding in Python on QuantConnect. Here is my code:

----------------------------------------------------------------------------------

class OptimizedModulatedCoil(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 3, 20)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Daily)


    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
        self.closeWindow = RollingWindow[float](10)
        self.closeWindow.Add(data["SPY"].Close)
        testParm = self.closeWindow[6]
        self.SetWarmUp(20, Resolution.Daily)
        if not self.Portfolio.Invested and testParm == 302.01:
            self.Buy("SPY", 1)

----------------------------------------------------------------------------------

 

...and here is the error message I keep recieving when I perform a backtest:

 

----------------------------------------------------------------------------------

Runtime Error: ArgumentOutOfRangeException : Index must be between 0 and 0 (entry 6 does not exist yet)
Parameter name: i
Actual value was 6.

----------------------------------------------------------------------------------

 

Any help that the community can offer will be greatly appreciated. I have created algorithms with Trading View's Pine Script language, but I am completely new to Quantconnect and Python.

 

Author