- Stop using IndicatorCounted. Use the new event handlers.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
How to do your lookbacks correctly. - koranged: I just cannot seem to get my head around this one! Essentially, I can't understand how the values of the last (1) bar have changed since the function was last launched. I have run the indicator myself and can see that on the first tick of the new bar:A new bar started, therefor the last tick of (now) bar 1 may or may not have been processed. Remember, ticks can be missed.
- Stop using IndicatorCounted. Use the new event handlers.
Event Handling Functions - Functions - Language Basics - MQL4 Reference
How to do your lookbacks correctly. - A new bar started, therefor the last tick of (now) bar 1 may or may not have been processed. Remember, ticks can be missed.
In this instance apparently that isn't the case. From manual:
"(at) the last tick of the previous bar (at the moment t 2) the function start() was successfully started and execute"
There is an example given later on where the last but one tick is not processed, but in this particular example, the manual specifically says that at the last tick... the function start() was successfully executed.
- When start returns the last tick has been processed. No guarantee that prior ticks were.
-
Don't double post!
General rules and best pratices of the Forum. - General - MQL5 programming forum
- When start returns the last tick has been processed. No guarantee that prior ticks were.
-
Don't double post!
General rules and best pratices of the Forum. - General - MQL5 programming forum
The situation you are referring to is the exactly the same as the third example given in the manual - https://book.mql4.com/samples/icustom
The situation I am referring to is the second example given in the manual - which makes no mention of prior ticks not being processed.
Here is the full example:
Variant 2. A new tick is the first tick of a zero bar (happens from time to time).
In this case the fact of appearance of a new bar is important. Before control is passed to the special function start(), client terminal will draw again all bars present in the security window and re-index all declared indicator arrays (set in correspondence with buffers). Besides, client terminal will remember that there are already 301 bars, not 300 in a chart window.
Fig. 118 contains situation when on the last tick of the previous bar (at the moment t 2) the function start() was successfully started and executed. That's why, though now the first bar (with index 1) finished at the moment t 2 was calculated by the indicator, function IndicatorCounted() will return value that was on the previous bar, i.e. 299:
Counted_bars=IndicatorCounted(); // Number of counted bars
In the next line index i will be calculated, in this case for the first tick of a new bar it will be equal to 1 (301-299-1):
i=Bars-Counted_bars-1; // Index of the first uncounted
It means calculation of indicator array values in while() loop at the appearance of a new bar will be performed both for the last bar and for the new zero bar. A little earlier during re-indexation of indicator arrays the client terminal increased sizes of these arrays. Values of array elements with zero indexes were not defined before the calculations in the loop. During calculations in the loop these elements get some values. When calculations in start() are over, control is returned to the client terminal. After that the client terminal will draw indicator lines on the zero bar based on just calculated values of array elements with zero indexes.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- book.mql4.com
I cannot seem to understand how it is that 'IndicatorCounted' (Counted_bars) can equal anything other than (Bars-1), unless the program is on its first iteration of the start() function.
Think of imperfect world. Processed bars count can be dropped to 0, if some bars was intially missing in history (for some reason), but then downloaded from server. Or the count can be less than Bars - 1 if there were no connection for quite a lot of time - larger than 1 bar frame (or, for example, when the terminal restarts).
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
This code is taken directly from the manual/tutorial in the Custom Indicators section - https://book.mql4.com/samples/icustom
I cannot seem to understand how it is that 'IndicatorCounted' (Counted_bars) can equal anything other than (Bars-1), unless the program is on its first iteration of the start() function.
As far as I understand, 'IndicatorCounted' returns the amount of bars 'not changed' since the function was last launched. So if there are 300 bars on the chart and the array element values 0-299 have already been defined, then 'Counted_bars' must equal 299 at the next iteration of the start() function (as only the values of the 0 bar have changed since the function was last launched - (300-1=299)).
The manual however insists that in the following situation:
'Bars' = 301
'Counted_bars' = 299
I just cannot seem to get my head around this one! Essentially, I can't understand how the values of the last (1) bar have 'changed' since the function was last launched. I have run the indicator myself and can see that on the first tick of the new bar:
There is clearly a discrepancy of 2 between 'Bars' and 'Counted_bars'.
If somebody can offer an explanation clearer than that given in the manual/tutorial as to why this would be the case, I would be greatly appreciative.
Very new to coding so apologies if my question seems silly.