IndicatorCounted returns the number of bars that the indicator has already made its calculations
You use it so that your indicator is not calculating data on every bar, every tick.
Usually you will code it so that it only recalculates the last completed and the current bar, but it will still do this every tick. So you might check for a new bar so it only calculates when a new bar is opened.
- Always count down so you're not repainting
- Don't decrement Contradictory information on IndicatorCounted() - MQL4 forum
- Don't look back past the last candle.
int start() { int counted_bars=IndicatorCounted(), lookback = MathMax(JawsPeriod, MathMax(TeethPeriod, LipsPeriod)); if(counted_bars < lookback) counted_bars = lookback; for(int i=Bars - 1 - counted_bars; i>=0; 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); }
WHRoeder:
- Always count down so you're not repainting
- Don't decrement Contradictory information on IndicatorCounted() - MQL4 forum
- Don't look back past the last candle.
thank you both, I will try and learn this properly
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi forum, had it recently pointed out to me by one of our esteemed moderators (THANK YOU RAPTOR)
That I writing my code such that my indicators were updating every tick.
Have just found the time to start looking at this and hopefully re writing some code to ease load on CPU, but I am a bit confused
I looked at documentation for IndicatorCounted (code, cut and pasted below) "The function returns the amount of bars not changed after the indicator had been launched last"
I also looked at a suggestion from Raptor:
//-- Comment("") Only update the objects if they need updating
if( iTime(NULL, PERIOD_H1, 1) == Bar1Time) return(0);
Bar1Time = iTime(NULL,PERIOD_H1,1);
Would someone mind stating in really simple terms, the difference here, and specifically how IndicatorCounted works
The text above suggests to me that if Bar1Time is the same as the previous hours time, do nothing (indicator is not recalculated and drawn)
That is you wont have the indicator update or the following loop proceed until 1 hour and 1 tick from the previous update
But I am unable in get the documentation into simple terms that allows me to understand exactly how IndicatorCounted works in practice
thanks as always