Can't use market depth in EA anymore

 

Hi there,

for quite a while I was using market depth info in my EA on a demo account. Suddenly (maybe an update of MT5 platform) I can't anymore, unless it's window is manually opened in the MT5. The code to get the market depth goes like

MqlBookInfo priceArray[];
bool getBook=MarketBookGet(Symbol(),priceArray);

if(getBook) {

  // here goes the code to process it

} else {

  // now always going here

}

Do you have any idea why is this so? How could I solve it? I don't want to open that MD window always, just for my EA to work. Much thanks.

 

Please read the documentation of MarketBookGet().

Note

The Depth of Market must be pre-opened by the MarketBookAdd() function.

 
Yes you're right, don't know how it worked till now ;), thanks
 

I used the "MarketBookAdd" and "MarketBookGet" functions to get market depth information. Please advise how I can get the Bid volume for example and save it to compare the Bid volume in the next ticks. My programming literacy is low. Thank you for your help and if possible, write the code line so that I can use it. Thanks

my code is :

 
yasser.danesh #:

I used the "MarketBookAdd" and "MarketBookGet" functions to get market depth information. Please advise how I can get the Bid volume for example and save it to compare the Bid volume in the next ticks. My programming literacy is low. Thank you for your help and if possible, write the code line so that I can use it. Thanks

my code is :

Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window
 
yasser.danesh #:
Do you really understand what an order book is and how it works?   And what do you mean by tick?  A time unit? (like in tick chart) Or do you mean the smallest distance between two possible prices?
"how I can get the Bid volume for example and save it to compare the Bid volume in the next ticks."
What do you mean? At one point in time there are many bid prices and volumes in the order book of the exchange.What do you want to compare with what?
 
Alain Verleyen #:

Please read the documentation of MarketBookGet().

I have no problem with the direction of the said functions to get the depth of the market. My question is:
I use mql to write directional code in my country's stock market. Our country's stock market is such that our stocks have a limited range. This means that each daily share can have a 5% increase or decrease in price. Each time it has a share in its lowest range for high sales but uses it there is no buy. At this time the volume of willow is high. I want to bring and save Bid volume at this lowest price. And every moment of the market I check how much of this volume of paper. I want to buy when this accumulated volume has been being bought by always and is now running out.Because after that, the share usually increases in price by a few percent. Our country's stock market is open during the day. For example, at the beginning of the market, I want to put the stock that has accumulated Bid volume at the lowest price of the fluctuation range in the watch list, and obtain and save their Bid volume, and compare the Bid volume with it at any time in the market. . Please teach me how to save this volume for further comparison. thank you
 
Willbur #:
Do you really understand what an order book is and how it works?   And what do you mean by tick?  A time unit? (like in tick chart) Or do you mean the smallest distance between two possible prices?
"how I can get the Bid volume for example and save it to compare the Bid volume in the next ticks."
What do you mean? At one point in time there are many bid prices and volumes in the order book of the exchange.What do you want to compare with what?
I have no problem with the direction of the said functions to get the depth of the market. My question is:
I use mql to write directional code in my country's stock market. Our country's stock market is such that our stocks have a limited range. This means that each daily share can have a 5% increase or decrease in price. Each time it has a share in its lowest range for high sales but uses it there is no buy. At this time the volume of willow is high. I want to bring and save Bid volume at this lowest price. And every moment of the market I check how much of this volume of paper. I want to buy when this accumulated volume has been being bought by always and is now running out.Because after that, the share usually increases in price by a few percent. Our country's stock market is open during the day. For example, at the beginning of the market, I want to put the stock that has accumulated Bid volume at the lowest price of the fluctuation range in the watch list, and obtain and save their Bid volume, and compare the Bid volume with it at any time in the market. . Please teach me how to save this volume for further comparison. thank you
 
Alain Verleyen #:

Please read the documentation of MarketBookGet().

In addition, my code for gaining market depth is:
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
long ask_price=0;
long ask_volume = 0;
long bid_volume = 0;
MqlBookInfo BookInfo[];
MarketBookAdd(_Symbol);
MarketBookGet(_Symbol,BookInfo);
for(int i=0;i<ArraySize(BookInfo)-1;i++)
  {
   if(BookInfo[i].type != BookInfo[i+1].type)
     {
     ask_price= BookInfo[i].price;
      ask_volume = BookInfo[i].volume;
      bid_volume = BookInfo[i+1].volume;
     }
  }
 
  }
 
If I understood, it's like this:

      ask_volume += BookInfo[i].volume;
      bid_volume += BookInfo[i+1].volume;

Depending on how you want to use the values, you might need to save them in a global variable.
Reason: