CHARTEVENT_OBJECT_CLICK

 
I would really appreciate some help, I have coded a lot in the old mt4, now coding in the new and it's been going ok, but having a problem with CHARTEVENT_OBJECT_CLICK, I am running in OnTimer() and it appears that I can't run CHARTEVENT_OBJECT_CLICK in OnTimer(), every way I try gives me errors, I am trying to execute a line of code when I click on an object, I can do it the old method by checking the position of the object and when it changes execute the code, but this seems to be the new way, but I am getting errors, even when I copy existing code and just past it in. Thanks in advance.     
 
Robert Lotter:
I would really appreciate some help, I have coded a lot in the old mt4, now coding in the new and it's been going ok, but having a problem with CHARTEVENT_OBJECT_CLICK, I am running in OnTimer() and it appears that I can't run CHARTEVENT_OBJECT_CLICK in OnTimer(), every way I try gives me errors, I am trying to execute a line of code when I click on an object, I can do it the old method by checking the position of the object and when it changes execute the code, but this seems to be the new way, but I am getting errors, even when I copy existing code and just past it in. Thanks in advance.     

You dont run it in on timer you run it as a separate function just like in mql4.

Please see:

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

//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,         // Event identifier  
                  const long& lparam,   // Event parameter of long type
                  const double& dparam, // Event parameter of double type
                  const string& sparam  // Event parameter of string type
                  )
  {
//--- the left mouse button has been pressed on the chart
   if(id==CHARTEVENT_CLICK)
     {
      Print("The coordinates of the mouse click on the chart are: x = ",lparam,"  y = ",dparam);

     }

//--- the mouse has been clicked on the graphic object
   if(id==CHARTEVENT_OBJECT_CLICK)
     {
      Print("The mouse has been clicked on the object with name '"+sparam+"'");
     }

  }
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Types of Chart Events - Reference on algorithmic/automated trading language for MetaTrader 5
 
Thank you fantastic it's working I should have been performing task outside the timer
Reason: