How can I write a CHARTEVENT_CLICK code to execute something?

 

Hi comrades, I want to write a program to print "Printed Output" after the chat has been clicked. I have the following code which obviously did not work. Please how do I go about it? Thank you in advance.


 

void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam)
   {
   if (sparam == CHARTEVENT_CLICK)
       Print("Printed Output");
   }
 
if (sparam == CHARTEVENT_CLICK)

to

if (id == CHARTEVENT_CLICK)

.but you probably want to use CHARTEVENT_OBJECT_CLICK to only execute when a specific object has been clicked. Otherwise you will get repeated executuion everytime you click on the chart.

 
GumRai:

to

.but you probably want to use CHARTEVENT_OBJECT_CLICK to only execute when a specific object has been clicked. Otherwise you will get repeated executuion everytime you click on the chart.

Thank you so much. Actually I want to click on the chart and not on an object. I want any chat on top of the window to be the one to execute the event. But I have read the MQL4 help document and I can see X-cordinate, and Y-cordinate as the parameters to be passed through, including of course the CHARTEVENT_CLICK.

Also, the id alone does not seem to do anything after clicking on the chart. Do I have to add the coordinates, if yes how do I go about it?


Event of a mouse click on the chart

CHARTEVENT_CLICK

the X coordinate

the Y coordinate

 
Ok thanks, I think I got it.
Reason: