Switching timeframes recalculates whole indicator even with IndicatorCounted()

 

Hi guys,


So yeah, the question is in the title. I have an indicator which uses IndicatorCounted() to find out how many candles have not yet been calculated since "last time", but when i switch back and forth between two timeframes, IndicatorCounted() is always zero and thus the whole thing gets recalculated. You would assume that IndicatorCounted() serves a purpose in that very scenario at least, but i'm increasingly irritated by the uselessness of this function.


Am I missing something or is this indeed so? Anyway, how can i NOT recalculate the whole indicator after switching back to a timeframe where the indicator has already been calculated before? Cheers! :)

 

Switching time-frames means that the whole indicator has to be recalculated.

You wouldn't want an indicator calculated on H1 showing on D1 would you?

 
Keith Watford:

Switching time-frames means that the whole indicator has to be recalculated.

You wouldn't want an indicator calculated on H1 showing on D1 would you?


Obviously not, but i rather meant that if you switch from, let's say, M5 to H1 and then BACK to H5, then the indicator wouldn't have to be recalculated for M5 again except for the new bars that appeared in the mean time. But it still does recalculate which bugs me :/


Is there a way to get around this?

 
RichPiano:


Obviously not, but i rather meant that if you switch from, let's say, M5 to H1 and then BACK to H5, then the indicator wouldn't have to be recalculated for M5 again except for the new bars that appeared in the mean time. But it still does recalculate which bugs me :/


Is there a way to get around this?


How would the indicator know you were just switching temporarily M5 --> H1 --> M5, versus switching to H1 and staying there?

Yes, you could code something that remembered where it was on each timeframe previously, but I would suggest it would be unnecessarily complicated. Most well-coded indicators really don't take too long to process all the bars.

 
Samuel Beer:

Hi guys,


So yeah, the question is in the title. I have an indicator which uses IndicatorCounted() to find out how many candles have not yet been calculated since "last time", but when i switch back and forth between two timeframes, IndicatorCounted() is always zero and thus the whole thing gets recalculated. You would assume that IndicatorCounted() serves a purpose in that very scenario at least, but i'm increasingly irritated by the uselessness of this function.


Am I missing something or is this indeed so? Anyway, how can i NOT recalculate the whole indicator after switching back to a timeframe where the indicator has already been calculated before? Cheers! :)


Hello Beer,

I faced a similar issue, because i was drawing text on the chart, thus the indicator recalculates everything without going through the init() function which could have reseted the number of counted text (suffice) on the charts to starts from zero.

The results of switching between timeframes made resulted texts drawn to duplicate texts drawn on the charts. The solution, reset again if IndicatorCounted()=0.

Solution:

int start()

{

   BarIsCounted = IndicatorCounted();

   

   if(BarIsCounted==0)  

   {  ObjectsDeleteAll(chart_ID,1,OBJ_TEXT);

      CalCnt = 0;     // reset texts suffices

   }

//< your code here>

return(0);

}

 
Samuel Beer:


Obviously not, but i rather meant that if you switch from, let's say, M5 to H1 and then BACK to H5, then the indicator wouldn't have to be recalculated for M5 again except for the new bars that appeared in the mean time. But it still does recalculate which bugs me :/


Is there a way to get around this?

You can not do that - your buffers in the indicators are reset (lost) - hence, start from oldest bar or you shall have close to nothing in your indicator

It is not just a matter of a variable or two (like the indicator counted), but of the whole thing and what is stored in it

 
let's say, M5 to H1 and then BACK to H5, then the indicator wouldn't have to be recalculated for M5 again except for the new bars that appeared in the mean time.

Is there a way to get around this?

Open separate charts, same symbol, same indicator, different timeframes. Switching between charts doesn't recalculate anything.

 
Samuel Beer: Obviously not, but i rather meant that if you switch from, let's say, M5 to H1 and then BACK to H5, then the indicator wouldn't have to be recalculated for M5 again except for the new bars that appeared in the mean time.

Then every indicator would use nine times the memory it does now (9 TF on MT4.) It would have to save all buffers and variables per timeframe just so it could restore them when you switch back. The cost of storing and restoring would out weigh the little CPU that recalculating uses.

Reason: