Questions about MarketBookGet and L2 Depth of Market

 

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  

 

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.

 

Thanks for testing it! 

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

 
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.
 

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. 

 
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 

 
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.
 

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.