Pretty confused!
The code below compiles, works and paints the bars:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
candle = Close[0] > Open[0];
if (candle) {
BarBrush = Brushes.Blue;
}
}
================================================== ======
This almost IDENTICAL code below fails:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
candle = Open[0] >= Low[1] && Close[0] <= High[1];
if (candle) {
BarBrush = Brushes.Blue;
}
}
ERROR: Strategy 'st1': 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.
Why would it fail when trying to access the previous bar [1]?
Right now it's Saturday and the market is closed by I still don't get it, the chart has the data from the previous candle, no? Also confused why the error says bar 0 when clearly if I only use bar 0 there's no problems, only when I attempt bar 1 (Low[1] or High[1])
Why does this happen and how can I fix it? Thank you kindly for taking the time to read and reply.
UPDATE: Any bars except for 0 throw the error! If I use Low[1], Low[2], Low[3], etc.. all error out!
Comment