You used NormalizeDouble, It's use is usually wrong, as it is in your case.
-
Floating point has an infinite number of decimals, it's you were not understanding floating point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia, the free encyclopediaSee also The == operand. - MQL4 programming forum (2013)
-
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) — code fails on non-currencies.
On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum #10 (2011)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 programming forum (2012)
-
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 non-currencies. So do it right.
Trailing Bar Entry EA - MQL4 programming forum (2013)
Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum (2012) -
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.
(MT4 2013)) (MT5 2022)) -
MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
MT4:NormalizeDouble - MQL5 programming forum (2017)
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum (2017) -
Prices you get from the terminal are already correct (normalized).
-
PIP, Point, or Tick are all different in general.
What is a TICK? - MQL4 programming forum (2014)
Sorry but i have also again a problem when i try to call i open (you tell is just normalized a decimal, therefore i not normalize double ) but return some data wrong not normalized
DEMA DE MA DEEEE -----> 23.07 DEMA DE MA DEEEE -----> 88.98999999999999 NZDJPY DEMA DE MA DEEEE -----> 7226.6 DEMA DE MA DEEEE -----> 15777.2 DEMA DE MA DEEEE -----> 15777.2 DEMA DE MA DEEEE -----> 1.07086 DEMA DE MA DEEEE -----> 0.85712 DEMA DE MA DEEEE -----> 1.6745 DEMA DE MA DEEEE -----> 1.07086 DEMA DE MA DEEEE -----> 1.95359 DEMA DE MA DEEEE -----> 94.25700000000001 AUDJPY DEMA DE MA DEEEE -----> 86.98 DEMA DE MA DEEEE -----> 94.25700000000001 AUDJPY DEMA DE MA DEEEE -----> 0.63949
It seems you have totally ignored William's first point. Here is some more information ...
Forum on trading, automated trading systems and testing trading strategies
MathRound fails for one particular number
Fernando Carreiro, 2018.01.01 22:08
He means that the value "0.69" cannot be exactly represented given the way a floating point number works (based on binary and not decimal representation) - hence, why the value gets represented as "0.68999999..." (see below).
You can never really "normalize" it and it is the main reason why both @whroeder1 and myself contest the use of the NormalizeDouble() function. It should in the very least be renamed to something like "RoundDigits()" because it is more of a "rounding" function and does not "normalize" in any way or fashion.
https://www.h-schmidt.net/FloatConverter/IEEE754.html
EDIT: Please note that the above images are for examples of representation in the 4-byte "float", and not the 8-byte "double" which offers more precision but still cannot represent the value "0.69" exactly due to the "binary" nature of the format.
EDIT2: For future readers that have difficulty understanding (or accepting) this concept, of decimal values not having an exact representation with a "float" or a "double", here is an article worth reading:
Why 0.1 Does Not Exist In Floating-Point
Many new programmers become aware of binary floating-point after seeing their programs give odd results: “Why does my program print 0.10000000000000001 when I enter 0.1?”; “Why does 0.3 + 0.6 = 0.89999999999999991?”; “Why does 6 * 0.1 not equal 0.6?” Questions like these are asked every day, on online forums like stackoverflow.com.
The answer is that most decimals have infinite representations in binary. Take 0.1 for example. It’s one of the simplest decimals you can think of, and yet it looks so complicated in binary:
Decimal 0.1 In Binary ( To 1369 Places
The bits go on forever; no matter how many of those bits you store in a computer, you will never end up with the binary equivalent of decimal 0.1.
... Read the rest of the article at: http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/
It is not an exclusive MQL problem. It is the same for ALL programming languages that use floating point.
You can see that by the links I provided and I quote from one of them ...
"The questions came from the context of a variety languages: Java, C++, C#, Python, Javascript, awk, Perl, Objective-C, and PHP. "
- Rick Regan
- www.exploringbinary.com
When you print or compare to.other double, you can safely expect to get correct result.
When you print or compare to.other double, you can safely expect to get correct result. Good luck or should I say, be careful with MQL ;)
That is not correct! In C or C++, rounding does not guarantee the exact number of digits. Floating point, has binary representation, not decimal representation.
Printed output, can be different to what is actually stored internally, especially if a set precision is defined for the output. So please, do not confuse the two.
Please read my post above and the links and proof provided.
That is not correct! In C or C++, rounding does not guarantee the exact number of digits. Floating point, has binary representation, not decimal representation.
Printed output, can be different to what is actually stored internally, especially if a set precision is defined for the output. So please, do not confuse the two.
Please read my post above and the links and proof provided.
OK, thanks for clarification.
Nevertheless, please be careful when using __ double __.
Always verify (double check) if the logic / math of your code as expected.
but the problem is not in mathematical way can normalize it , i know is in binary is impossible but when i transform it in string i want truncate a string and i want a string with 7 digit , for insert in editbox , you tell me is impossible do also this ?
Use DoubleToStr() or StringFormat() and you'll be fine.
- 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, I create this simple script i notice in some cross return many decimal and if i normalize double not normalize nothing how is possible?? i do some error ??
return 2023.09.09 11:11:35.465 da_cancellare AUDCAD,H1: FirstPriceVCFirstPriceVCFirstPriceVCFirstPriceVCFirstPriceVC---> 86.52200000000001
my code