Download MetaTrader 5

Detect object under mouse

To add comments, please log in or register
RichPiano
160
RichPiano  

Hi again


Is there a way to get the object(s) below the mouse cursor (or at a certain position x/y) ? I can't seem to find a function... :/


Thanks! :)

honest_knave
Moderator
2334
honest_knave  

You need to do it manually.

Figure out where the mouse is (pick it up from either CHARTEVENT_CLICK or CHARTEVENT_OBJECT_CLICK or CHARTEVENT_MOUSE_MOVE)

Figure out where the object is (ObjectGetInteger).

See if the mouse x/y is within the object's area.

RichPiano
160
RichPiano  
honest_knave:

You need to do it manually.

Figure out where the mouse is (pick it up from either CHARTEVENT_CLICK or CHARTEVENT_OBJECT_CLICK or CHARTEVENT_MOUSE_MOVE)

Figure out where the object is (ObjectGetInteger).

See if the mouse x/y is within the object's area.


Ok thanks. But what if it's a line? o_O
honest_knave
Moderator
2334
honest_knave  
RichPiano:

Ok thanks. But what if it's a line? o_O

Do you want to know if it has been clicked, or just hovering over the line?
RichPiano
160
RichPiano  
honest_knave:

Do you want to know if it has been clicked, or just hovering over the line?

If it has been clicked :X
honest_knave
Moderator
2334
honest_knave  
RichPiano:

If it has been clicked :X

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK && sparam==line_name) // line has been clicked
     {
     
     }
  } 
RichPiano
160
RichPiano  
honest_knave:


thank you, but the problem here is that the event is only triggered when the mouse button is released again. but i need it to register when the mouse button is only pressed but not released :/
Alain Verleyen
Moderator
32393
Alain Verleyen  
RichPiano:

thank you, but the problem here is that the event is only triggered when the mouse button is released again. but i need it to register when the mouse button is only pressed but not released :/
Then it's not a click.
honest_knave
Moderator
2334
honest_knave  
Yep, so you'll need to use CHARTEVENT_MOUSE_MOVE, check the mouse location relative to your line, and check sparam for the mouse button status.
RichPiano
160
RichPiano  
honest_knave:
Yep, so you'll need to use CHARTEVENT_MOUSE_MOVE, check the mouse location relative to your line, and check sparam for the mouse button status.

Ok thanks! I guess I'll just use CHARTEVENT_MOUSE_CLICK then as this obviously isn't foreseen in mql4 and such stuff makes me very anxious about bugs. It's also just something cosmetic ;)
To add comments, please log in or register