double AskPrice0 = e.MarketDepth.Ask[0].Volume;
double AskPrice1 = e.MarketDepth.Ask[1].Volume;
double AskPrice2 = e.MarketDepth.Ask[2].Volume;
double AskPrice3 = e.MarketDepth.Ask[3].Volume;
double AskPrice4 = e.MarketDepth.Ask[4].Volume;
data = AskPrice0 + AskPrice1 + AskPrice2 + AskPrice3 + AskPrice4;
Plot0.Set(data);
I ran this on the Simulator and it ran fine for about 1 1/2 hours, then I get this error message, "Error on calling "OnMarketDepth" 'MyFileName': You are accessing an index with a value that is invalid since its out of range, I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars in the chart."
I usually see this error if I forget to put this in the beginning of my script, " if(CurrentBar < xx)return;" But when this is the problem, the script will not work at all until I insert the CurrentBar line. My code executes fine, then stops suddenly. If I open up the Indicator window of the chart and click OK, then it starts working again, but at some point later, errors again.
So it appears there is a problem processing the data a some point. I added a Print statement to see if anything unusual showed up, but when the error occurs, it just prints the error and the data before that looked normal. Any suggestions as to how I can stop this error from occuring?
Thanks,
Safetrading
Comment