Here's the code:
I get the array out of range error on this line:
Now, I think I now why (At the end of the loop, there is no DataBuffer[i+1]). I'm just not sure how to avoid it.
This indicator is finding out what the difference is of a candle's range - the previous candle's range. Not all that useful, but I've got other things in mind. If this can be solved, then the rest will be easy.
Thanks.
-Michael.
Typical me. I have a "temporary" fix. Would like to know if there's an easier way. Here's what's added:
Added the following global variable:
bool IsInit;
Then set it in OnInit():
IsInit=true;
Then I added this in the second for loop right at the beginning of it:
if(IsInit && i>Bars-100) { IsInit=false; break; }
line 74
//int limit=rates_total-prev_calculated; int limit=MathMin(rates_total-1, rates_total-prev_calculated);
Because, on first calculation
preve_calculated = 0
Therefore,
rates_total - preve_calculated = rates_total
DataBuffer[i+1] = DataBuffer[rates_total]
Also you should correct following two lines.
line 11
//#property indicator_buffers 4 #property indicator_buffers 3
line 43
//IndicatorBuffers(3); IndicatorBuffers(4);
Michael:I get the array out of range error on this line:
int limit=rates_total-prev_calculated; if(prev_calculated>0) limit++; for(i=0;i<limit;i++) if(Diff>DataBuffer[i+1]) ... } return(rates_total); |
|

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Here's the code:
I get the array out of range error on this line:
Diff=DataBuffer[i]-DataBuffer[i+1];
Now, I think I now why (At the end of the loop, there is no DataBuffer[i+1]). I'm just not sure how to avoid it.
This indicator is finding out what the difference is of a candle's range - the previous candle's range. Not all that useful, but I've got other things in mind. If this can be solved, then the rest will be easy.
Thanks.
-Michael.