In MQL4, the latest data number is 0, but in MQL5, it's the oldest one.
You should consider that point to get a correct result.
The first your program doesn't work correctly because it's for MQL5.
Regarding "for" statement, usually the same result is obtained in either direction, but in rare cases, it can not be calculated in the opposite direction.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
In MQL4, the latest data number is 0, but in MQL5, it's the oldest one.
You should consider that point to get a correct result.
The first your program doesn't work correctly because it's for MQL5.
Regarding "for" statement, usually the same result is obtained in either direction, but in rare cases, it can not be calculated in the opposite direction.
I think this is an example.