//if(prev_calculated==0) limit=rates_total; //replace if(prev_calculated==0) limit=rates_total-1;
Well done for highlighting the relevant code.
If only everyone would do that, it makes it easier for others to locate the problem.
for(int i=limit; i>=1 && !IsStopped() ; i--)Do you not want to calculate for the [0] bar?
BollingerBandsDefinition = iBands(_Symbol,_Period,20,0,2,PRICE_CLOSE);
You can't get results for the first 20 bars.
How to do your lookbacks
correctly.
Stephen Reynolds:
Why is it when i counts up the Version 1 code works but when i counts down as shown below in Version 2 code it gives array out of range error?
Version 1 with i counting forwards
Version 2 with i counting backwards
if(prev_calculated==0) limit=rates_total-1;
Mladen Rakic:
This works! Thanks.
I see if i make i count 9254-1 rather than 9255-1 it works.
Cant understand exactly why it works though?
Stephen Reynolds:
When you take into account the type of the error you get, isn't that obvious?
This works! Thanks.
I see if i make i count 9254-1 rather than 9255-1 it works.
Cant understand exactly why it works though?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Why is it when i counts up the Version 1 code works but when i counts down as shown below in Version 2 code it gives array out of range error?
Version 1 with i counting forwards
Version 2 with i counting backwards