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
NormalizeDouble, It's use is usually wrong,
Double-precision floating-point format - Wikipedia, the free encyclopedia
See also The == operand. - MQL4 programming forum
MT4:NormalizeDouble - General - MQL5 programming forum
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
Code breaks if lot step is not a power of 10.
When I suggested the -log10() function I was giving a solution referring to his very limited "switch" list, that also only allowed for the values 0.01, 0.1 and 1. For these cases the function works. If you include other values, e.g.
-log10(0.02)=1.698
-log10(0.3)=0.523
-log10(0.4)=0.398
rounding UP (not MathRound) is the correct way to obtain the number of digits, as can be seen with the example -log10(0.4), because the result is below 0.5, so MathRound should return 0, whereas the number of digits after the decimal point for 0.4 is 1
so I guess
ceil(-log10(step)) should be correct, not round(-log10(step));
or am I getting this wrong?
What is wrong is doing it at all. "If that is not a power of 1/10," then Lotdecimal_0_1_2 is meaningless.
Forget about switch. Use if.
No need to make it complicated.
Forget about switch. Use if.
No need to make it complicated.
Yes, my opinion too: keep it simple.
But suppose you have other steps (like 0.25 or 0.5) then I have an unconventional (but working) solution, which I use for long time: the function GetNoDigits.
Please see -
Output
Enjoy your life
Matthias
------------------------------------------------------
"Is it more important to feel strong than to be strong."
Yes, my opinion too: keep it simple.
But suppose you have other steps (like 0.25 or 0.5) then I have an unconventional (but working) solution, which I use for long time: the function GetNoDigits.
Please see -
Output
Enjoy your life
Matthias
------------------------------------------------------
"Is it more important to feel strong than to be strong."
Now, you have the number of digits,
great!
so what then?
It seems to be a correct answer, but for a different question.
Stop using NormalizeDouble, It's use is usually wrong, as it is in your case.
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
See also The == operand. - MQL4 programming forum 2013.06.07
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 metals. (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - 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 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 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - 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.
MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
MT4:NormalizeDouble - MQL5 programming forum
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
What is a TICK? - MQL4 programming forum 2014.08.03
Prices you get from the terminal are already normalized.
Of course, they are. Reread my post, especially № 1 and № 2.