int pos = limit - period;
What is period?
What is period?
Sorry, forgot to state that, period is the indicator period, I did that with this logic, if I have 100 bars in history and I need 20 bars at minimum to calculate the indicator value, I need to plot from bar 80 (100 - 20, or limit - period)
Sorry, forgot to state that, period is the indicator period, I did that with this logic, if I have 100 bars in history and I need 20 bars at minimum to calculate the indicator value, I need to plot from bar 80 (100 - 20, or limit - period)
That makes no sense at all.
Apart from that, what do you think happens when limit == 1 ?
That makes no sense at all.
Apart from that, what do you think happens when limit == 1 ?
- Fernando Jose Velasco Borea:
Sorry, forgot to state that, period is the indicator period, I did that with this logic, if I have 100 bars in history and I need 20 bars at minimum to calculate the indicator value, I need to plot from bar 80 (100 - 20, or limit - period)
int pos = limit - period;
If you are on the H1 you are computing limit - 60. If you are on the D1 you compute limit-1440. Just compute your look back in bars:
limit = Bars - MathMax(20, counted_bars);
How to do your lookbacks correctly #9 - #14 & #19 - You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11
-
If you are on the H1 you are computing limit - 60. If you are on the D1 you compute limit-1440. Just compute your look back in bars:
How to do your lookbacks correctly #9 - #14 & #19 - You should stop using the old event handlers and IndicatorCounted() and start using new event handlers.
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 2016.05.11
Thanks a lot! It worked without the -1 from the post you linked on your reply. I'm not completely sure why that is, but when I add it, I face the same issue, I suspect that is because I'm doing i > 0 instead of i >= 1 but I'm not sure:
for (int i = Bars - MathMax(period, prev_calculated); i > 0; i--) // Where Period is an input {...}
Also, if I don't want to calculate for all available bars, but for the last X bars, would this call be correct?
iBar = Bars - max_bars - MathMax(period, prev_calculated); // Where max_bars is an input
period is not X. What part of "limit - 60" and "limit-1440" was unclear?
My bad, when I mean period I refer to the actual indicator period, not the time-frame. Just noticed that my approach for last X bars is not correct, it'd be as follows, still, when max_bars is smaller, for some reason I still seem to have the issue:
iBar = MathMin(Bars, max_bars) - MathMax(period, prev_calculated); // EDIT: Just noticed the issue, this is the fixed one which seems to work properly: iBar = MathMin(Bars - MathMax(period, prev_calculated), max_bars - period)
Obviously It'd require something like the code below on top.
if (Bars < period) return(-1);

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello!
I have an issue with my indicator and I'm almost sure it's due to the way I am performing the look back. My problem is basically that when the indicator is loaded, it plots on the chart without issues, but when new bars forms, it doesn't update. Here is the code I am using to perform the loop:
The above image is from the strategy tester, when it's loaded it performs it's required calculations, but as new bars are formed, it doesn't update.
Any advice is appreciated!