Forum on trading, automated trading systems and testing trading strategies
rounding problem
Yango, 2022.04.24 09:46
hello, these 3 lines are set and the prizes are displayed. unfortunately he gives the price of the white line unrounded and i don't know why. I can't get any further with NormalizeDouble..
for the most part he rounds it correctly, but sometimes he still has problems and gives me the price with too many decimal places.. in the backtest
it works
it does not work
double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
double price_red_middle_position = 0;
price_red_middle_position = NormalizeDouble(MathRound(ObjectGetDouble(ChartID(),objects_lines,OBJPROP_PRICE)/tickSize)*tickSize,_Digits);
You can can use these functions for accurate rounding:
double RoundToStepUp(double num, double step); double RoundToStepDown(double num, double step);

- www.mql5.com
Floating-point has an infinite number of decimals, it's you, not understanding floating-point and that some numbers can't be represented exactly. (like 1/10.)
Double-precision floating-point format - Wikipedia
See also The == operand. - MQL4 programming forum (2013)
If you want to see the correct number of digits, convert it to a string with the correct/wanted accuracy.
question about decima of marketinfo() - MQL4 programming forum (2016)

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use