ChartEvent Clicks Filter

 

I want to filter normal clicks on chart with clicks on objects

I am using this code but its not working

if(id == CHARTEVENT_CLICK && id!=CHARTEVENT_OBJECT_CLICK) {
//print something
}

How can I filter in these two types of clicks?

 
Rodger Sen:
if (id == CHARTEVENT_CLICK)
{  //print something }
else
if (id == CHARTEVENT_OBJECT_CLICK)
{  //print something }

Or simply do an "if" with the click you are interested in. You don't have to "filter" if what you really want to control is a specific click.

if (id == CHARTEVENT_CLICK)
{  //print something }
 
Miguel Angel Vico Alba #:
if (id == CHARTEVENT_CLICK) {  //print something } else if (id == CHARTEVENT_OBJECT_CLICK) {  //print something }

Hi, The problem is when clicking on any object it detects both clicks, I only want to detect one type of click

if (id == CHARTEVENT_CLICK) {
      Print("Its a chart Click");
   } else if (id == CHARTEVENT_OBJECT_CLICK) {
      //print something }
      Print("Its a chart Object Click");
   }
 

Each event is called separately (and in some cases, probably not this one, with no specific order). If you want only one to be called you would need to filter click events by checking manually if it hovers any object and exiting the function if that is the case, or remove/ignore the object click events and handle both cases in the click event (with the same hover check)


That would be easier with squared objects, if you are using lines then I have no experience in those things. Maybe you can try to put a transparent canvas that covers the whole screen in the background and handle its clicks as chart clicks... (I don't know if that would work, I haven't tried it!)

 

Limit clicks per pixel or per object, otherwise a click on an object is necessarily also a click on the chart.


Event of a mouse click on the chart

CHARTEVENT_CLICK

the X coordinate

the Y coordinate

Event of a mouse click in a graphical object belonging to the chart

CHARTEVENT_OBJECT_CLICK

the X coordinate

the Y coordinate

Name of the graphical object, on which the event occurred


https://www.mql5.com/en/docs/constants/chartconstants/enum_chartevents

 

Have you just tried printing every parameter of the OnChartEvent function?

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   PrintFormat("id: %s, lparam: %s, dparam, %s, sparam: %s", 
               EnumToString(ENUM_CHART_EVENT(id)), string(lparam), string(dparam), sparam);
  }
 
Rodger Sen:

I want to filter normal clicks on chart with clicks on objects

I am using this code but its not working

How can I filter in these two types of clicks?

//---
   if(id!=CHARTEVENT_MOUSE_MOVE)
      PrintFormat("id: %s, lparam: %s, dparam, %s, sparam: %s",
                  EnumToString(ENUM_CHART_EVENT(id)), string(lparam), string(dparam), sparam);
//---
   static const ulong DELAY_TRIGGER = 1000;
   static ulong lastObjectClick     = 0;

   if(id==CHARTEVENT_OBJECT_CLICK)
      lastObjectClick = GetMicrosecondCount();

   if(id==CHARTEVENT_CLICK)
     {
      if(GetMicrosecondCount()-lastObjectClick>DELAY_TRIGGER)
         printf("Chart click ONLY");
      else
         printf("Chart click with object");
     }


 
Alain Verleyen #:
//---    if(id!=CHARTEVENT_MOUSE_MOVE)       PrintFormat("id: %s, lparam: %s, dparam, %s, sparam: %s",                   EnumToString(ENUM_CHART_EVENT(id)), string(lparam), string(dparam), sparam); //---    static const ulong DELAY_TRIGGER = 1000;    static ulong lastObjectClick     = 0;    if(id==CHARTEVENT_OBJECT_CLICK)       lastObjectClick = GetMicrosecondCount();    if(id==CHARTEVENT_CLICK)      {       if(GetMicrosecondCount()-lastObjectClick>DELAY_TRIGGER)          printf("Chart click ONLY");       else          printf("Chart click with object");      }

wow, thank you, thats amazing and working!

 
Topic has been moved to the section: Expert Advisors and Automated Trading
Reason: