A minute and a half difference between local time and fresh tick time. What to do.

 

I wrote a small Expert Advisor, which shows the maximum difference between local computer time and new tick time_msc (just received).

Roughly speaking, it measures TimeLocal() only in milliseconds minus the time of the last tick Tick.teme_msc . The tick is received using SymbolInfoTick.

Didn't make much fun of it. 24 characters in market overview. OnTimer() with calling period 1 millisecond. I'm polling all symbols with SymbolInfoTick. If a tick is new I make measurements.

I have tested the Expert Advisor at Evening. Here are the results:

New ticks caught 46800

Minimal time between local computer time and tick's time -7048 milliseconds (with minus sign)

Average time between local computer time and tick time -6819 milliseconds (with minus)

Maximal time between local computer time and tick time -97082 milliseconds ( with plus )


How to deal with this ?

 
pivomoe:

I wrote a small Expert Advisor that shows the maximum difference between the local computer time and the time of the new tick time_msc (just received).

Roughly speaking, it measures TimeLocal() only in milliseconds minus the time of the last tick Tick.teme_msc . The tick is received using SymbolInfoTick.

Didn't make much fun of it. 24 characters in market overview. OnTimer() with calling period 1 millisecond. I'm polling all symbols with SymbolInfoTick. If a tick is new I make measurements.

I have tested the Expert Advisor at Evening. Here are the results:

New ticks caught 46800

Minimal time between local computer time and tick's time -7048 milliseconds (with minus sign)

Average time between local computer time and tick time -6819 milliseconds (with minus)

Maximal time between local computer time and tick time -97082 milliseconds ( with plus )


How to deal with this ?

Had a look at your code...

You are not doing it right at all.

You need to add the most liquid instruments to Market Watch.

Then add their money pots.

And, when OnBookEvent() triggers, copy 1 tick (the last) there will be time and immediately take the local time and compare.

And why do you need to compare the local time with the time of ticks?

If you need to know whether it is possible to trade, then here is a function

//+------------------------------------------------------------------+
//| Expert Check Market Time function                                |
//+------------------------------------------------------------------+
bool CheckMarketTime()
{
  MqlDateTime cur_time, sv_time;
  cur_time.year = 0;
  TimeTradeServer(cur_time); //Возвращает расчетное текущее время торгового сервера.
  if(cur_time.year > 0)
  {
    sv_time.year = 0;
    TimeCurrent(sv_time); //Возвращает последнее известное время сервера
    if(sv_time.year > 0)
    {
    //  if((cur_time.day_of_week == int(FirstDay)) ||
    //     (cur_time.day_of_week == int(SecondDay))) return(false); //Проверка на выходные
      if(cur_time.day_of_week == sv_time.day_of_week)
      {
        ulong tr_time = sv_time.hour * 3600 + sv_time.min * 60 + sv_time.sec;
        if(((tr_time >= time_st_mon) && (tr_time < 50370)) ||  //10:00:01 - 13:59:30
           ((tr_time >= time_st_day) && (tr_time < 67470)) ||  //14:05:01 - 19:44:30 
           ((tr_time >= time_st_evn) && (tr_time < 85770)))    //19:05:01 - 23:49:30
        {
          return(true);
        }  
      }  
    } 
  }   
  return(false);
}
 

On the topic of tick relevance, check out this indicator with comments.

Ping
Ping
  • www.mql5.com
Для торговли важным параметром является актуальность текущей цены. На него влияет множество факторов, самый популярный из которых - сетевой пинг между терминалом и торговым сервером. Но часто из виду упускается другой параметр: так называемый "внутренний пинг терминала" - дополнительный лаг котировок внутри самого терминала (платформы). Даже...
 
prostotrader:

Looked at your code...

You're not doing it right at all.

You need to add the most liquid instruments to Market Watch.

Then, add the market depths of these instruments.

And, when OnBookEvent() triggers, copy 1 tick (the last) there will be time and immediately take the local time and compare.

And in general, why do you need to compare local time with ticks time?

Why do you need to do everything, through a stack ? Just to make the code look better ? If I have a symbol in market overview, doesn't it mean that there is a constant synchronization and I can access the last 4096 ticks for the symbol directly from the cache ( i.e. instantly ) ? In any case your idea needs to be tested. The only thing I don't understand, what does "copy 1 tick (last)" mean to calculate the tick by changing the cup ?

And in general why do you need to compare local time with tick time ?

Making trading decisions based on yesterday's prices is not a good idea. To buy SBER at 100 yesterday might be a good idea from the point of view of the algorithm, but today you have to sell it at 80.

 
pivomoe:

Why do everything, through a glass ? Just to make the code look better ? If I have a symbol in the market overview, doesn't it mean that there is a constant synchronization and I can access the last 4096 ticks on the symbol directly from the cache ( i.e. instantly ) ? In any case your idea needs to be tested. The only thing I don't understand, what does "copy 1 tick (last)" mean to calculate the tick by changing the cup ?

And in general why do you need to compare local time with tick time ?

Making trading decisions based on yesterday's prices is not a good idea. Yesterday SBER at 100 may be a good idea from the point of view of the algorithm, but today you should sell it at 80.

Why are you asking a question if you know everything yourself.

Do as you see fit.

 
prostotrader:

Why are you asking the question if you know everything yourself?

Do as you see fit.

I am asking in all seriousness. When programming in MQL, I realised that neither the help nor the information provided by the terminal should be trusted. It's no more than a piece of information for reflection. It is possible that the tick gives information earlier (more stable) thanSymbolInfoTick.

By the way, here is the tick which came with a delay of a minute and a half:

New MA Maximum difference 97082 SBPR-3.19 Local time 2019.03.15 21:05:31.842 Tick time 2019.03.15 21:03:54.760

There was nothing criminal in the tick history this minute. Two ticks in a minute.

 
pivomoe:

I am asking in all seriousness. When I was programming in MQL, I realised that neither the help nor the information provided by the terminal should be trusted. It's no more than a piece of information. It is possible that the tick gives information earlier (more stable) thanSymbolInfoTick.

By the way, here is the tick which came with a delay of a minute and a half:

New MA Maximum difference 97082 SBPR-3.19 Local time 2019.03.15 21:05:31.842 Tick time 2019.03.15 21:03:54.760

There was nothing criminal in the tick history this minute. Two ticks in a minute.

You, are completely missing the point!

Don't care about your local time at all.

Only the time of the TRADING server is important!

There are trading sessions, during this time you can trade.

Trading time is not determined by your local time,

and the time of the trade server.

 
prostotrader:

You are completely missing the point!

You don't care about your local time at all.

Only the time of the TRADING server matters!

There are trading sessions, during this time you can trade.

Trading time is not determined by your local time,

and the time of the trade server.

I must have poorly explained the point.fxsaber, understood me because he understands the importance of getting new ticks without delays and gave a link to his indicator, which does the same thing as my code, but in graphical form. It has no relation to exchange timing.

I will try to explain it on my fingers.

At 16:39.59.999 local time the Expert Advisor receives the first tick, for each symbol from market overview and stores it.

At 16:40.00.000, the Expert Advisor polls the last tick for each symbol again. For some of them we get new ticks.

Most of the new ticks have a time ( time_msc ) of about 16:39.59.000. But one came with a time of 16:38.30.335.

It turns out, that there was no tick at 16:39.59.999 (local), but it suddenly appeared a millisecond later and even was 16:38:30, although usually it's different only by a second.

After such ticks not a good idea occurs. Suppose we request the last tick from the illiquid symbol in the real trade. We obtain the time of tick (time_msc)

which differs from the local one by two minutes. Immediately there are assumptions that someone already knows about a tick that occurred 90, 60, or 30 seconds ago, and our EA does not know about it, and it may be punished by a hit to a limit order, for example.

This problem must be solved.

 
pivomoe:

Thefxsaber understood me, because he understands the importance of getting new ticks without delays and gave a link to his indicator, which does something similar to my code, but in graphical form. It has no relation to exchange timing.

I will try to explain on my fingers.

At 16:39.59.999 local time the Expert Advisor receives the first tick, for each symbol from market overview and stores it.

At 16:40.00.000, the Expert Advisor polls the last tick for each symbol again. For some of them we get new ticks.

Most of the new ticks come with a time ( time_msc ) of about 16:39.59.000. But one came with a time of 16:38.30.335.

It turns out, that there was no tick at 16:39.59.999 (local), but it suddenly appeared a millisecond later and even was 16:38:30, although usually it's different only by a second.

After such ticks not a good idea occurs. Suppose we request the last tick from the illiquid symbol in the real trade. We obtain the time of tick (time_msc)

which differs from the local one by two minutes. Immediately there are assumptions that someone already knows about a tick that occurred 90, 60, or 30 seconds ago, and our EA does not know about it, and it may be punished by a hit to a limit order, for example.

This problem must be solved.

You don't have to "fight" anything. You should understand how ticks are received in the terminal and correctly

process them correctly!

https://www.mql5.com/ru/code/16210

Лента всех сделок
Лента всех сделок
  • www.mql5.com
Хитрый усреднитель Hello Smart Эксперт усредняет убыточные позиции по определенному алгоритму. ColorJSatl_Digit Сглаженный быстрый цифровой фильтр JSatl с цветовой индикацией направления движения, с отображением последнего значения в виде ценовой метки и с возможностью округлять уровни...
 
prostotrader:

There is no need to "fight" anything, but to understand how the ticks come into the terminal and to handle them correctly!

Handle them properly!

Can you finally share this knowledge ? Even if through your method, you can get a new tick event sooner, it turns out that you give me a fish and not a fishing rod, ie do not explain why this is the case.

Where do you get the confidence that your method is faster than mine ? Did I miss something in the documentation ? Maybe you've determined experimentally that the terminal is more willing to give new ticks when subscribed to a glass?

I will implement the switch in this EA from my way of catching new ticks to yours.

 
pivomoe:

Can you finally share this knowledge ? Even if through your method, you can get a new tick event sooner, it turns out that you are giving me a fish and not a fishing rod i.e. you don't explain why this is the case.

Where do you get the confidence that your method is faster than mine ? Did I miss something in the documentation ? Maybe you've determined experimentally that the terminal gives new ticks more readily by subscribing to a glass?

I will implement switch in this EA from my way of catching new ticks to yours.

There is the source code with comments.

Do you feel lazy to look through it? Or something is not clear?

Reason: