Download MetaTrader 5

How to get Price data and Time data of mouse position by clicking the mouse?

To add comments, please log in or register
Use the Pocket to paste your content. It is convenient!
Yu Zhang
170
Yu Zhang 2016.08.02 06:12 

We can use "CHARTEVENT_CLICK" to get X coordinate value and Y coordinate value of mouse position , But How to get Price data and Time data of mouse position by clicking the mouse?

It we move the mouse , we can see Price data and Time data by using "Crosshair,Ctrl+F" , But How to output the data to the variable ?

Is anyone who knows how to achieve this function?

Thank you. 

Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.08.02 07:00  
Yu Zhang:

We can use "CHARTEVENT_CLICK" to get X coordinate value and Y coordinate value of mouse position , But How to get Price data and Time data of mouse position by clicking the mouse?

It we move the mouse , we can see Price data and Time data by using "Crosshair,Ctrl+F" , But How to output the data to the variable ?

Is anyone who knows how to achieve this function?

Thank you. 

ChartXYToTimePrice

Converts the X and Y coordinates on a chart to the time and price values.

bool  ChartXYToTimePrice( 
   long           chart_id,     // Chart ID 
   int            x,            // The X coordinate on the chart 
   int            y,            // The Y coordinate on the chart 
   int&           sub_window,   // The number of the subwindow 
   datetime&      time,         // Time on the chart 
   double&        price         // Price on the chart 
   );
 
//+------------------------------------------------------------------+ 
//| 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);
      datetime time;
      double price;
      int subwindow;
      ChartXYToTimePrice(0,lparam,dparam,subwindow,time,price);
      Print(" Subwindow: ",IntegerToString(subwindow)," Time: ",TimeToString(time,TIME_SECONDS)," Price: ",DoubleToString(price));
        
     } 
//--- 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+"'"); 
     } 
  }
Yu Zhang
170
Yu Zhang 2016.08.02 11:00  
Marco vd Heijden:
Thank you very much.
To add comments, please log in or register