Price issue (bug?): unexpected number of decimals (too many!)

Back to topics list To post a new topic, please log in or register
avatar
2
BI43442 2016.05.04 11:30
 

I have an issue when using several candle prices.If I use:

 Print(Close[33]);

to print the value of a given candle, I get:  2016.05.04 11:17:55.733 Indicator - CADCHF,M15: 0.7507200000000001

This happens occasionally with some candles, not all.  

I've tried to limit the number of decimals, but still get the same:

Print(NormalizeDouble(Close[34],Digits)+" "+MarketInfo(Symbol(), MODE_DIGITS));

and get  2016.05.04 11:17:55.736 Indicator - CADCHF,M15: 0.7507200000000001 5

I've also check the History Center to see if the price data base was corrupt, but it shows 0.75072

I've also restarted MT4, but get the same result. 

I've checked around in the internet and have not bee able to find anything related to this issue. 

Does anybody have any idea why this may be happening? 

avatar
2017
gooly 2016.05.04 11:56 #
 
Because of this: https://en.wikipedia.org/wiki/Double-precision_floating-point_format
avatar
Moderator
3206
angevoyageur 2016.05.04 13:29 #
 

Please read the documentation carefully : Print()

Data of double type are shown with the accuracy of up to  16 digits after a decimal point, and can be output either in traditional or in scientific format, depending on what entry will be more compact. Data of float type are output with 5 digits after a decimal point. To output real numbers with another accuracy or in a predefined format, use the PrintFormat() function.

See also these topics Can price != price ?, what is a double ?

avatar
12985
WHRoeder 2016.05.04 14:29 #
 
Floating point has infinite number of decimals, it's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.) Double-precision floating-point format - Wikipedia, the free encyclopedia
double t = 10/81.; 
Print(DoubleToString(t,15)); // tests USDCHF,H1: 0.123456790123457 
See also The == operand. - MQL4 forum
Back to topics list  

To add comments, please log in or register