IndicatorCounted() Twice all Bars?

 
Anyone knows why we get in the begin nearly all the time twice the whole amount of bars?


https://docs.mql4.com/customind/IndicatorCounted
I just copied part of the example code in the attached test indicator. ( test_2.mq4 )


The result is this.

EXAMPLE1 M1 :
12:15:58 test EURUSD,M1: loaded successfully
12:15:58 test EURUSD,M1: initialized
12:15:58 test EURUSD,M1: Alert: limit: 2154
12:16:01 test EURUSD,M1: Alert: limit: 2
12:16:01 test EURUSD,M1: Alert: limit: 3
12:16:01 test EURUSD,M1: Alert: limit: 2
12:16:01 test EURUSD,M1: Alert: limit: 2155
12:16:01 test EURUSD,M1: Alert: limit: 2
12:16:01 test EURUSD,M1: Alert: limit: 2
12:16:02 test EURUSD,M1: Alert: limit: 2
12:16:03 test EURUSD,M1: deinitialized
12:16:03 test EURUSD,M1: uninit reason 1
12:16:03 test EURUSD,M1: removed


EXAMPLE2 M5:
12:21:35 test EURUSD,M5: loaded successfully
12:21:35 test EURUSD,M5: initialized
12:21:35 test EURUSD,M5: Alert: limit: 2070
12:21:36 test EURUSD,M5: Alert: limit: 2
12:21:38 test EURUSD,M5: Alert: limit: 2
12:21:38 test EURUSD,M5: Alert: limit: 2
12:21:38 test EURUSD,M5: Alert: limit: 2070
12:21:38 test EURUSD,M5: Alert: limit: 2
12:21:39 test EURUSD,M5: Alert: limit: 2
12:21:39 test EURUSD,M5: Alert: limit: 2
12:21:39 test EURUSD,M5: Alert: limit: 2
12:21:40 test EURUSD,M5: Alert: limit: 2
12:21:40 test EURUSD,M5: Alert: limit: 2
12:21:41 test EURUSD,M5: deinitialized
12:21:41 test EURUSD,M5: uninit reason 1
12:21:41 test EURUSD,M5: removed

EXAMPLE3 H1:
12:22:24 test EURUSD,H1: loaded successfully
12:22:24 test EURUSD,H1: initialized
12:22:24 test EURUSD,H1: Alert: limit: 2050
12:22:25 test EURUSD,H1: Alert: limit: 2
12:22:25 test EURUSD,H1: Alert: limit: 2
12:22:27 test EURUSD,H1: Alert: limit: 2050
12:22:27 test EURUSD,H1: Alert: limit: 2
12:22:28 test EURUSD,H1: Alert: limit: 2
12:22:28 test EURUSD,H1: Alert: limit: 2
12:22:28 test EURUSD,H1: Alert: limit: 2
12:22:35 test EURUSD,H1: Alert: limit: 2
12:22:35 test EURUSD,H1: Alert: limit: 2
12:22:36 test EURUSD,H1: Alert: limit: 2
12:22:37 test EURUSD,H1: Alert: limit: 2
12:22:37 test EURUSD,H1: Alert: limit: 2
12:22:38 test EURUSD,H1: Alert: limit: 2
12:22:39 test EURUSD,H1: Alert: limit: 2
12:22:40 test EURUSD,H1: Alert: limit: 2
12:22:40 test EURUSD,H1: deinitialized
12:22:40 test EURUSD,H1: uninit reason 1
12:22:40 test EURUSD,H1: removed


Anyone knows why we get that always twice?

if one uses a for loop like in the example https://docs.mql4.com/customind/IndicatorCounted
for(int i=0; i<limit; i++) we calculate twice the whole bars?

Any thoughts are appreciated

Thanks

MJ

Files:
test_2.mq4  2 kb
 

I tried to replicate your results but I couldnt, in my test limit is only equal to the whole chart one time, after that it is 2 for every tick.

I dont know why no one else has responded to this, in regards to code optimization it seems pointless to use that commonly used code, not withstanding the fact as you pointed out here, IndicatorCounted() in your test caused the whole chart indicator to be calculated twice within 3 seconds, this code is also causing the indicator at both the current bar and the previous bar to be recalculated on every tick, limit should be 1 except on the event of a new bar, when limit should then and only then, be 2.

I know there is supposedly a valid reason for redrawing indicators at the last bar one time, when a new bar forms in case of a missed tick, but for what reason could it be neccessary to redraw it every time a new tick arrives ?

I have also wondered how valid is the reason for even redrawing at the last bar once in case of that missed tick ? I wonder how often that really happens, and when you think about it, so what if there was a missed tick ? You couldnt have traded on it anyway if it was missed so what is the point of redrawing the indicator to include calculation on a tick that wasnt even available at the time of trading ?

The end result of redrawing at the last bar is you never have an indicator drawn directly from the ticks, every indicator is constantly redrawn as if from a history chart based on HLOC instead of ticks is this really desireable ?

 

hi SDC,

thanks a lot for your reply.

SDC:

I tried to replicate your results but I couldnt, in my test limit is only equal to the whole chart one time, after that it is 2 for every tick.

THANKS: Funny that you do not have the same problem. BTW: I use Build 399 (broker: DEMO MIG). I might have to check this out with another broker too.

BTW: what I did was to add the indi - close the terminal - and than restarted the terminal.

SDC: if you don't mind could you post which Operating system you use and which account (Demo/LIVE maybe also which broker) and MT4 build number - thanks


SDC:

I know there is supposedly a valid reason for redrawing indicators at the last bar one time, when a new bar forms in case of a missed tick, but for what reason could it be neccessary to redraw it every time a new tick arrives ?

I have also wondered how valid is the reason for even redrawing at the last bar once in case of that missed tick ? I wonder how often that really happens, and when you think about it, so what if there was a missed tick ? You couldnt have traded on it anyway if it was missed so what is the point of redrawing the indicator to include calculation on a tick that wasnt even available at the time of trading ?

I'm not too familiar with mt4 but I could imagine a number of reason why one might want to redraw/correct a missing tick even though it is in the past.

- e.g. if an indicator uses previous results as input for calculation of the next one.

- some indicators use anyway only past data (e.g. Fractals) but someone might still use them.

- most of us traders use the charts to visualize 'past data' - otherwise one could only draw the last bar


SDC:

The end result of redrawing at the last bar is you never have an indicator drawn directly from the ticks, every indicator is constantly redrawn as if from a history chart based on HLOC instead of ticks is this really desireable ?

I see that a bit different: the Last tick of a bar is it's closing price: so if it has not been processed I would agree that it is valid to redraw it.


SDC:

I know there is supposedly a valid reason for redrawing indicators at the last bar one time, when a new bar forms in case of a missed tick, but for what reason could it be neccessary to redraw it every time a new tick arrives ?

Absolutely agree with you on that.

THANKS

MJ

 

im still using build 226 Windows Vista broker:liteforex live I didnt yet upgrade mt4 to the latest version because I read on other threads some bug reports.

 
SDC - Thanks a lot.
 
I had to reinstall MT4 client and build 229 was fine - seems the problem was introduced afterwards by Metratrade