quick question about Indicator Counted

 

Hello Forum, I am trying to understand the concept of Indicator Counted and as a consequence, how to distinguish between when indicators recalculate during the current bar OR not !!

( I hope I am looking at the right part of the documentation)

I've lifted the code below from the documentation https://docs.mql4.com/customind/indicatorcounted

Am still struggling to understand this, and want to ask for clarification on the following:

If I wanted my indicator to NOT update on the current bar, would this be achieved by simply changing the "i" integer value from 0 to 1 in the code line (for (int i=0;  i<limit;  i++)  ?

Or is it more complex than this?

Thanks in advance...

int start()
    {
     int limit;
     int counted_bars=IndicatorCounted();
  //---- check for possible errors
     if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
  //---- main loop
     for(int i=0; i<limit; i++)
       {
        //---- ma_shift set to 0 because SetIndexShift called abowe
        ExtBlueBuffer[i]=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
        ExtRedBuffer[i]=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
        ExtLimeBuffer[i]=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
       }
  //---- done
     return(0);
    }
 
pullend:

If I wanted my indicator to NOT update on the current bar, would this be achieved by simply changing the "i" integer value from 0 to 1 in the code line (for (int i=0;  i<limit;  i++)  ?

Correct . . . as far as I am aware.  

 

IndicatorCounted() indirectl tells you how many bars you need to calculate your buffers for since last time you did it.  It does this by actually telling you how many bars are the same compared to the last time IndicatorCounted() was called.  First time through your start() function this will be zero bars as they have not been "seen" by Indicator Counted() before,  next time through,  as long as there isn't a new bar, IndicatorCounted() has "seen" all the bars and all buffer values have been calculated so Bars-1 is returned,  meaning that all bars are the same as the last time so there is nothing to do.

 
RaptorUK:

Correct . . . as far as I am aware.  

 

IndicatorCounted() indirectl tells you how many bars you need to calculate your buffers for since last time you did it.  It does this by actually telling you how many bars are the same compared to the last time IndicatorCounted() was called.  First time through your start() function this will be zero bars as they have not been "seen" by Indicator Counted() before,  next time through,  as long as there isn't a new bar, IndicatorCounted() has "seen" all the bars and all buffer values have been calculated so Bars-1 is returned,  meaning that all bars are the same as the last time so there is nothing to do.


Thank you Raptor !!
 
  1. No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 forum
  2. Always count down. Get in the habit.
int counted_bars=IndicatorCounted();
// Adjust for look back. E.g. iMA(PERIOD) LB=PERIOD
// if (counted_bars < LOOK_BACK) counted_bars = LOOK_BACK;
// Same as SetIndexDrawBegin() setting in init.
 for(iBar = Bars -1 -counted_bars; iBar >= 1; iBar--){
   :
Reason: