Download MetaTrader 5
To add comments, please log in or register
They are already making profit using the Market. You can join them!
BigFisherman
125
BigFisherman 2014.02.13 17:08 

Hi guys, I'm testing out on this new chart operation ChartXYToTimePrice() on a custom indicator for the new Mql4. But the price converted from CHARTEVENT_CLICK (x, y coordinates) behaves weirdly. Price converted from screen XY coordinates (obtained from mouse click event) is incorrect & appears to be upside down (chart top lower price ---> chart bottom higher price). Here's my simple test code:

//+------------------------------------------------------------------+
//|                                                    TestClick.mq4 |
//|                                     Copyright 2014, BigFisherman |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, BigFisherman"
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_maximum 10
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
//---
   datetime ClickTime = 0;
   double ClickPrice = 0.0;
   int Window = 0;
   int X = (int)lparam;
   int Y = (int)dparam;

   if (id==CHARTEVENT_CLICK){
      bool ConvertXY_Result = ChartXYToTimePrice(0,X,Y,Window,ClickTime,ClickPrice);
      Print("X: "+X+" Y: "+Y+" Window: "+Window+" ClickTime: "+ClickTime+" ClickPrice: "+ClickPrice);
   }   
}
//+------------------------------------------------------------------+

And here's the log generated from some random mouse click (Note "Y" coordinates & "ClickPrice". Smaller Y (Higher chart position) --> Lower ClickPrice ):

2014.02.13 18:47:47.775 TestClick AUDJPY,Daily: X: 367 Y: 21 Window: 0 ClickTime: 1384992000 ClickPrice: 80.43123393
2014.02.13 18:47:44.535 TestClick AUDJPY,Daily: X: 227 Y: 31 Window: 0 ClickTime: 1383004800 ClickPrice: 80.63714653
2014.02.13 18:47:43.335 TestClick AUDJPY,Daily: X: 224 Y: 142 Window: 0 ClickTime: 1383004800 ClickPrice: 82.92277635
2014.02.13 18:47:42.431 TestClick AUDJPY,Daily: X: 227 Y: 247 Window: 0 ClickTime: 1383004800 ClickPrice: 85.08485861
2014.02.13 18:47:41.463 TestClick AUDJPY,Daily: X: 232 Y: 311 Window: 0 ClickTime: 1383091200 ClickPrice: 86.40269923

Any idea what's wrong with my codes or it's some bug? I've read through the help files & forums but found no solutions yet.

Thanks in advance!

Ubzen
Moderator
5394
Ubzen 2014.02.13 18:05  
BigFisherman:

Hi guys, I'm testing out on this new chart operation ChartXYToTimePrice() on a custom indicator for the new Mql4. But the price converted from CHARTEVENT_CLICK (x, y coordinates) behaves weirdly. Price converted from screen XY coordinates (obtained from mouse click event) is incorrect & appears to be upside down (chart top lower price ---> chart bottom higher price). Here's my simple test code:

And here's the log generated from some random mouse click (Note "Y" coordinates & "ClickPrice". Smaller Y (Higher chart position) --> Lower ClickPrice ):

2014.02.13 18:47:47.775 TestClick AUDJPY,Daily: X: 367 Y: 21 Window: 0 ClickTime: 1384992000 ClickPrice: 80.43123393
2014.02.13 18:47:44.535 TestClick AUDJPY,Daily: X: 227 Y: 31 Window: 0 ClickTime: 1383004800 ClickPrice: 80.63714653
2014.02.13 18:47:43.335 TestClick AUDJPY,Daily: X: 224 Y: 142 Window: 0 ClickTime: 1383004800 ClickPrice: 82.92277635
2014.02.13 18:47:42.431 TestClick AUDJPY,Daily: X: 227 Y: 247 Window: 0 ClickTime: 1383004800 ClickPrice: 85.08485861
2014.02.13 18:47:41.463 TestClick AUDJPY,Daily: X: 232 Y: 311 Window: 0 ClickTime: 1383091200 ClickPrice: 86.40269923

Any idea what's wrong with my codes or it's some bug? I've read through the help files & forums but found no solutions yet.

Thanks in advance!

Please submit your findings to the service desk.
Keith Watford
Moderator
8016
Keith Watford 2014.02.13 22:46  

When placing an object such as a label on the chart, the default anchor corner is 0 (top left)

From your results, it appears that the default corner is 2 (bottom left) for CHARTEVENT_CLICK.

Actually this makes sense as when reading a chart normally, you would expect the x co-ordinate to increase as it moves to the right and the y co-ordinate to increase as it moves from the bottom to the top.

BigFisherman
125
BigFisherman 2014.02.14 02:01  
ubzen:
Please submit your findings to the service desk.


Submitted #955612
BigFisherman
125
BigFisherman 2014.02.14 02:11  
GumRai:

When placing an object such as a label on the chart, the default anchor corner is 0 (top left)

From your results, it appears that the default corner is 2 (bottom left) for CHARTEVENT_CLICK.

Actually this makes sense as when reading a chart normally, you would expect the x co-ordinate to increase as it moves to the right and the y co-ordinate to increase as it moves from the bottom to the top.


Yeap, it make more sense for Y=0 to be at chart bottom than current top, but I'm actually fine if it works. Lets see if they get this fix soon.

Slawa
Moderator
6682
Slawa 2014.02.14 09:43  
BigFisherman:

Submitted #955612
Fixed
/
To add comments, please log in or register