MT5 and speed in action - page 65

 
fxsaber:
Was at the computer, did not do any calculations. Didn't load the CPU with anything.

19 ms and 48 ms for the execution of SymbolInfoTick. There were several dozens of cases where the duration was hundreds of microseconds. But I didn't cite them.


Apparently, in order to reproduce it, we need to run combat advisors for 24 hours, and then only watch. In my opinion, it is unrealistic to figure out what initiates such lags.

Sometimes the computer may be downloading updates or running some service tasks. Also, mains voltage fluctuations may affect it. This way you can get to programmable network cards, where all bot logic is written at hardware level :) but even there will be delays due to fluctuations of quantum field
 
Maxim Dmitrievsky:
Sometimes the comp may be pumping updates or doing some service tasks. Also, a mains voltage variation can have an effect. This way you can get to programmable network cards, where all bot logic is hardwired :) but even there will be delays due to quantum field fluctuations

The developers have done the best they can. And without that, the branch has provided code that shows how the tick is lagging behind the Market Watch and vice versa. How the tick arrival sequence is broken and probably something else. All in all, nasty valid code is posted to reproduce other situations.

 
Anton:

SymbolInfoTick sends the data received from the broker's server. What the server sends is what you get.

IsSymbolInfoTick() executed in blocking mode or in non-blocking mode?

For example, it is in the body of while loop and there is no connection or market is closed for weekend,
then it will be blocked by stopping the loop or it will be executed asynchronously?

 
fxsaber:

how the market watch lags behind the Market Watch and vice versa.

I.e. SymbolInfoTick catches a new tick and we get a different Ask and Bid through the Market Watch event (without waiting for Market Watch to change) ? It wasn't possible to do it a year or so ago. SymbolInfoTick and CopyTick and vintage always lead to the same tick. If you get ticks through various OnXXX functions, of course, you will get something through one function, and something through another...

 
pivomoe:

i.e. SymbolInfoTick catches a new tick and we get a different Ask and Bid through polling the cup (without waiting for cup change event) ?

Here.

 
fxsaber:

Here.

As I thought you are testing OnBookEvent and OnTick, not MarketBookGet and SymbolInfoTick. If you tested according to this scheme you would have everything matched:

While(1)
{
 Sleep(1)
 Запрос тика через SymbolInfoTick
 Запрос тика через стакан MarketBookGet
 Проверка на совпадение. 
}

p.s Read your posts below. You understand it too. Why do you need OnBookEvent and OnTick at all ? In my example Sleep(1) takes 1-2 milliseconds, request and tick with SymbloInfoTick takes less than MICROsecond. The processor is already resting 99.9% of the time if there are no ticks. What is the benefit of using OnBookEvent and OnTick ?

 
pivomoe:

As I thought you are testing OnBookEvent and OnTick, not MarketBookGet and SymbolInfoTick. If you were testing according to this scheme you would have everything matched:

p.s Read your posts below. You understand it too. Why do you need OnBookEvent and OnTick at all ? In my example Sleep(1) takes 1-2 milliseconds, request and tick with SymbloInfoTick takes less than MICROsecond. The processor is already resting 99.9% of the time if there are no ticks. What's the benefit of using OnBookEvent and OnTick ?

Without a hint of diplomacy, you are talking nonsense. Sleep(1) is a tenth of a millisecond. I see only one theorizing.

Users in OnTick want to see a fresh tick and not the one that arrived to the Terminal some time ago. You can put SymbolInfoTick right after MarketBookGet in the source code.


The developers have fully acknowledged two problems with their silence.

 
fxsaber:

Without a hint of diplomacy, you're talking nonsense. Sleep(1) is a dozen milliseconds. I see only one theorizing.

Users want to see a fresh tick in OnTick and not a tick that arrived to the Terminal some time ago. You can put SymbolInfoTick right after MarketBookGet in the source code.


The developers, by their silence, have fully acknowledged two problems.

Not always and not every tenth of a millisecond. Checked with a simple script

//+------------------------------------------------------------------+
//|                                                    TestSleep.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

#define  ITERATIONS 10000
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   ulong t1=GetMicrosecondCount();
   for(int i=0; i<ITERATIONS; i++)
     {
      Sleep(1);
     }
   ulong t2=GetMicrosecondCount()-t1;
   PrintFormat("total %I64u microseconds (%.3f ms per iteration)",t2,double(t2)/(ITERATIONS*1000.0));
  }
//+------------------------------------------------------------------+

Here is my log

2020.11.04 13:14:31.590 TestSleep (EURUSD,H1)   total 17058138 microseconds (1.706 ms per iteration)

OnTick users always see the freshest tick.

OnBookEvent users always see the freshest tick.

But if you want to compare the ticks received by OnTick and received by OnBookEvent, then you will be disappointed, because the events are processed sequentially, not in parallel. That's what user pivomoe tried to tell you

Документация по MQL5: Основы языка / Функции / Функции обработки событий
Документация по MQL5: Основы языка / Функции / Функции обработки событий
  • www.mql5.com
