In newer versions of MQL4 (and some C++ compilers), the scope of a variable declared in a for loop (like int i) extends to the entire function, not just inside the loop.
This means: the first declaration of int i makes i exist for the whole OnTick() function, so when you try to declare it again in the second loop, the compiler complains.
The problem didn't exit previously as newer versions of MetaEditor (or MQL4/5 compilers) became stricter and enforce this rule.
Incorrect. It has always extended in MQL4, unless you used strict. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
I know the fix, but this has never happened to me once, and from some time ago, it just doesn't stop..
Thanks!
define i outside the scope so it won't change
I know the fix, but this has never happened to me once, and from some time ago, it just doesn't stop..
Thanks!
Incorrect. It has always extended in MQL4, unless you used strict. Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
Oh this must have been the thing I changed, since I didn't know what was this for! Interesting.. Thank you so much 🙌

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I know the fix, but this has never happened to me once, and from some time ago, it just doesn't stop..
Thanks!