Hi everyone I'm not sure why NormalizeDouble is not working here. Can anyone suggest a fix to this?
***

Hi everyone I'm not sure why NormalizeDouble is not working here. Can anyone suggest a fix to this?
***
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
The documentation is clear when you try to print these numbers:
https://www.mql5.com/en/docs/convert/normalizedouble
"Please note that when output to Journal using the Print() function, a normalized number may contain a greater number of decimal places than you expect"

- www.mql5.com
You used NormalizeDouble, It's use is usually wrong, as it is in your case.
-
Floating point has a 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 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 (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. (2013) -
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)
The code that is inserted correctly:
int OnInit() { Alert(""); Alert("Starting Strategy Mid Line"); double tradeBuyValue[420]; ArrayInitialize(tradeBuyValue,0); for(int i = 0; i<420; i++) { tradeBuyValue[i] = 90 + NormalizeDouble(i*0.1, 2); } } *** Alert(tradeBuyValue[1]); Alert(tradeBuyValue[2]); Alert(tradeBuyValue[3]); Alert(tradeBuyValue[4]); Alert(tradeBuyValue[5]); ***
tradeBuyValue[i] = NormalizeDouble(90 + i*0.1, 2);
Additionally, MQL5 Print() and Alert() may produce strings that may be confusing to some people without deep understanding of how floating-point format works at the binary level.
You would better use this custom toString() function to print floating point numbers with extreme accuracy.
So, your code would be like this:
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { Alert(""); Alert("Starting Strategy Mid Line"); double tradeBuyValue[420]; ArrayInitialize(tradeBuyValue,0); for(int i = 0; i<420; i++) { tradeBuyValue[i] = NormalizeDouble(90 + i*0.1, 2); } for(int i = 0; i<420; i++) { Alert(toString(tradeBuyValue[i])); } } //+------------------------------------------------------------------+ //| Converting numeric value into the shortest string representation | //| that round-trips into the same numeric value. The result may hold| //| up to the first 17 significant digits, discarding trailing zeros.| //| The round-trip ("%.17g") format specifier ensures that a numeric | //| value converted to a string is always parsed back into the same | //| numeric value, StringToDouble(toString(f)) == f. | //+------------------------------------------------------------------+ string toString(double value) { string str = ""; //--- First format with 15 spaces of precision. If round-trip fails, //--- format with 17 spaces of precision. if(value == StringToDouble(str = StringFormat("%.15g", value))) return str; return StringFormat("%.17g", value); }

- www.mql5.com
The following works:
include <stdlib.mqh>
DoubleToStrMorePrecision(Wert,2)

- 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 everyone I'm not sure why NormalizeDouble is not working here. Can anyone suggest a fix to this?
***