Download MetaTrader 5
To add comments, please log in or register
How to choose the most appropriate signal and subscribe to it in no time
moonsboy
889
moonsboy 2014.12.29 08:32 

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. 

Halley
198
Halley 2014.12.29 11:13  

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.

whroeder1
13627
whroeder1 2014.12.29 16:20  
jollydragon: Is it still necessary to use NormalizeDouble() for 'stoploss' and 'takeprofit'?
  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  2. 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
  3. 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
  4. 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.
whroeder1
13627
whroeder1 2014.12.29 16:25  
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.
  1. Doubles (Double-precision floating-point format - Wikipedia, the free encyclopedia) are by definition not decimal (Binary-coded decimal - Wikipedia, the free encyclopedia).
  2. They are not invalid. The problem is comparing without understanding The == operand. - MQL4 forum
Halley
198
Halley 2014.12.29 23:51  
WHRoeder:
  1. Doubles (Double-precision floating-point format - Wikipedia, the free encyclopedia) are by definition not decimal (Binary-coded decimal - Wikipedia, the free encyclopedia).
  2. They are not invalid. The problem is comparing without understanding The == operand. - MQL4 forum

 

Please ignore my inputs. Thank you.

moonsboy
889
moonsboy 2014.12.31 07:25  
WHRoeder:
  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  2. 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
  3. 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
  4. 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! 

/
To add comments, please log in or register