ChartTimePriceToXY() vs. Pixels

 

I have found the function ChartTimePriceToXY() to be quite useful but exploring in more detail there may be some discrepancies.

Pick a candle using Time[] then use the code below to show the position of the candle as a percentage down the chart calculated using Time/Price & Pixels.

I would have thought the factor's should have been the same - see printout.

Is my code wrong or is it the inaccuracy of the platform?

(please can someone tell me how to exit the code window when I have entered code to continue below - it's driving me crazy!)


int start()
{      
 int x,y;
 ChartTimePriceToXY(0,0,Time[33],iClose(NULL,0,33),x,y);
 //calculate how far down the chart candle 33 is using time/price
 double diff_price = (WindowPriceMax() - WindowPriceMin())/(WindowPriceMax()-iClose(NULL,0,33));
 Print(1/diff_price);

 //calculate how far down the chart candle 33 is using pixels
 double y1 = y;
 double factor = NormalizeDouble(y1/ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0),4);
 PrintFormat(factor);
}
 

Depending on timeframe, the accuracy will be different.

I would think that on most timeframes there are less pixels than there are points range. So many different values may be accommodated by a single pixel on the y axis. 

This would cause the difference in your 2 calculations

As a % the difference is very small. 

 

(please can someone tell me how to exit the code window when I have entered code to continue below - it's driving me crazy!) 

What code window? You mean the editor? - just close it.
 
GumRai:

Depending on timeframe, the accuracy will be different.

I would think that on most timeframes there are less pixels than there are points range. So many different values may be accommodated by a single pixel on the y axis. 

This would cause the difference in your 2 calculations

As a % the difference is very small. 

 

What code window? You mean the editor? - just close it.

Thanks for the reply but not quite sure what you mean by this. The difference in values can be relatively large depending on what further calcs are being done. I still think the values should be closer as it's a fairly basic comparison.

Anyway, the code window is where code is entered - SRC button as seen above in my first post. If I enter the code and click outside of that box (below it) nothing happens!!It I press ESC nothing happens - if I press 'RETURN' another SRC box appears!

Has it got something to do with the browser IE11?

Reason: