My strategy uses two data series. The Primary is the 30 Minute and Secondary is the 1 Tick.
Here is a snippet of the logic in question:
--------------------------------------------------------------------------------
public int barsinProgress0 = 0;
public int barsinProgress1 = 1;
public bool OkToTradeDay;
OnBarUpdate()
{
//Checks if today is a CME observed holiday to prevent trading. The dates start from the beginning of 2021 to the end of 2022.
if (ToDay(Times[barsinProgress1][0]) == 20210117 || // MLK Day
ToDay(Times[barsinProgress1][0]) == 20210221 || //Presidents Day
....... etc.....)
{
OkToTradeDay = false;
}
else
{
OkToTradeDay = true;
}
if (OkToTradeDay == true)
{
//Perform rest of strategy logic
}
}
--------------------------------------------------------------------------------
When I run a backtest for the current year (2022), it works fine. When I run the same strategy for the prior year (2021) I receive the error: "Error on calling "OnBarUpdate" method on bar 0: You are accessing an index value that is invalid since it is out of range etc..."
Then when I change the BarsInProgress index to 0 by using "barsinProgress0" to use the Primary Series (30 Min) to check for holidays, the error says an error is calling on bar -1.
I placed prints throughout my script and I know the error is coming from this section where it checks for the holidays.
Any insight as to why this error is appearing?
Also; The strategy works fine on both years when tested on the ES, but only works fine in 2022 and not in 2021 when testing on the NQ which is what the snippet above is trading. Would this be an issue with downloading the correct data?
Comment