The function returns the amount of bars not changed after the indicator had been launched last. The most calculated bars do not need any recalculation.
In most cases, same count of index values do not need for recalculation. The function is used to optimize calculating.
Note: The latest bar is not considered to be calculated and, in the most cases, it is necessary to recalculate only this bar. However, there occur
some boundary cases where custom indicator is called from the expert at the first tick of the new bar. It is possible that the last tick of the previous bar
had not been processed (because the last-but-one tick was being processed when this last tick came), the custom
indicator was not called and it was not calculated because of this. To avoid indicator calculation errors in such situations, the IndicatorCounted()
function returns the count of bars minus one.
Sample:
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);
}
|