Apologies in advance, as I guess I'm doing somthing stupid. I figured I could access historical bars in an indicator in the same way as the main dataseries, but for some reason, it does not work
I have this code which updates 2 plots
AskInt[0] = totalAsk;
BidInt[0] = totalBid;
if (Bars.Count>20)
{
if (BidInt.Count>20)
{
BidInt[0]= totalBid - BidInt[10];
}
if (AskInt.Count>20)
{
AskInt[0] = totalAsk - AskInt[10];
}
}
The idea being to reduce the value each by the value from 10 bars ago. However, I always get this error, even though I checked enough bars exist
Error on calling 'OnBarUpdate' method on bar 0: 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.
If I comment out the above (except the plot update first 2 lines), all runs as expected.
What an I doing wrong?
Thanks.
Comment