Download MetaTrader 5

Mouse Hover function

To add comments, please log in or register
Having troubles understanding the code? Articles can help you!
Michalis Phylactou
10414
Michalis Phylactou 2016.11.17 16:19 

Hello

I wish to write an that will read how many candles back from the last one the candles where the mouse is and repeat a given code that uses the time ,every time the mouse moves.

Can someone provide me an example?


Thank you

Alain Verleyen
Moderator
30707
Alain Verleyen 2016.11.17 19:13  
Michalis Phylactou:

Hello

I wish to write an that will read how many candles back from the last one the candles where the mouse is and repeat a given code that uses the time ,every time the mouse moves.

Can someone provide me an example?


Thank you

See CHARTEVENT_MOUSE_MOVE
Michalis Phylactou
10414
Michalis Phylactou 2016.12.18 21:57  
Alain Verleyen:
See CHARTEVENT_MOUSE_MOVE

Thank you for your response.

Are you able to provide an example as I am unable to follow the instunctions shown in the help manual regarding this feature and OnChartEvent.

Thank you

Michalis Phylactou
10414
Michalis Phylactou 2016.12.19 12:40  
Michalis Phylactou:

Thank you for your response.

Are you able to provide an example as I am unable to follow the instunctions shown in the help manual regarding this feature and OnChartEvent.

Thank you

For example if someone can give me sample code that gives an alert with the Open Price of the candle where the mouse cursor is,whenever the mouse moves.

Thank you
honest_knave
Moderator
2159
honest_knave 2016.12.19 13:06  

You will get a lot of alerts. Think how many pixels there are on your screen. You want an alert every time the mouse moves a pixel.

I've modified your request slightly to show the open price in the Comment, and only on a different bar.

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   static int iLast=-1; // the index of the last bar the mouse was on
   if(id==CHARTEVENT_MOUSE_MOVE) // if the mouse moves
     {
      int x=(int)lparam,   // store the x coordinate
          y=(int)dparam;   // store the y coordinate
      datetime when;      
      double price;
      int subwin=0;
      ChartXYToTimePrice(0,x,y,subwin,when,price); // convert x/y to time/price
      int i=iBarShift(NULL,0,when); // find out which bar the mouse is on
      if(i!=iLast) Comment(Open[i]);  // if it is a different bar, alert with the open price
      iLast=i;                      // remember the bar index for next time
     }
  }


 

Michalis Phylactou
10414
Michalis Phylactou 2016.12.21 15:19  
honest_knave:

You will get a lot of alerts. Think how many pixels there are on your screen. You want an alert every time the mouse moves a pixel.

I've modified your request slightly to show the open price in the Comment, and only on a different bar.

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
   static int iLast=-1; // the index of the last bar the mouse was on
   if(id==CHARTEVENT_MOUSE_MOVE) // if the mouse moves
     {
      int x=(int)lparam,   // store the x coordinate
          y=(int)dparam;   // store the y coordinate
      datetime when;      
      double price;
      int subwin=0;
      ChartXYToTimePrice(0,x,y,subwin,when,price); // convert x/y to time/price
      int i=iBarShift(NULL,0,when); // find out which bar the mouse is on
      if(i!=iLast) Comment(Open[i]);  // if it is a different bar, alert with the open price
      iLast=i;                      // remember the bar index for next time
     }
  }


 

Thanks  a lot
To add comments, please log in or register