CustomBookAdd Ajuda

Celso Carvalho  

Hi I'm trying to get data from the book with the example cited in docs. In order to write the indicator of the queue calculation (books [4] .volume = 10;) using a #property indicator_buffers 1. int CustomBookAdd (const string symbol, // const symbol name MqlBookInfo & books [] / / array with offer book element descriptions uint count = WHOLE_ARRAY // number of elements to use); Does anyone have a running model or example that writes in the graph. Abç (treasure is in your ideas) fm

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Order Book Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Order Book Structure
  • www.mql5.com
The MqlBookInfo  structure is predefined, thus it doesn't require any declaration and description. To use the structure, just declare a variable of this type.
torytory  

Hi,

I have created MqlBookInfo book_array , I use the entire array since this is used by default . I then use  MarketBookAdd within onInit() function with my CustomSymbolCreate symbol. 

MqlBookInfo

Finally I use the CustomBookAdd to update the MqlBookInfo book_array , then check the book_array elements to ensure book_array[counter + i].volume_real and .price values are correct. 


  if(  CustomBookAdd(GLOBAL_custom_symbol,book_array) != -1){
      Print(" Book: " + GLOBAL_custom_symbol + " updated successfully with tick: " + IntegerToString(Depth)    );
      
      
       Print(" Book Size: " +  ArraySize(book_array) + " Ask [0] " + book_array[0].price + " Q [0] " + book_array[0].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Ask [1] " + book_array[1].price + " Q [0] " + book_array[1].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Ask [2] " + book_array[2].price + " Q [0] " + book_array[2].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Ask [3] " + book_array[3].price + " Q [0] " + book_array[3].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Ask [4] " + book_array[4].price + " Q [0] " + book_array[4].volume_real );
       
       Print(" Book Size: " +  ArraySize(book_array) + " Bid [5] " + book_array[5].price + " Q [0] " + book_array[5].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Bid [6] " + book_array[6].price + " Q [0] " + book_array[6].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Bid [7] " + book_array[7].price + " Q [0] " + book_array[7].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Bid [8] " + book_array[8].price + " Q [0] " + book_array[8].volume_real );
       Print(" Book Size: " +  ArraySize(book_array) + " Bid [9] " + book_array[9].price + " Q [0] " + book_array[9].volume_real );
       
       Print("SYMBOL_TICKS_BOOKDEPTH" +  SymbolInfoInteger(GLOBAL_custom_symbol,SYMBOL_TICKS_BOOKDEPTH) );
       Print("SYMBOL_POINT" +  SymbolInfoDouble(GLOBAL_custom_symbol,SYMBOL_POINT) );
      
      
      
      return(true);
    }else{
     Alert(" Book: " + GLOBAL_custom_symbol + " update failed: " + IntegerToString( GetLastError() ) );
     ResetLastError();
     return(false);
    }

 My issue now, is that the Depth of Market (DOM) is still waiting for updates. The return value is not -1 , therefore I can Print out the data in the experts Tab as the image shows. What did I overlook? 

torytory  

Is it mandatory to use the CustomTicksAdd to trigger the DOM?

"When throwing the Depth of Market in, the symbol's Bid and Ask prices are not updated. You should control the change of the best pricesand throw in the ticks using CustomTicksAdd."

Documentation on MQL5: Custom Symbols / CustomTicksAdd
Documentation on MQL5: Custom Symbols / CustomTicksAdd
  • www.mql5.com
[in]   An array of tick data of the MqlTick type arranged in order of time from earlier data to more recent ones, i.e. ticks[k].time_msc <= ticks[n].time_msc, if k<n. function only works for custom symbols opened in the Market Watch window. If the symbol is not selected in Market Watch, then you should add ticks using CustomTicksReplace...
Alain Verleyen  
torytory:

Hi,

I have created MqlBookInfo book_array , I use the entire array since this is used by default . I then use  MarketBookAdd within onInit() function with my CustomSymbolCreate symbol. 


Finally I use the CustomBookAdd to update the MqlBookInfo book_array , then check the book_array elements to ensure book_array[counter + i].volume_real and .price values are correct. 


 My issue now, is that the Depth of Market (DOM) is still waiting for updates. The return value is not -1 , therefore I can Print out the data in the experts Tab as the image shows. What did I overlook? 

Did you enable the DOM ? Documentation :

The CustomBookAdd function works only for custom symbols the Depth of Market is opened for — via the platform interface or the MarketBookAdd function.

torytory  
Alain Verleyen:

Did you enable the DOM ? Documentation :

Yes Sir. I have the DOM open with the correct CustomSymbol attached to that opened DOM.


DOM 1

I have also tried the MarketBookAdd within the OnInit() without any returned value checking. I changed the code to and I have successfully triggered the MarketBoodAdd successfully

 if( MarketBookAdd(GLOBAL_custom_symbol) )
 {
   Print(" DOM SUCCESSFULLY OPENED ON:" + GLOBAL_custom_symbol);
 }else{
   Print(" DOM FAILED ON:" + GLOBAL_custom_symbol);
 }


Finally I have a plotting of values within the DOM. 


DOM 2

Now, Issue #1 is that the DOM displays the book_array[i].volume_real as a value of 0.000000x Volume ( Yes double value is correct), instead of the proper values being printed in the image ( these printed values are 0.01 at smallest).  Please see the previous post 


book_array[rates_counter_buy + i].volume_real = NormalizeDouble(price_bid_1_q,Create_Symbol_Digits);// // VOLUME_REAL IS double
torytory  
What marketinfoconstants requires adjustment?
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
To obtain the current market information there are several functions: SymbolInfoInteger(), SymbolInfoDouble() and SymbolInfoString(). The first parameter is the symbol name, the values of the second function parameter can be one of the identifiers of ENUM_SYMBOL_INFO_INTEGER, ENUM_SYMBOL_INFO_DOUBLE and ENUM_SYMBOL_INFO_STRING. Some symbols...
torytory  

Is this a Bug in the DOM? The Chart Comments is from an Expert Advisor that subscribes to the attached Symbol. It seems to work with CustomCharts and Normal Charts which is great to know. However, the values of the comments display correctly (It displays the values that I pass into the CustomBookAdd function from another Expert Advisor), but the DOM Quanity book[].real_volume does not show the proper values. 


DOM shows wrong values

torytory  

The next question/bug is how to make the DOM real time? At first, I thought CustomTicksAdd  needed to be updated to trigger the DOM, but after adding the necessary code to generate the mqlTick database, the DOM still doesn't update. I run the CustomBookAdd before I run the CustomTicksAdd but this should matter since on the next tick update works while the DOM is still sleeping. 


DOM not realtime

torytory  
Does the OnOrderBook event only fire 1 time per second? EDIT: Depends on the broker. Some can update faster than once per second, other broker may only update at 1 second intervals. 
Alain Verleyen  
torytory:

Is this a Bug in the DOM? The Chart Comments is from an Expert Advisor that subscribes to the attached Symbol. It seems to work with CustomCharts and Normal Charts which is great to know. However, the values of the comments display correctly (It displays the values that I pass into the CustomBookAdd function from another Expert Advisor), but the DOM Quanity book[].real_volume does not show the proper values. 

Unfortunately I didn't try the DOM yet with Custom symbols. But that seems a matter of setup of the custom symbol, you have to find the right settings. Look at a broker symbol to have a better idea.
torytory  

Tick_FLAG issues. Below is the int value that is assigned based on the ENUM TICK_FLAG ( not documented for some reason). 

TICK_FLAG_BID = (2)  tick has changed a Bid price

TICK_FLAG_ASK  = (4) a tick has changed an Ask price

TICK_FLAG_LAST = (8) a tick has changed the last deal price

TICK_FLAG_VOLUME = (16) a tick has changed a volume

TICK_FLAG_BUY = (32) a tick is a result of a buy deal

TICK_FLAG_SELL = (64) a tick is a result of a sell deal


Image below includes assigning the CustomTickAdd the flag of Bid and Ask, however, the time and sales comes back as type NA. 



Then I try the Tick Tag Buy and Sell with the same results


 You can tell what the flag is by the "Flag" number within the Print. Any help would be much appreciated. 

Documentation on MQL5: Integration / MetaTrader for Python / copy_ticks_from
Documentation on MQL5: Integration / MetaTrader for Python / copy_ticks_from
  • www.mql5.com
# create 'datetime' object in UTC time zone to avoid the implementation of a local time zone offset                  time      bid      ask  last  volume       time_msc  flags  volume_real 0 2020-01-10 00:00:00  1.11051  1.11069   0.0       0  1578614400987    134          0.0...