No market orders in Book Event

philikn  

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.

philikn  

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?

জচেলিনো  
philikn:

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.

Phil

Have you already tried to read the article below?

[ ]'s

MQL5 Cookbook: Implementing Your Own Depth of Market
MQL5 Cookbook: Implementing Your Own Depth of Market
  • www.mql5.com
MQL5 language is constantly evolving and offering more opportunities for operation with exchange information every year. One of such exchange data types is information about Depth of Market. It is a special table showing price levels and volumes of limit orders. MetaTrader 5 has a built-in Depth of Market for displaying limit orders, but it is...
FRANCISCO LIMJAP DE GUZMAN  
philikn:

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.


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?


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".

https://www.mql5.com/en/articles/3336#i3

Implementing a Scalping Market Depth Using the CGraphic Library
Implementing a Scalping Market Depth Using the CGraphic Library
  • www.mql5.com
Now, we will start to work with this improved and revised version trying to gradually turn it into a scalping Market Depth tool. Overview of the CPanel graphics library There are many articles devoted to the creation of user interfaces in MQL5. Anatoly Kazharsky's "Graphical Interfaces" series stands out among them. It is difficult to add...
Alain Verleyen  
philikn:

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.

Phil

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.
rrocchi  
Alain Verleyen:
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 Alain Verleyen 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) 
Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
  • www.mql5.com
[in]  The number of requested ticks. If the 'from' and 'count' parameters are not specified, all available recent ticks (but not more than 2000) will be written to ticks_array[]. The first call of CopyTicks() initiates synchronization of the symbol's tick database stored on the hard disk. If the local database does not provide all the requested...
douglas14  
rrocchi:

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

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

It will give you this output.  

Gentlemen,

I had the same doubt of  philikn and this Topic helped a lot. One more question is: my book array: MqlBookInfo book[]; has the size of only 32 always, for whatever asset being used.

You guys know if this 32 is a limitation, is incorrect, or can be setted up to a variable size ?

Reason: