Download MetaTrader 5

Questions about MarketBookGet and L2 Depth of Market

To add comments, please log in or register
Do you know that MQL5 is an object-oriented language?
k.doras
74
k.doras 2014.08.13 08:49 

Dear all,

 

I was recently trying out the new MT5/MQL5 features about accessing the Depth of Market infortmation programatically. However, I do have a question.

I currently have an account by a broker starting with A*****. Unfortunately, this acc can only be used using MT4. For testing purposes I opened a Demo Account to use it with MT5 and read out DoM information.

 

I do understand that DoM information  must be provided by the broker to be accessible, so I checked that and confirmed that the information is there - at least within the GUI (see screenshot)

 

DoM EURUSD 

 

So I tried accesing the information in an EA using the following code:

 

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2012, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property version   "1.00"

MqlBookInfo priceArray[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   bool add=MarketBookAdd(NULL);
   if(add) Print("Market Book added.");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {

   bool getBook=MarketBookGet(NULL,priceArray);
   if(getBook)
     {
      int size=ArraySize(priceArray);
      Print("MarketBookInfo about ",Symbol());
     }
   else
     {
      Print("Failed to receive DOM for the symbol ",Symbol());
     }

 

However, it seems that the information is not accesible:

 Log

 

 

So my question is:

 

Is it possible, that the programatically access on the DoM information is prohibited explicitly (from the broker), although the information is accessible from the Terminal GUI?

 

 

Thanks in advance  

Alain Verleyen
Moderator
30744
Alain Verleyen 2014.08.13 09:39  

Your code works for me with Alpari-MT5 server.

I suggest you to modify this line of code :

      Print("Failed to receive DOM for the symbol ",Symbol()," error : ",GetLastError());

That can eventually give you more information.

k.doras
74
k.doras 2014.08.13 10:09  

Thanks for testing it! 

Have you tested it on a live or a demo account?

Alain Verleyen
Moderator
30744
Alain Verleyen 2014.08.13 10:11  
k.doras:

Thanks for testing it! 

Have you tested it on a live or a demo account?

A demo. I don't have a real account with DOM available.
k.doras
74
k.doras 2014.08.13 10:14  

Okay, I have tested it again on a different machine and indeed it now works. So it might be a corrupted MT5 installation. When I am back from work I will test your suggestion. 

Rodrigo Malacarne
Moderator
9904
Rodrigo Malacarne 2014.08.13 11:44  
k.doras:

Okay, I have tested it again on a different machine and indeed it now works. So it might be a corrupted MT5 installation. When I am back from work I will test your suggestion. 

Please observe which MT5 version you're using... according to this post on the Portuguese Section, a small bug was introduced with Build 965, which made the MarketBookGet() function to return false all the time.

I've written to MQ's Service Desk and, as I've already tested, this bug was already corrected on Build 975.

So, the only thing you have to do is to update your MT5 version.

I hope it helps.
Malacarne 

Alain Verleyen
Moderator
30744
Alain Verleyen 2014.08.13 14:04  
Malacarne:

Please observe which MT5 version you're using... according to this post on the Portuguese Section, a small bug was introduced with Build 965, which made the MarketBookGet() function to return false all the time.

I've written to MQ's Service Desk and, as I've already tested, this bug was already corrected on Build 975.

So, the only thing you have to do is to update your MT5 version.

I hope it helps.
Malacarne 

My test was made with build 969.
k.doras
74
k.doras 2014.08.14 19:30  

Thanks for your answers. You are correct that I tested it on Build 975 - that's were it failed.

 

All other builds seem to work correctly regarding this bus.

 

Thanks again. 

To add comments, please log in or register