ChartTimePriceToXY() and ChartXYToTimePrice() does not produce the same result

 

Hi friends,


 come across these function in MQl4.

ChartTimePriceToXY()  
  and  
ChartXYToTimePrice()

While I was doing one of my coding exercises, I tried to convert a price say 1.0850 to X and Y coordinates and convert the resultant X and Y coordinates back to the price, expecting to get back the same price. However, the price actually differ by a little bit.

Can anyone pls help me with this ?


Thks v much


   int xCoordEntrytest,yCoordEntrytest,temp1;
   datetime timetest;
   double pricetest;

   ChartTimePriceToXY(0,0,TimeCurrent(),1.0850,xCoordEntrytest,yCoordEntrytest);

   
   Print("Ynew= "+yCoordEntrytest);   
   Print("price used= 1.0850"); 
   
   

   ChartXYToTimePrice (0, xCoordEntrytest, yCoordEntrytest, temp1, timetest, pricetest);
   Print("priceoutput: "+pricetest);


 

It's perfectly normal. Most of the time 1 pixel at X,Y will match with a range of prices, because there is not enough pixels on your screen for each price (point or even pips precision).

2020.05.12 23:33:00.079    340429 EURGBP,H1: Chart height in pixels = 645, prices from min 0.86520 to max 0.94230, 7710 points

On this example, there is not even enough pixels for each pip, similarly to your example.
 

@Alain Verleyen


hello Alain, do you think you could also help me to understand the following problem?

 this is my code and it produces negative number in my pixels reference variable..


  int timeXY;
  int priceXY;

  ChartTimePriceToXY(chart_ID,0,D'2019.02.26 12:30:00',1.14582, timeXY, priceXY);

 If debugging this code i get a negative -198 value in my priceXY variable... Can you please help explaining?

Reason: