Tiki in real time - page 12

 
Sergey Chalyshev:

I would like to remind you that OnTick receives two independent threads, information and trade,COPY_TICKS_INFO and COPY_TICKS_ALL and undergoes preprocessing .

These threads are not synchronized with each other, so if you compare OnBookEvent with OnTick, you should takeTICKS_INFO.

By definition, OnBookEvent should be faster since it doesn't go through pre-processing.

The tests do not reliably determine who is faster, because we do not know the stock time of a tick, unlike ticks.

Although, we have many times asked developers to ADD STOCK TIME! ! !


p.s. besides speed, tumblr also has advantages over OnTick,

as already stated, it is not possible to get better Bid and Ask prices in OnTick,

andOnTick has no data from other symbols, it is useless for Expert Advisors analyzing several symbols.


changedCOPY_TICKS_ALL toCOPY_TICKS_INFO

Result

2020.01.31 19:45:17.893 Ticks_test (GOLD-3.20,M1)       OnTick: 2020.01.31 19:45:11.360 Ask=1591.4 
2020.01.31 19:45:17.894 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:09.384 Ask=1591.3 
2020.01.31 19:45:17.973 Ticks_test (GOLD-3.20,M1)       OnTick: 2020.01.31 19:45:11.570 Ask=1591.1 
2020.01.31 19:45:17.973 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:09.384 Ask=1591.3 
2020.01.31 19:45:18.060 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:09.384 Ask=1591.3 
2020.01.31 19:45:18.077 Ticks_test (GOLD-3.20,M1)       OnTick: 2020.01.31 19:45:11.712 Bid=1591.4 
2020.01.31 19:45:18.077 Ticks_test (GOLD-3.20,M1)       OnTick: 2020.01.31 19:45:11.712 Bid=1591.4 
2020.01.31 19:45:18.078 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:09.384 Ask=1591.3 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:10.574 Ask=1591.2 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:10.742 Bid=1591.2 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:11.360 Ask=1591.4 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:11.570 Ask=1591.1 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:11.570 Ask=1591.4 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:11.712 Bid=1591.4 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:11.712 Bid=1591.4 
2020.01.31 19:45:18.356 Ticks_test (GOLD-3.20,M1)       OnBookEvent: 2020.01.31 19:45:12.14 Ask=1591.2 

Marked in yellow - same tick!

There's probably an inaccuracy in the code after all...?
 

For a second there, it seemed like you had a desire to sort things out and it would help temper your pride.
No, it just seemed that way.

In general, the question is solved, and anyone can watch yours and fxsaber's and my codes, and draw conclusions.
With you I stop dialogue, nothing except loud shouting from you comes, and on reception of the information your brain does not work at all.

Good luck on FORTS.

 
Sergey Chalyshev:

I would like to remind you that OnTick receives two independent threads, information and trade,COPY_TICKS_INFO and COPY_TICKS_ALL and undergoes preprocessing .

These threads are not synchronized with each other, so if you compare OnBookEvent with OnTick, you should takeTICKS_INFO.

Sergei, we use On-functions simply as an entry point.

The question was which entry point would come first (while giving the same correct information about the last tick).

Run my EA, and look at the log. The time of the event (accurate to ms) and the time of the last known tick (also with ms) are output in the log.

Just analyse a few individual ticks for "who's earliest".


Sergey Chalyshev:

OnBookEvent should by definition be faster as it doesn't go through pre-processing.

I don't think OnTick does. And the tests confirm it, there's no delay.


Sergey Chalyshev:

As it was already said, it's impossible to get better Bid and Ask price in OnTick.

Possibly with CopyTicks.

Тики в реальном времени
Тики в реальном времени
  • 2020.01.31
  • www.mql5.com
Всем доброго времени суток. Появилась необходимость протестировать торговый алгоритм на реальных тиках брокера "Открытие...
 
Andrey Khatimlianskii:

Run my EA, and look at the log. The time of the event (accurate to ms) and the time of the last known tick (also with ms) are output to the log.

Just analyse a few individual ticks for "who's earliest".

A common situation is when OnBook comes at the same time as OnTick or 1-2ms later. But there are lags as well:


 

In 5 hours' time:

2020.01.31 20:45:48.214 TestTicks (GOLD-3.20,M15)       63906 USE_BOOK events received
2020.01.31 20:45:52.782 TestTicks (GOLD-3.20,M15)       31199 USE_TICK events received

Twice as many OnBook events. Pity not all of them carry a useful load (if best bid/ask and flipper are needed).

 
Andrey Khatimlianskii:

Sergey, we are using the On-functions simply as an entry point.

The question was which entry point would come first (while giving the same correct information about the last tick).

Run my EA, and look at the log. The time of the event (accurate to ms) and the time of the last known tick (also with ms) are output in the log.

Just analyse a few individual ticks for "who's earliest".

This is you doing it wrong. Perhaps the tumblr event has arrived but has not yet made it into the tick history. You should be comparing Bid Ask prices, not digging into the tick history.

I don't think OnTick passes it. And the tests confirm it, there is no delay.

Before entering the history the ticks are necessarily processed and also distributed to all necessary charts, indicators and Expert Advisors. And all this in MT5 is done sequentially (not paralleled).

Perhaps with the help of CopyTicks.

No, withCopyTicks it is also impossible to get the best price, and what if it is your order that stands the best.
 

Просто проанализируйте несколько отдельных тиков на предмет "кто раньше".

I've got a different way of doing things:

tick vs book

blue lines are OnBook,

The red ones are OnCalculat = OnTick.

If you are interested, I can show you the code

 
Sergey Chalyshev :

I get it differently:


blue lines are OnBook ,

red OnTick .

If interested, I can show the indicator code

No Serezha!

It must be admitted that OnBookEvent() and OnTick() all ticks are the same (I had a bug in the code),

but other DOM changes are not reflected in OnTick() in any way

This is not important for FOREX traders. (Cautious quote from the message above: " There are 2 times more OnBook events. It's a pity that not all of them carry a payload (if you need a best bid/ask and a last)". )

Corrected code:

 //+------------------------------------------------------------------+
//|                                                   Ticks_test.mq5 |
//|                                      Copyright 2019 prostotrader |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019 prostotrader"
#property link        "https://www.mql5.com"
#property version    "1.00"
//---
bool is_book;
MqlTick ticks[];
ulong last_time, mem_cnt, tot_cnt;
bool is_first;
int t_cnt, result;
enum ENUM_BOOK_OR_TICK
{
        USE_BOOK,       // Use OnBookEvent
        USE_TICK         // Use OnTick
};

input ENUM_BOOK_OR_TICK Mode = USE_BOOK;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit ()
{
  tot_cnt = 0 ;
   if (Mode == USE_BOOK) is_book = MarketBookAdd ( Symbol ());
  result = CopyTicks ( Symbol (), ticks, COPY_TICKS_ALL , 0 , 1 );
   if (result > 0 )
  {
    last_time = ulong (ticks[ 0 ].time_msc); //запоминаем время последнего известного тика
    is_first = true ;
  }
   else
  {
    is_first = false ;
     Alert ( "No start time!" );
     return ( INIT_FAILED );
  } 
   ArraySetAsSeries (ticks, true );  
   return ( INIT_SUCCEEDED );
}
//+------------------------------------------------------------------+ 
//| возвращает строковое описание тика                               | 
//+------------------------------------------------------------------+ 
string GetTickDescription( MqlTick &tick) 
  { 
   string res = string (tick.time) + "." +   string (tick.time_msc% 1000 ); 
// 
   bool buy_tick = ((tick.flags& TICK_FLAG_BUY )== TICK_FLAG_BUY ); 
   bool sell_tick = ((tick.flags& TICK_FLAG_SELL )== TICK_FLAG_SELL ); 
   bool ask_tick = ((tick.flags& TICK_FLAG_ASK )== TICK_FLAG_ASK ); 
   bool bid_tick = ((tick.flags& TICK_FLAG_BID )== TICK_FLAG_BID ); 
   bool last_tick = ((tick.flags& TICK_FLAG_LAST )== TICK_FLAG_LAST ); 
   bool volume_tick = ((tick.flags& TICK_FLAG_VOLUME )== TICK_FLAG_VOLUME ); 
// 
   if ((buy_tick== true ) || (sell_tick == true )) 
   { 
     res = res + (buy_tick? StringFormat ( " Buy Tick: Last=%G Volume=%d " ,tick.last,tick.volume): "" ); 
     res = res + (sell_tick? StringFormat ( " Sell Tick: Last=%G Volume=%d " ,tick.last,tick.volume): "" ); 
     res = res + (ask_tick? StringFormat ( " Ask=%G " ,tick.ask): "" ); 
     res = res + (bid_tick? StringFormat ( " Bid=%G " ,tick.bid): "" ); 
   } 
   else 
   { 
     res = res + (ask_tick? StringFormat ( " Ask=%G " ,tick.ask): "" ); 
     res = res + (bid_tick? StringFormat ( " Bid=%G " ,tick.bid): "" ); 
     res = res + (last_tick? StringFormat ( " Last=%G " ,tick.last): "" ); 
     res = res + (volume_tick? StringFormat ( " Volume=%d " ,tick.volume): "" ); 
   } 
   return res; 
  } 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit ( const int reason)
{
   if (Mode == USE_BOOK)
  {
     Print ( "USE_BOOK ticks received: " , tot_cnt);
     if (is_book == true ) MarketBookRelease ( Symbol ());
  }
   else
  {
     Print ( "USE_TICK ticks received: " , tot_cnt);
  }  
}
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent ( const string &symbol)
{
   if ( Mode != USE_BOOK || symbol != Symbol () ) return ;
  tot_cnt++;
   if (is_first == true )
  {
    result = CopyTicks ( Symbol (), ticks, COPY_TICKS_ALL , last_time, 0 ); //копируем все вновь пришедшие тики от последнего известного времени
     if (result > 0 )
    {
      t_cnt = 0 ;
       for ( int i= 0 ; i<result; i++)
      {
         if (ticks[i].time_msc == ticks[ 0 ].time_msc) t_cnt++;             //Считаем кол-во тиков с одинаковым временем
         Print ( __FUNCTION__ , ": " ,GetTickDescription(ticks[i]));
      }
      is_first = false ;
      last_time = ulong (ticks[ 0 ].time_msc);                             //Запоминаем время последнего тика
    } 
  }
   else
  {
    result = CopyTicks ( Symbol (), ticks, COPY_TICKS_ALL , last_time, 0 ); //забираем тики из последнего (посчитанного пакета тикив и считываем тики из нового пакета)
     if (result > 0 )
    {
       if (result > t_cnt)
      {
        mem_cnt = t_cnt;
        t_cnt = 0 ;
         for ( int i= 0 ; i<(result - int (mem_cnt)); i++)
        {
           if (ticks[i].time_msc == ticks[ 0 ].time_msc) t_cnt++;           //Считаем кол-во тиков с одинаковым временем
           Print ( __FUNCTION__ , ": " ,GetTickDescription(ticks[i]));
        } 
         if (last_time == ulong (ticks[ 0 ].time_msc))
        {
          t_cnt += int (mem_cnt);
        }
         else last_time = ulong (ticks[ 0 ].time_msc);
      }
       else
      {
         Print ( __FUNCTION__ , ": Pending order!" );                           //Изменения стакана (добавлен/удален отложенный ордер)
      }
    }
     else
    {
       Print ( __FUNCTION__ , ": Pending order!" );                             //Изменения стакана (добавлен/удален отложенный ордер)
    }
  }
}
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick ()
{
   if ( Mode != USE_TICK ) return ;
  tot_cnt++;
   if (is_first == true )
  {
    result = CopyTicks ( Symbol (), ticks, COPY_TICKS_ALL , last_time, 0 ); //копируем все вновь пришедшие тики от последнего известного времени
     if (result > 0 )
    {
      t_cnt = 0 ;
       for ( int i= 0 ; i<result; i++)
      {
         if (ticks[i].time_msc == ticks[ 0 ].time_msc) t_cnt++;             //Считаем кол-во тиков с одинаковым временем
         Print ( __FUNCTION__ , ": " ,GetTickDescription(ticks[i]));
      }
      is_first = false ;
      last_time = ulong (ticks[ 0 ].time_msc);                             //Запоминаем время последнего тика
    } 
  }
   else
  {
    result = CopyTicks ( Symbol (), ticks, COPY_TICKS_ALL , last_time, 0 ); //забираем тики из последнего (посчитанного пакета тикив и считываем тики из нового пакета)
     if (result > 0 )
    {
       if (result > t_cnt)
      {
        mem_cnt = t_cnt;
        t_cnt = 0 ;
         for ( int i= 0 ; i<(result - int (mem_cnt)); i++)
        {
           if (ticks[i].time_msc == ticks[ 0 ].time_msc) t_cnt++;           //Считаем кол-во тиков с одинаковым временем
           Print ( __FUNCTION__ , ": " ,GetTickDescription(ticks[i]));
        } 
         if (last_time == ulong (ticks[ 0 ].time_msc))
        {
          t_cnt += int (mem_cnt);
        }
         else last_time = ulong (ticks[ 0 ].time_msc);
      }
       else
      {
         Print ( __FUNCTION__ , ": Pending order!" );                           //Изменения стакана (добавлен/удален отложенный ордер)
      }
    }
     else
    {
       Print ( __FUNCTION__ , ": Pending order!" );                           //Изменения стакана (добавлен/удален отложенный ордер)
    }
  }
}
//+------------------------------------------------------------------+
Результат (фрагмент)
 2020.01 . 31 23 : 35 : 24.092 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 17.571 Bid= 1593.7 
2020.01 . 31 23 : 35 : 24.093 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 17.571 Bid= 1593.7 
2020.01 . 31 23 : 35 : 24.144 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 24.163 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 24.844 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 24.851 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 24.865 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.215 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.222 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.241 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.254 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.286 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.462 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.474 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.482 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.503 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.545 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 25.995 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.003 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.004 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.483 Buy Tick: Last= 1593.8 Volume= 1 
2020.01 . 31 23 : 35 : 26.011 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 19.484 Ask= 1593.9   Bid= 1593.8 
2020.01 . 31 23 : 35 : 26.012 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 19.484 Ask= 1593.9   Bid= 1593.8 
2020.01 . 31 23 : 35 : 26.061 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.075 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.142 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.155 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.162 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.191 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 26.213 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 27.293 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 27.345 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 27.936 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 27.943 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 28.166 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 28.172 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.657 Ask= 1594.1   Bid= 1593.9 
2020.01 . 31 23 : 35 : 28.172 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.172 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.172 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.172 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.172 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.173 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.657 Ask= 1594.1   Bid= 1593.9 
2020.01 . 31 23 : 35 : 28.173 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.173 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.173 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.173 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.173 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.650 Buy Tick: Last= 1593.9 Volume= 1 
2020.01 . 31 23 : 35 : 28.191 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 21.661 Ask= 1594 
2020.01 . 31 23 : 35 : 28.192 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : 2020.01 . 31 23 : 35 : 21.661 Ask= 1594 
2020.01 . 31 23 : 35 : 28.255 Ticks_test (GOLD- 3.20 ,M1)       OnBookEvent : Pending order!
2020.01 . 31 23 : 35 : 29.516 Ticks_test (GOLD- 3.20 ,M1)       USE_BOOK ticks received: 153
2020.01 . 31 23 : 35 : 29.892 Ticks_test (GOLD- 3.20 ,M1)       OnTick : 2020.01 . 31 23 : 35 : 23.367 Ask= 1594.1 
2020.01 . 31 23 : 35 : 31.660 Ticks_test (GOLD- 3.20 ,M1)       USE_TICK ticks received: 27
 
prostotrader:

No Seryozh!

I have to admit that OnBookEvent() and OnTick() all the ticks coincide (I had an error in the code),

but other changes in the glass are not reflected in OnTick()

For FOREX people it doesn't matter.(Cautious quote from post above: "2 times more OnTick events. Too bad not all of them carry a useful load (if you need best bid/ask and flipper)".)

Corrected code:

Result (snippet).

Ticks in history of course will match, but in the picture above, it turns out not all info-ticks get to history or are skipped in OnCalculat.

I don't know if there is an error, I will try to fix it on Monday.

 
prostotrader:


Or maybe for real time, instead of

MqlTick ticks[];
result = CopyTicks(Symbol(), ticks, COPY_TICKS_ALL, 0, 1);

use

MqlTick ticks[1];
bool success = SymbolInfoTick(_Symbol, ticks); //Возвращает текущие цены.

Why copy when you can immediately get the current price?
In theory, CopyTicks has in its guts extra parameter checks, thus increasing the length of code in the function body.
But SymbolInfoTick has no additional parameters, and in theory, the implementation of this function should contain less code.
Less code means faster execution.

The only bad thing is that the SymbolInfoTick function doesn't have detailed documentation similar to CopyTicks and it's not completely clear how it works.
Does it cache, or does it give back the raw data immediately.