В языке MQL5 предусмотрена обработка некоторых предопределенных событий. Функции для обработки этих событий должны быть определены в программе MQL5: имя функции, тип возвращаемого значения, состав параметров (если они есть) и их типы должны строго соответствовать описанию функции-обработчика события. Именно по типу возвращаемого значения и по...
 
Slava:

Not always and not everywhere a tenth of a millisecond. Checked with a simple script

Here's my log.

And here is my log.

#include <fxsaber\Benchmark\Benchmark.mqh> // https://www.mql5.com/ru/code/31279

void OnStart()
{
  for (int i = 0; i < 5; i++)
    _BV(Sleep(1), 1);
}

Result.

2020.11.04 15:19:32.565 Alert: Bench_Stack = 0, 1 <= Time[Test9.mq5 93 in OnStart: Sleep(1)] = 5326 mcs.
2020.11.04 15:19:32.580 Alert: Bench_Stack = 0, 1 <= Time[Test9.mq5 93 in OnStart: Sleep(1)] = 14928 mcs.
2020.11.04 15:19:32.596 Alert: Bench_Stack = 0, 1 <= Time[Test9.mq5 93 in OnStart: Sleep(1)] = 15930 mcs.
2020.11.04 15:19:32.611 Alert: Bench_Stack = 0, 1 <= Time[Test9.mq5 93 in OnStart: Sleep(1)] = 14910 mcs.
2020.11.04 15:19:32.627 Alert: Bench_Stack = 0, 1 <= Time[Test9.mq5 93 in OnStart: Sleep(1)] = 15941 mcs.

OnTick users always see the freshest tick.

OnBookEvent users always see the freshest tick.

The result of running the EA on a single chart from a machine which is not busy in any way.

2020.11.04 15:31:19.151 Test9 (EURUSD,H1)       Alert: OnBook-lag! - 6564 mcs.
2020.11.04 15:31:19.151 Test9 (EURUSD,H1)             [bid]   [ask] [onTick] [Interval]
2020.11.04 15:31:19.151 Test9 (EURUSD,H1)       [0] 1.17192 1.17192     true     108150
2020.11.04 15:31:19.151 Test9 (EURUSD,H1)       [1] 1.17192 1.17192    false         30
2020.11.04 15:31:19.151 Test9 (EURUSD,H1)       [2] 1.17189 1.17191     true      88210
2020.11.04 15:31:19.151 Test9 (EURUSD,H1)       [3] 1.17189 1.17191    false       6564
2020.11.04 15:31:30.260 Test9 (EURUSD,H1)       Alert: OnBook-lag! - 3888 mcs.
2020.11.04 15:31:30.260 Test9 (EURUSD,H1)             [bid]   [ask] [onTick] [Interval]
2020.11.04 15:31:30.260 Test9 (EURUSD,H1)       [0] 1.17192 1.17192    false     117471
2020.11.04 15:31:30.260 Test9 (EURUSD,H1)       [1] 1.17192 1.17192     true         11
2020.11.04 15:31:30.260 Test9 (EURUSD,H1)       [2] 1.17192 1.17193     true     882710
2020.11.04 15:31:30.260 Test9 (EURUSD,H1)       [3] 1.17192 1.17193    false       3888
2020.11.04 15:31:31.519 Test9 (EURUSD,H1)       Alert: OnTick-lag! - 4653 mcs.
2020.11.04 15:31:31.519 Test9 (EURUSD,H1)             [bid]   [ask] [onTick] [Interval]
2020.11.04 15:31:31.519 Test9 (EURUSD,H1)       [0] 1.17195 1.17195     true      86660
2020.11.04 15:31:31.519 Test9 (EURUSD,H1)       [1] 1.17195 1.17195    false         11
2020.11.04 15:31:31.519 Test9 (EURUSD,H1)       [2] 1.17194 1.17194    false     220122
2020.11.04 15:31:31.519 Test9 (EURUSD,H1)       [3] 1.17194 1.17194     true       4653

Marks identical ticks, which are received in different On-functions by corresponding methods. The lag can be up to tens of milliseconds if run on six charts instead of one.

But if you want to compare ticks received in OnTick and received in OnBookEvent, then you will be disappointed because the events are processed sequentially, not in parallel. What user pivomoe tried to tell you

If a nearly empty OnBookEvent/OnTick is triggered 20 milliseconds later than the corresponding nearly empty OnTick/OnBookEvent, is that OK?


ZS While you're paying attention to the thread, there's another reproduction code here. There in Market Watch the ticks come in with a time earlier than the Market Watch time before that.

 
fxsaber:

If a nearly empty OnBookEvent/OnTick is triggered 20 milliseconds later than the corresponding nearly empty OnTick/OnBookEvent, is that OK?


The EA queue is a lockable resource. When an event is written to the queue, the Expert Advisor waits (unless the Expert Advisor is currently processing an event)

Events for the Expert Advisor come from the event queue of the corresponding chart, which in turn comes from the processing cycle of the corresponding symbol. And this loop of processing not only distributes events to its own charts, but also does a lot of other things.

I have already told you that Windows is not a real-time operating system.

Reason: