Market closed - page 7

 
Set the timer for half a second. It got a little better. OK, let's keep it that way for now.
 
Vasiliy Pushkaryov:
Set the timer for half a second. It got a little better. Okay, let's keep it that way for now.

Show me the code.

 
fxsaber:

Show me the code.

I've cleaned up the excess.

But such lags can often be caught manually, or is 500ms normal?


Files:
 
Vasiliy Pushkaryov:

I've cleaned up the excess.

But such lags can often be caught manually, or is 500ms normal?


I've tried this construction instead of removing the marker, just replacing the text if the marker exists, but I haven't noticed any difference

   if(ObjectFind(idChart, nameFix) == 0)
   {
     ObjectSetString(idChart, nameFix, OBJPROP_TEXT, text);
     ChartRedraw();
     return;
   }
 
Vasiliy Pushkaryov:

is it often possible to catch lags like this manually, or is it 500ms normal?

This is not a lag. You display the time from OnTimer, then wait for 500ms. In that 500ms the time changes, but OnTimer has not yet been called.

You need to synchronize - set EventSetTimer(1) exactly at the moment when "TimerCurrent changed".


Tried this way to synchronise

bool SetTimerSync( const uint TimerMs = 1000, const uint SyncError = 50 )
{
  // https://www.mql5.com/ru/forum/166646/page5#comment_5796939  
  return((GetCurrenTime() % 1000 > 1000 - SyncError) && EventSetMillisecondTimer(TimerMs));
}

void OnTimer()
{
  static bool Sync = GetCurrenTime() * 0;
   // --- при максимизированном окне выводим время на график
  if (Sync)
    showHideTime(); // https://www.mql5.com/ru/forum/166646/page7#comment_6384173
  else
    Sync = SetTimerSync();
}


int OnInit()
{
  EventSetMillisecondTimer(1);
  
  return INIT_SUCCEEDED;
} 
It does not work. And I have bad thoughts towards MT5 lag. See for yourself how your script will behave with these changes.
 
fxsaber:

Tried this way to synchronise

It does not work. And I have bad thoughts towards MT5 lag.

OnTimer is not called after the set number of ms. Hence the accumulated error and the observed lag. Bug!

 
fxsaber:

This is not a lag. You output the time from OnTimer to the screen, then wait for 500 ms. During this 500 ms the time changes, but OnTimer has not yet been called.

You need to synchronize - set EventSetTimer(1) exactly at the moment when "TimerCurrent changed".


Tried this way to synchronise

It does not work. And I have bad thoughts towards MT5 lag. See for yourself how your script will behave with these changes.
You have millisecond timer in your code in OnInit, in your post you write a regular one-second timer. I guess you want to use EventSetTimer(1) after all?
 
Vasiliy Pushkaryov:
You have millisecond timer in your code in OnInit, in your post you write regular, one-second timer. I guess you want to use EventSetTimer(1) after all?

First the first timer is synchronised, then the second timer is set.

 
fxsaber:

First there is synchronisation via the first timer, then the second timer is set.

I see, I won't be able to check it until tomorrow, thanks for your help.
 
fxsaber:

OnTimer is not called after the set number of ms. Hence the accumulated error and the observed lag. It's a bug!

The script in the chart comment shows this bug

input int TimerMs = 1000;

const bool Init = EventSetMillisecondTimer(TimerMs);

void OnTimer()
{
  static ulong StartTime = 0;  
  static int Count = 0;
  
  if (!StartTime)
    StartTime = GetMicrosecondCount();
  
  Comment("Error " + (string)((int)(GetMicrosecondCount() - StartTime) / 1000 - TimerMs * Count) + " ms.");  
  
  Count++;
}
Reason: