I am trying to do some basic lookback on equities price but for some reaason my loop is throwing an out of range error. The rollingwindows has worked fine before with indicators.

 

import numpy as np
import decimal as d
from datetime import timedelta
### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
'''Basic template algorithm simply initializes the date range and cash'''

def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

self.SetStartDate(2015, 1, 1) #Set Start Date
self.SetEndDate(2017,1,1) #Set End Date
self.SetCash(100000) #Set Strategy Cash
# Find more symbols here: http://quantconnect.com/data
self.osymbol = "XOM"
equity = self.AddEquity("XOM", Resolution.Daily)
self.stock = equity.Symbol
self._sma = RollingWindow[d.Decimal](14)
self.window = RollingWindow[TradeBar](14)
self._sma12 = self.SMA(self.osymbol, 12, 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.'''
#self._macdHistogram.Add(self._macd.Histogram.Current.Value)
#self._RSI.Add(self._rsi.Current.Value)
self._sma.Add(self._sma12.Current.Value)
self.window.Add(data["XOM"])
# Wait for windows to be ready.
if not self.window.IsReady: return
if not self.Portfolio.Invested:
for num in range(0,4):
self.Log(self.window[num])

 

The error i get is " Runtime Error: ArgumentOutOfRangeException : Must be between 0 and 0
Parameter name: i
Actual value was 1.
at QuantConnect.Indicators.RollingWindow`1[T].get_Item (System.Int32 i) [0x0004c] in <76d49b5d5c8545899040d54812d7ccc1>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0
at OnData in main.py:line 74
ArgumentOutOfRangeException : Must be between 0 and 0
Parameter name: i
Actual value was 1.
at QuantConnect.Indicators.RollingWindow`1[T].get_Item (System.Int32 i) [0x0004c] in <76d49b5d5c8545899040d54812d7ccc1>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in <2e7c1c96edae44d496118948ca617c11>:0 (Open Stacktrace)
"