a problem about "IndicatorCounted()".

 

According to my understanding, "IndicatorCounted()" will return "-1" when it was loaded at the first time and will return the mount of "effective bars" from the second loaded or executed.

But when I run below codes, I see that the parameter, "counted_bars", always is -1 and constant repeatly.

I don't know why and how shall get the effective bars by "IndicatorCounted() "?

 int start()
  {
   int counted_bars=IndicatorCounted();
   Print("counted_bars:",counted_bars);
   return(0);
  }
 

You're running it like an expert_advisor. Identify it as indicator, place it within the correct folders, do-some reading about indicators instead of trial and error.

example:


#property indicator_separate_window
#property indicator_buffers 1

void start(){
    int counted_bars=IndicatorCounted();
    Comment("counted_bars=",counted_bars);
}
 
ubzen:

You're running it like an expert_advisor. Identify it as indicator, place it within the correct folders, do-some reading about indicators instead of trial and error.

example:


yes, it is.

thanks,

 

vx0532: According to my understanding, "IndicatorCounted()" will return "-1" when it was loaded at the first time a

But when I run below codes, I see that the parameter, "counted_bars", always is -1 and constant repeatly.

  1. False IndicatorCounted() function returns the count of bars minus one. If IndicatorCounted is "always is -1" something is wrong like using indicator functions in a EA or script.
  2. No decrement Contradictory information on IndicatorCounted() - MQL4 forum
  3. //b4plusdi=iADX(NULL,0,ADXbars,PRICE_CLOSE,MODE_PLUSDI,shift+1);
      int lookback =       ADXbars                              +1;
    
    int shift,counted_bars=IndicatorCounted();
    if(counted_bars < lookback) counted_bars = lookback;
    for (shift = Bars - 1 - CountBars; shift>=0; shift--)
Reason: