- Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
Hi Whroeder1,
I saw this comment you type in another post, and i tried it already but didn't work, regardless look at the function again, i Do NOT use NormalizeDouble, clearly i am looking for an alternative in this MQL"5" not 4
anyway, thanks for passing by
Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
You really should stop spreading misinformation around here. What's wrong is your use of MathRound instead of NormalizeDouble in your rounding function since NormalizeDouble properly implements logic to prevent drift and MathRound does not (as pointed out by amrali in this thread).
Correct method:
double price = 1.2345678; price = step * NormalizeDouble(price / step,0);
OP, you can use the CDouble lib make your life easy. :)
You really should stop spreading misinformation around here. What's wrong is your use of MathRound instead of NormalizeDouble in your rounding function since NormalizeDouble properly implements logic to prevent drift and MathRound does not (as pointed out by amrali in this thread).
Correct method:
OP, you can use the CDouble lib make your life easy. :)
Hi Nicholishen,
I have tried the recommended function, but didn't work at all, even failed to pass any of the tests as below
double RNormalizeDouble(double num, double precision){ double c = 0.5 * DBL_EPSILON * num; // double p = MathPow(10, precision); //slow double p = 1; while (precision--> 0) p *= 10; if (num < 0) p *= -1; return MathRound((num + c) * p) / p; }
2018.03.25 10:24:03.126 Core 1 2017.01.02 08:37:40 A -0.8100000000000001
2018.03.25 10:24:03.126 Core 1 2017.01.02 08:37:40 B -0.8100000000000001
2018.03.25 10:24:03.126 Core 1 2017.01.02 08:37:40 A -0.82
2018.03.25 10:24:03.126 Core 1 2017.01.02 08:37:40 B -0.82
2018.03.25 10:24:03.126 Core 1 2017.01.02 08:37:40 A -0.6899999999999999
2018.03.25 10:24:03.126 Core 1 2017.01.02 08:37:40 B -0.6899999999999999
Your topic is "double to string", what's wrong with DoubleToString() function ?
You should read and learn what is a double in mql.

- en.wikipedia.org
Your topic is "double to string", what's wrong with DoubleToString() function ?
You should read and learn what is a double in mql.
Hi Alain,
I wrote the title this way as i convert it to String First, thanks for the note but i know what double and float are
anyway, my problem is actually with the precision of double as stated earlier
Your topic is "double to string", what's wrong with DoubleToString() function ?
You should read and learn what is a double in mql.
Dear Alain,
Could you advise if such values could affect the calculations ?
they might seem like infinitesimal yet it occurred to me that some trades fail because of wrong values like this due to unexpected precision, is that thought correct ?
Dear Alain,
Could you advise if such values could affect the calculations ?
they might seem like infinitesimal yet it occurred to me that some trades fail because of wrong values like this due to unexpected precision, is that thought correct ?
Forum on trading, automated trading systems and testing trading strategies
quantumninja, 2018.03.25 19:12
Hi Alain,
I wrote the title this way as i convert it to String First, thanks for the note but i know what double and float are
anyway, my problem is actually with the precision of double as stated earlier
Your question and all this topic shows that you don't understand what a double is. Some values can't be represented exactly as double, for example 0.1 can't.
There is no "wrong" values. nicholishen shows you the code to normalize a price.
Your question and all this topic shows that you don't understand what a double is. Some values can't be represented exactly as double, for example 0.1 can't.
There is no "wrong" values. nicholishen shows you the code to normalize a price.
Okay

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
i am trying to convert double to string in MQL5, the NormalizeDouble is such a failure as it get numbers such as 0.07000000000000001 and 0.9399999999999999
i have created the below function, but it can only filter our cases as 0.9399999999999999, but fails with 0.07000000000000001
Sample of the output
PN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.9399999999999999
LM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .93
FE 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.93
II 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.9399999999999999
JP 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .93
EN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.93
MN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.9399999999999999
RE 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .93
PD 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.93
EM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.79
QL 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .79
LG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.79
PG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.63
JO 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .63
JP 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.63
NF 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.64
RG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .64
EG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.64
DO 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.34
EO 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .34
DD 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.34
DD 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.35
RM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .35
GM 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.35
KR 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.06
HJ 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .06
NJ 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.06
FL 0 00:52:30.450 Core 1 2017.01.02 06:24:41 A -0.07000000000000001
QN 0 00:52:30.450 Core 1 2017.01.02 06:24:41 Debug .07
EG 0 00:52:30.450 Core 1 2017.01.02 06:24:41 B -0.07000000000000001