Download MetaTrader 5

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

To add comments, please log in or register
Ignacio Oguiza
Ignacio Oguiza  

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


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? 

Carl Schreiber
Carl Schreiber  
Because of this:
Alain Verleyen
Alain Verleyen  

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 ?

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
To add comments, please log in or register