Can an indicator get best ask/bid volume in real time?

 

I'm trying to create a simple panel/indicator that retrieves the best ask volume and the best bid volume in real time... However, after reading the MQL5 docs I found the information that OnBookEvent( ) works only for expert advisors, but not for indicators. Even setting OnTimer( ) to 10 miliseconds I'm not getting the information refreshed inside my panel.

In this case I cannot use OnCalculate( ), because the best ask volume and the best bid volume do change even when no trade occurs. Let me show the code I'm using:

#property version       "1.000"
#property description   "SIMPLE PANEL"
//+------------------------------------------------------------------+
//| INCLUDES                                                                       |
//+------------------------------------------------------------------+
#include <Controls\Dialog.mqh>
#include <Controls\Label.mqh>
#include <Controls\Panel.mqh>
//+------------------------------------------------------------------+
//| GLOBAL PARAMETERS AND VARIABLES                                                |
//+------------------------------------------------------------------+
MqlBookInfo       BookInfo[];
CAppDialog myPanel;
CLabel BidVolume;
CLabel AskVolume;
//+------------------------------------------------------------------+
//| ON INIT                                                                        |
//+------------------------------------------------------------------+
int OnInit() {
//--- Adding the DOM for the Symbol
   MarketBookAdd(_Symbol);
//--- Setting OnTimer interval
   EventSetMillisecondTimer(10);
//--- Creating panel
   myPanel.Create(0, "SIMPLE PANEL", 0, 20, 20, 200, 200);
//--- Creating ask volume label
   AskVolume.Create(0,"Ask volume",0,0,0,0,0);
   myPanel.Add(AskVolume);
//--- Creating bid volume label
   BidVolume.Create(0,"Bid volume",0,0,15,0,0);
   myPanel.Add(BidVolume);
//--- Setting initial values for bid and ask volumes
   MarketBookGet(NULL,BookInfo);
   for(int i=0;i<ArraySize(BookInfo)-1;i++)
     {
      if(BookInfo[i].type != BookInfo[i+1].type)
        {
         AskVolume.Text("Ask volume = "+BookInfo[i].volume);
         BidVolume.Text("Bid volume = "+BookInfo[i+1].volume);
        }
     }
//--- Run panel
   myPanel.Run();   
//--- Return
   return(0);
}
//+------------------------------------------------------------------+
//| ON DEINIT                                                                      |
//+------------------------------------------------------------------+
void OnDeinit(const int reason){
//--- Destroy panel
   myPanel.Destroy(reason);
//--- Libera o DOM do ativo
   MarketBookRelease(_Symbol);
//--- Apaga todos os objetos
   ObjectsDeleteAll(0,0);
//--- Remove timer
   EventKillTimer();
//---   
}
//+------------------------------------------------------------------+
//| ON TIMER                                                                       |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
   MarketBookGet(NULL,BookInfo);
//---
   for(int i=0;i<ArraySize(BookInfo)-1;i++)
     {
      if(BookInfo[i].type != BookInfo[i+1].type)
        {
         AskVolume.Text("Ask volume = "+BookInfo[i].volume);
         BidVolume.Text("Bid volume = "+BookInfo[i+1].volume);
        }
     }

}
//+------------------------------------------------------------------+
//| ON CHART EVENT                                                                 |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
//---
   myPanel.ChartEvent(id, lparam, dparam, sparam);
//--- 
}

Although I'm able to correctly refresh the information using other methods, like Print( ) or Comment( ), I'm not able to refresh the information (with the desired frequency) inside the panel. It seems that the information is refreshed only when a new tick occurs..

Could you please tell me if what I'm trying to achieve is actually possible and, if possible, help me to identify where is the problem?

Thanks in advance! 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Environment State / Symbol Properties - Documentation on MQL5
 
You probably need a timer resolution lesser than 10 milliseconds.
 

Hello Alain,

thanks for the comment. I've tried a smaller timer frequency (1 milisecond) and it doesn't work either. As said, commands like Print( ) and Comment( ) do return the correct information when a new event occurs on the DOM. However I'm not able to properly refresh the information inside the panel. I believe I'm doing something wrong... any idea?

 
Malacarne:

Hello Alain,

thanks for the comment. I've tried a smaller timer frequency (1 milisecond) and it doesn't work either. As said, commands like Print( ) and Comment( ) do return the correct information when a new event occurs on the DOM. However I'm not able to properly refresh the information inside the panel. I believe I'm doing something wrong... any idea?

Ah sorry, I missed the point.

Try to add the following line :

      if(BookInfo[i].type != BookInfo[i+1].type)
        {
         AskVolume.Text("Ask volume = "+BookInfo[i].volume);
         BidVolume.Text("Bid volume = "+BookInfo[i+1].volume);
         myPanel.Run();
        }
 

Thanks again Alain!

It works perfectly !!!

 

by use this method ,we can only get the volume that has not excuted by sever ,is it not ?

if it is ,how  to know the volume of bid and ask of the newest tick ?  not the sum volume of bid and ask .


 

Hi,Rodrigo Malacarne & Alain Verleyen can i add alert for this panel ?

Alert =

BidVolume value < 1000 ?
 
30yami:

Hi,Rodrigo Malacarne & Alain Verleyen can i add alert for this panel ?

Alert =

Perhaps you will be helped by this article:

Adding a control panel to an indicator or an Expert Advisor in no time

Adding a control panel to an indicator or an Expert Advisor in no time

Have you ever felt the need to add a graphical panel to your indicator or Expert Advisor for greater speed and convenience? In this article, you will find out how to implement the dialog panel with...


 

Hi, 

Can this panel show Total ask volume and Total bid volume ?


Reason: