Get object name of the last clicked object
Yes there is.
Use OnChartEvent()
//+------------------------------------------------------------------+ //| 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+"'"); } //--- the key has been pressed if(id==CHARTEVENT_KEYDOWN) { switch(lparam) { case KEY_NUMLOCK_LEFT: Print("The KEY_NUMLOCK_LEFT has been pressed"); break; case KEY_LEFT: Print("The KEY_LEFT has been pressed"); break; case KEY_NUMLOCK_UP: Print("The KEY_NUMLOCK_UP has been pressed"); break; case KEY_UP: Print("The KEY_UP has been pressed"); break; case KEY_NUMLOCK_RIGHT: Print("The KEY_NUMLOCK_RIGHT has been pressed"); break; case KEY_RIGHT: Print("The KEY_RIGHT has been pressed"); break; case KEY_NUMLOCK_DOWN: Print("The KEY_NUMLOCK_DOWN has been pressed"); break; case KEY_DOWN: Print("The KEY_DOWN has been pressed"); break; case KEY_NUMPAD_5: Print("The KEY_NUMPAD_5 has been pressed"); break; case KEY_NUMLOCK_5: Print("The KEY_NUMLOCK_5 has been pressed"); break; default: Print("Some not listed key has been pressed"); } ChartRedraw(); } //--- the object has been deleted if(id==CHARTEVENT_OBJECT_DELETE) { Print("The object with name ",sparam," has been deleted"); } //--- the object has been created if(id==CHARTEVENT_OBJECT_CREATE) { Print("The object with name ",sparam," has been created"); } //--- the object has been moved or its anchor point coordinates has been changed if(id==CHARTEVENT_OBJECT_DRAG) { Print("The anchor point coordinates of the object with name ",sparam," has been changed"); } //--- the text in the Edit of object has been changed if(id==CHARTEVENT_OBJECT_ENDEDIT) { Print("The text in the Edit field of the object with name ",sparam," has been changed"); } }
Keith Watford:
OnChartEvent() IS the function.
Read the documentation.
i know its a function and i know this function handles the events related to chart and i know how to detect the mouse click on chart or on an object , i have done so previously , where i was using the object name
but in this situation i didnt know how to get the name of the object that is clicked
is there any way to get the name of the object that was clicked most recently ?
i have too many objects on chart and i want to save the name of the last clicked object into a variable , is there any way to accomplish that ?