The IndicatorCounter function explained (drawing on window chart)

The IndicatorCounter function explained (drawing on window chart)

28 June 2018, 00:30
Mpendulo Chiliza
0
140

Hi, after this short blog post, I promise you, you will have a better understand on how to use the function IndicatorCounter.

i) IndicatorCounter function return value?

This function has a return type of integer; this value represents the number of
bars that the indicator has calculated on.

This value must always be greater than zero, or zero if its running 
for the first time, else if negative: an error has occurred.

Value of less than zero: error has occurred terminate the start() function.
Value of zero: no bars calculated (first call of the start() function ).
Value of grater then zero: not all bars have been accounted for.

ii) How is this value used?

 Example:  
   int Counted_bars = IndicatorCounted(); // Number of counted bars
   Counted_bars = Counted_bars-1; //recount of the last bar
   int position = Bars- Counted_bars; 

Once we have the IndicatorCounted function value (int Counted_bars), we add -1, so we can recount 
the last bar.

Bars is a pre-defined MQL4 variable that holds the total number of bars on your current chart. Therefore the
position variable holds the number of time your for loop will run. At each position you will have access to that
bar's calculated close price, open price, highest price, lowest price to name a few variables.

iii) DIAGRAM


diagram of IndicatoCounter explained


Position 6 would be the value of Bars, as you can notice, it counts backwards this is sometimes confusing 
if you still a beginner. But with more practice you will grasp the idea.

I hope this gives you a solid understanding on how metetrader goes about helping you drawing your custom indicator. 
If you have any questions, please leave a comment below and i will reply to it.


Share it with friends: