How to access market orders from OnBookEvent

Hello,

i want to catch market orders in OnBookEvent(). But all i get are limit orders of the market depth.

My Code:

//+------------------------------------------------------------------+
//|                                                     testbook.mq5 |
//+------------------------------------------------------------------+
int OnInit()
{    
   MarketBookAdd(_Symbol);
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   MarketBookRelease(_Symbol);
}
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
{

   MqlBookInfo BookInfo[];
        
   if (MarketBookGet(_Symbol,BookInfo))
   {
      for(int i=0;i<ArraySize(BookInfo)-1;i++)
      {
         
         if (BookInfo[i].type == BOOK_TYPE_SELL_MARKET)
            Print("Market Sell Order never happens!");
            
         if (BookInfo[i].type == BOOK_TYPE_BUY_MARKET)
            Print("Market Buy Order never happens!");  
            
            
         Print("Price: " + DoubleToString(BookInfo[i].price, Digits()) + "; " + 
               "Volume: " + (string)BookInfo[i].volume_real + "; " + 
               "Type: " + EnumToString(BookInfo[i].type));
      }
   }
}  
//+------------------------------------------------------------------+

This is what happens:

Metatrader5 clearly shows me market orders on the left with volume. But my expert cant see it? How do i get market orders with code?

Thank you.

Ok. I got a bit further, but not really. It is still a mystery to me what information exactly Metatrader 5 displays in his trade information table.

So i found out that market sell and buy orders are apparently also(?) in MqlTick? But not everything somehow.

Here is what i have done to dissect and display all tick information.

void OnTick()
{
   MqlTick last_tick;   
   if (SymbolInfoTick(Symbol(),last_tick))   
   {
   
      double aAsk = last_tick.ask;
      double aBid = last_tick.bid; 
      
   
      string s = "";
      
      if((last_tick.flags &TICK_FLAG_BID) > 0)     s+="BID|";
      if((last_tick.flags & TICK_FLAG_ASK) > 0)    s+="ASK|";
      if((last_tick.flags & TICK_FLAG_LAST) > 0)   s+="LAST|";
      if((last_tick.flags & TICK_FLAG_VOLUME) > 0) s+="VOL|";
      if((last_tick.flags & TICK_FLAG_BUY) > 0)    s+="BUY|";
      if((last_tick.flags & TICK_FLAG_SELL) > 0 )  s+="SELL|";
      
      
      Print(TimeToString(last_tick.time, TIME_SECONDS) +"."+ IntegerToString(last_tick.time_msc%1000), 
                         "| ", s , "("+IntegerToString(last_tick.flags)+")",
                         "| Bid: ", aBid, " | Ask: ", aAsk,  
                         " | Last: ", last_tick.last, 
                         " | ", last_tick.volume_real);
                         
                         
   }   
}

But what i find is this:

Maybe Metatrader is guessing here? So if market depth of limit book changes MT5 just assumes an order was executed when liquidity was taken off the limit book? It could just have been a cancellation of a limit order, right? I am not even sure this is done.

Can somebody shine some light on this?

How can i get the same information in my EA as Metatrader Displays in his trading table? And secondly: Is this even sensible, since the information seems to be innaccurate and a mix of limit order cancellation and real trades?

So apparently nobody seems to know this?

Can i talk to Metatrader support about this or are they likely not answering these kind of requests?

Is there some other section/community/forum i can talk to about this?

Thanks for pointers in any direction.

Have you already tried to read the article below?

Due to the speed of incoming ticks, OnTick() does not capture every tick. Improve your code by following the suggestion in this article.

Get to the part “Synchronizing the tick stream with the order book”.

You are confusing different things, Depth of Market is not the same as Time and Sales. You would need to check the ticks (CopyTicks) to “read” time and sales.

Complementing correct information. There is a full working script here:

https://www.mql5.com/en/docs/series/copyticks

It will give you this output.

//+------------------------------------------------------------------+ 
/* Example of the output 
Si-12.16: received 11048387 ticks in 4937 ms 
Last tick time = 2016.09.26 18:32:59.775  
First tick time = 2015.06.18 09:45:01.000  
1.  2016.09.26 09:45.249 Ask=65370 Bid=65370 (Info tick) 
2.  2016.09.26 09:47.420 Ask=65370 Bid=65370 (Info tick) 
3.  2016.09.26 09:50.893 Ask=65370 Bid=65370 (Info tick) 
4.  2016.09.26 09:51.827 Ask=65370 Bid=65370 (Info tick) 
5.  2016.09.26 09:53.810 Ask=65370 Bid=65370 (Info tick) 
6.  2016.09.26 09:54.491 Ask=65370 Bid=65370 (Info tick) 
7.  2016.09.26 09:55.913 Ask=65370 Bid=65370 (Info tick) 
8.  2016.09.26 09:59.350 Ask=65370 Bid=65370 (Info tick) 
9.  2016.09.26 09:59.678 Bid=65370 (Info tick) 
10. 2016.09.26 10:00.000 Sell Tick: Last=65367 Volume=3 (Trade tick) 
11. 2016.09.26 10:00.000 Sell Tick: Last=65335 Volume=45 (Trade tick) 
12. 2016.09.26 10:00.000 Sell Tick: Last=65334 Volume=95 (Trade tick) 
13. 2016.09.26 10:00.191 Sell Tick: Last=65319 Volume=1 (Trade tick) 
14. 2016.09.26 10:00.191 Sell Tick: Last=65317 Volume=1 (Trade tick) 
15. 2016.09.26 10:00.191 Sell Tick: Last=65316 Volume=1 (Trade tick) 
16. 2016.09.26 10:00.191 Sell Tick: Last=65316 Volume=10 (Trade tick) 
17. 2016.09.26 10:00.191 Sell Tick: Last=65315 Volume=5 (Trade tick) 
18. 2016.09.26 10:00.191 Sell Tick: Last=65313 Volume=3 (Trade tick) 
19. 2016.09.26 10:00.191 Sell Tick: Last=65307 Volume=25 (Trade tick) 
20. 2016.09.26 10:00.191 Sell Tick: Last=65304 Volume=1 (Trade tick) 
21. 2016.09.26 10:00.191 Sell Tick: Last=65301 Volume=1 (Trade tick) 

https://www.mql5.com/en/docs/series/copyticks