Download MetaTrader 5

how to detect a Double Click event on a Chart ?

To add comments, please log in or register
John
80
John  

Hi,

How can I detect a double click event on a Chart ?

I can do it for a single click using :

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

{


//new logic

   if(id==CHARTEVENT_CLICK)

   { ......

 

is there an CHARTEVENT_DOUBLECLICK  event ?

 

Thanks in advance. 

whroeder1
16105
whroeder1  
jfortes: is there an CHARTEVENT_DOUBLECLICK  event ?
Do you see any in the documention? Types of Chart Events - MQL4 Documentation

Halley
198
Halley  
jfortes:

Hi,

How can I detect a double click event on a Chart ?

I can do it for a single click using :

void OnChartEvent(const int id,

                  const long &lparam,

                  const double &dparam,

                  const string &sparam)

{


//new logic

   if(id==CHARTEVENT_CLICK)

   { ......

 

is there an CHARTEVENT_DOUBLECLICK  event ?

 

Thanks in advance. 


You cannot catch the system double-click event, but you may record the click time and coordinates and detect the double-click with your own metrics.
John
80
John  

Thanks DeepThought, good suggestion.

I will try to implement the logic: if x,y coordinates are clicked twice then consider a double click event. Thanks. 

h3nrixd
4
h3nrixd  
ulong click = 0;
ulong dclick = 200000;

int OnInit()
{
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   return(rates_total);
}

void OnChartEvent(const int id,
                  const long& lparam,
                  const double& dparam,
                  const string& sparam)
{
   int x = (int)lparam;
   int y = (int)dparam;

   int window  = 0;
   datetime dt = 0;
   double   p  = 0;
   
   if (ChartXYToTimePrice(0, x, y, window, dt, p))
   {
      if (id == CHARTEVENT_CLICK)
      {
         if (GetMicrosecondCount() - click < dclick)
         {
            onDoubleClick(id, lparam, dparam, sparam);
            click = 0;
         } else {
            onClick(id, lparam, dparam, sparam);
            click = GetMicrosecondCount();
         }
      }
   }
}

void onDoubleClick(const int id,
                  const long& lparam,
                  const double& dparam,
                  const string& sparam)
{
   int x = (int)lparam;
   int y = (int)dparam;

   int window  = 0;
   datetime dt = 0;
   double   p  = 0;

   if (ChartXYToTimePrice(0, x, y, window, dt, p))
      onXYDoubleClick(window, x, y, dt, p);      
}

void onClick(const int id,
                  const long& lparam,
                  const double& dparam,
                  const string& sparam)
{
   int x = (int)lparam;
   int y = (int)dparam;

   int window  = 0;
   datetime dt = 0;
   double   p  = 0;

   if (ChartXYToTimePrice(0, x, y, window, dt, p))
      onXYClick(window, x, y, dt, p);      
}

void onXYDoubleClick(int window, int x, int y, datetime dt, double p)
{
}

void onXYClick(int window, int x, int y, datetime dt, double p)
{
}
HaraldSchurr
67
HaraldSchurr  

//that's the sourcecode of an Indicator whose only purpose is to detect a doubleclick on the chart

//+------------------------------------------------------------------+
//|                                         detect a doubleclick.mq4 | //|                        Copyright 2017, MetaQuotes Software Corp. | //|                                        http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2017, MetaQuotes Software Corp." #property link      "http://www.metaquotes.net" #property  indicator_chart_window //************************************************************************************************************** //**************************************************************************************************************   int init() {    return(0) ; } //************************************************************************************************************** //************************************************************************************************************** int deinit() { return(0) ; } //************************************************************************************************************** //************************************************************************************************************** int start() { return(0) ; } //************************************************************************************************************** //************************************************************************************************************** void OnChartEvent(const int id,                   const long &lparam,                   const double &dparam,                   const string &sparam) {      if(id == CHARTEVENT_OBJECT_CLICK)  //custom defined Buttons for example      {         //Print("l: " + lparam + "      d: "  + dparam + "        s: " + sparam) ;                         return ;          }//end of: if(id == CHARTEVENT_OBJECT_CLICK)      //********************************************************      //********************************************************      if(id==CHARTEVENT_KEYDOWN)  //keystrokes      {         //Print("l: " + lparam + "      d: "  + dparam + "        s: " + sparam) ;                     return ;      }//end of: if(id==CHARTEVENT_KEYDOWN)           //********************************************************      //********************************************************      if(id==CHARTEVENT_CLICK)      {         //beginning of: detection of a doubleclick          static ulong ClickTimeMemory ; //static is crucial to remember ClickTimeMemory's content next time OnChartEvent() is called          //***                   ulong ClickTime = GetTickCount() ; //GetTickCount() uses milliseconds - it's not necessary to use GetMicrosecondCount()                   if(ClickTime > ClickTimeMemory && ClickTime < ClickTimeMemory + 300)   //the second click should appear within 300 milliseconds after the first click. That's 0.3 seconds - that's about the typical delay of the second click relative to the first click when making a doubleclick          {             Alert("just detected a doubleclick") ;          }                 //***                 ClickTimeMemory = ClickTime ;         //end of: detection of a doubleclick                       }//end of: if(id==CHARTEVENT_CLICK)      //********************************************************      //********************************************************      if(id == CHARTEVENT_MOUSE_MOVE)      {      }//end of: if(id == CHARTEVENT_MOUSE_MOVE)         //********************************************************      //********************************************************      return ;     }//end of: void OnChartEvent(...)
To add comments, please log in or register