Am trying to translate an MQL4 Indicator of mine to MQL5.
It loads and initially shows the Indicator lines and arrows correctly, but then refuses to update on new ticks.
Debug gives array out of range error on all lines in which arrays use [i-1]. Have also tried [i+1] with the same result.
Any ideas what i may be doing wrong?
for(int i = rates_total - prev_calculated - 1; i >= 0; i--)
At the end of this loop, i = 0
If you subtract 1, you get -1
There is no index -1, so your array is out of range.
At the start of this loop, i = rates_total - 1
If you add 1, you get rates_total.
There is no index equal to rates_total. The biggest index is rates_total - 1 (because the numbering starts from 0 not 1).
Generally speaking it is bad to use i - 1 with timeseries as it looks into the future.
Keep with i + 1 but limit your loop.
Here is a good post about how to do lookbacks correctly.
(If you want to use i+1 then your lookback is 1).
-------
PS please use the SRC button when you post code - it makes it much easier to read! I've edited your post for you.
At the end of this loop, i = 0
If you subtract 1, you get -1
There is no index -1, so your array is out of range.
At the start of this loop, i = rates_total - 1
If you add 1, you get rates_total.
There is no index equal to rates_total. The biggest index is rates_total - 1 (because the numbering starts from 0 not 1).
Generally speaking it is bad to use i - 1 with timeseries as it looks into the future.
Keep with i + 1 but limit your loop.
Here is a good post about how to do lookbacks correctly.
-------
PS please use the SRC button when you post code - it makes it much easier to read! I've edited your post for you.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Am trying to translate an MQL4 Indicator of mine to MQL5.
It loads and initially shows the Indicator lines and arrows correctly, but then refuses to update on new ticks.
Debug gives array out of range error on all lines in which arrays use [i-1]. Have also tried [i+1] with the same result.
Any ideas what is happening here? Does MQL5 possibly have a different syntax for decrementing within the array? Have not been able to find any documentation on this yet.