It is not necessary in general, but it is necessary after you perform any operation on the double precision number (even a simple sum of two "valid" numbers may lead to an "invalid" number).
And why? It is because the MQL implementation does not bother with adjusting (or tolerating) the double that is not exactly decimal.
jollydragon: Is it still necessary to use NormalizeDouble() for 'stoploss' and 'takeprofit'?
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP are market orders when triggered, they don't need to be normalized, only abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Only the 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 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power to 1/10 then NormalizeDouble is wrong. Do it right.
DeepThought: It is not necessary in general, but it is necessary after you perform any operation on the double precision number (even a simple sum of two "valid" numbers may lead to an "invalid" number). And why? It is because the MQL implementation does not bother with adjusting (or tolerating) the double that is not exactly decimal.
- Doubles (Double-precision floating-point format - Wikipedia, the free encyclopedia) are by definition not decimal (Binary-coded decimal - Wikipedia, the free encyclopedia).
- They are not invalid. The problem is comparing without understanding The == operand. - MQL4 forum
WHRoeder:
- Doubles (Double-precision floating-point format - Wikipedia, the free encyclopedia) are by definition not decimal (Binary-coded decimal - Wikipedia, the free encyclopedia).
- They are not invalid. The problem is comparing without understanding The == operand. - MQL4 forum
Please ignore my inputs. Thank you.
WHRoeder:
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP are market orders when triggered, they don't need to be normalized, only abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Only the 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 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power to 1/10 then NormalizeDouble is wrong. Do it right.
Dear WHRoeder, Thanks a lot for your clarification and help!
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
You know 'stoploss' and 'takeprofit' are "double" types in OrderModify().
Is it still necessary to use NormalizeDouble() for 'stoploss' and 'takeprofit'?
e.g. I saw some EAs use NormalizeDouble(histroyPrice, Digits) to set the 'stoploss' or 'takeprofit' by OrderModify().
However, you know the histroyPrice is a double type as accuracy as the Digits number of decimal digits already.
Is it still necessary to NormalizeDouble(histroyPrice, Digits) now? Why? Thanks.