Here's a simplified version of my code:
protected override void OnStateChange()
{
if (State == State.Configure)
{
AddDataSeries("SPY", BarsPeriodType.Minute, 1);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 1)
return;
double benchmarkClose = Closes[1][0];
Print(benchmarkClose)
}
When I use Closes[1][0] I get the following error: "Error on calling 'OnBarUpdate' method on bar 1: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."
I understand that this error typically occurs when trying to access a bar that doesn't exist yet. However, I'm trying to access the current bar of the secondary data series, which should exist when OnBarUpdate() is called, since CurrentBars[0] > 1.
I would appreciate any help in resolving this issue. Is there something I'm missing or misunderstanding about how to access the data of a secondary data series?
It happens even when using examples from the language reference. For context, I am running in sim mode on a trial account. I am using Ninjatrader for data. I have made sure to pick two instruments that have data in trial mode, and that the error happens regardless of the 'BarsPeriodType'.
Thank you in advance for your help.

Comment