MarketBookGet() is returning different data than shown in Depth of Market

 

Hi All,

I am new in MQL5/trading and was learning its coding. One thing which is very strange for me is that when I call MarketBookGet() function on some symbol, it is giving me totally different values than shown in Depth of Market. I might be missing something, due to which I came here to get help.

Below is how I am calling it.

   MqlBookInfo bookDummy[];
   MarketBookGet(Symbol(), bookDummy);

in bookDummy variable I am getting totally different values than what is shown in DOM, like number of records, price levels and volume. Not a single record is matching. I have tried different symbols like AUDNZD, AUDCAD, GBPUSD randomly.

 
Provide a full working code, the results from your log and screenshot to demonstrate what you said.
 

what should i do?
difference between print and depth market. is this for ping?


//+------------------------------------------------------------------+
//|                                                 DEATH MARKET.mq5 |
//|                                  Copyright 2022, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

//+------------------------------------------------------------------+
//| 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()
  {
//---


//ArraySetAsSeries(BookInfo_array,true);



  }
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {
   Print("Book event for: "+symbol);
//--- select the symbol
   if(symbol==_Symbol)
     {
      //--- array of the DOM structures
      MqlBookInfo last_bookArray[];

      //--- get the book
      if(MarketBookGet(_Symbol,last_bookArray))
        {
         //--- process book data
         for(int idx=0;idx<ArraySize(last_bookArray);idx++)
           {
            MqlBookInfo curr_info=last_bookArray[idx];
            //--- print
            PrintFormat("Type: %s",EnumToString(curr_info.type));
            PrintFormat("Price: %0."+IntegerToString(_Digits)+"f",curr_info.price);
            PrintFormat("Volume: %d",curr_info.volume);
           }
        }
     }
  }
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.11.09
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Files: