TimeCurrent() lagging as hell! - page 2

 
tayofu: - even when using TimeLocal - the time refresh still lags a lot...
Never have seen that, so the problem must be in your code. Add the attached countdown timer to your chart and you will see local time vs time[0] counting down just fine. If it doesn't, then you have a CPU intensive indicator that must be fixed.
Files:
 
Thanks whroeder1; your countdown_timer works fine so I guess it might be an error in my code...

Any reason this code would lag?

      ObjectSetText("lineTime", "Date/Time: "+TimeToStr(TimeLocal(),TIME_DATE  |  TIME_SECONDS), 8, "Tahoma", LabelColor);

Rgds.
 
tayofu: Any reason this code would lag?

Only if you put it in OnInit.

 
whroeder1:

Only if you put it in OnInit.

I hate to say it, but... I think it's a bit more complex than that.

If you have the following code then, obviously, it can lag because it is only updated for each tick of the chart symbol, which is not necessarily the same as each change in TimeLocal() or TimeCurrent():

void OnTick()
{
   ObjectSetText("lineTime", "Date/Time: "+TimeToStr(TimeLocal(),TIME_DATE  |  TIME_SECONDS), 8, "Tahoma", Red);
}

The next case is an infinite loop in OnTick(). Although the label is constantly being set, MT4 does not actually update the display of the label unless there is a new tick, or unless you do something such as scrolling or zooming the chart, or if you do an explicit ChartRedraw(). So, if you don't touch the chart, this case is the same as the one above, because MT4 will only actually change the display of the label on each new tick:

void OnTick()
{
   while (!IsStopped()) {
      ObjectSetText("lineTime", "Date/Time: "+TimeToStr(TimeLocal(),TIME_DATE  |  TIME_SECONDS), 8, "Tahoma", Red);
      Sleep(100);
   }
}

And then there's OnTimer(). This does always update the actual display on the chart, in my experience, regardless of whether there's a tick or not. (I think MT5 might be different in this respect, and require an explicit ChartRedraw(). Can't remember, and can't be bothered to check right now.)

void OnInit()
{
   EventSetMillisecondTimer(500);
}


void OnTimer()
{
   ObjectSetText("lineTime", "Date/Time: "+TimeToStr(TimeLocal(),TIME_DATE  |  TIME_SECONDS), 8, "Tahoma", Red);
}

 
Thanks a lot JC: option_3 did it.
 
tayofu: Thanks a lot JC: option_3 did it.

Why didn't you look at the countdown timer I gave you and learned how it works?

 

Well I have never said that I was a professional coder; if I were so why would I bother using this forum to ask for help anyway? I paid somebody to code my EA and then subsequently he disappeared on me... now I am stuck with an EA with bad refresh rate so I am trying to fix it by myself since I've already paid a professional coder once... nothing to do with being a lazy-ass: I don't have the time to study coding for 2 years prior to fixing the refresh rate bug that's all.

To whroeder1 I've looked at your file and I will study it more: as I said I am no professional coder so I need some time for that... I will actually try to transfer your code to my EA and see if this works.

** UPDATE: problem fixed thanks a lot! I put whroeder1's code directly in my EA: now I have both a non-lagging timer && a non-lagging timecurrent(): great.
Reason: