No market orders in Book Event

To add comments, please log in or register
philikn
38
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
38
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
38
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

Joscelino Celso de Oliveira
434
Joscelino Celso de Oliveira  
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...
fdeguzman
55
fdeguzman  
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...
To add comments, please log in or register