Mouse Hover function

 

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

 
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
 
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:

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
 

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
     }
  }


 

 
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