//--- write a file of equity if strategy active (total>1) double oilpricestart=43.539; double capitalstart=234.47; double capital=NormalizeDouble(AccountEquity(),2); double capital_percent=capitalstart/100; double performance=(capital-capitalstart)/capital_percent; double perfNormalized=NormalizeDouble(performance,2); double oilpricepercent=oilpricestart/100; double oilperformance=(oilpricestart-Ask)/oilpricepercent; double oilperfNormalized=NormalizeDouble(oilperformance,2); if(TimeCurrent()>TimesignalA) if(OrdersTotal()>0) { //---- add data to the end of file each 900 second interval TimesignalA=TimeCurrent()+900; int handle=FileOpen("timetosuccessSHORT.csv",FILE_CSV|FILE_READ|FILE_WRITE,';'); if(handle>0) { FileWrite(handle,"05-05-16 INITIAL EQYUITY = 234.47€ WTICOUSD 43.539","strategy return % since start","oil performance % since start"); FileSeek(handle,0,SEEK_END); FileWrite(handle,capital,perfNormalized,oilperfNormalized); FileClose(handle); handle=0; } }
Doubles and floats are represented as the closest number of a mantissa and an exponent (https://en.wikipedia.org/wiki/Double-precision_floating-point_format).
So even 0 is not 0 but (e.g.) 0.00000000000000000000001 or 3 not 3 but (e.g.) 2.9999999999999999999999999989.
And even after normalizing a double it is still a double!
- 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
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.
It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 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 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 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 of 1/10 then NormalizeDouble is wrong. Do it right.
Doubles and floats are represented as the closest number of amantissa and an exponent(https://en.wikipedia.org/wiki/Double-precision_floating-point_format).
So even 0 is not 0 but (e.g.) 0.00000000000000000000001 or 3 not 3 but (e.g.) 2.9999999999999999999999999989.
And even after normalizing a double it is still a double!
0 is just 0 of course.
And why did we had some discussions here that the comparison if ( a==0 ) failed?
And why did we had some discussions here that the comparisons failed:
The code you posted can't "failed", it's always true.
Do you have some link(s) ?
The code you posted can't "failed", it's always true.
Do you have some link(s) ?
double a = 0.0; if (a == 0.0 ) {
will work as a and 0.0 do have the same representation of 0.0 - wait a minute..
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i have a problem with normalizedouble in csv file :
226.82;-3.26;-9.890000000000001
226.64;-3.34;-10.13
226.7;-3.31;-10.05
226.79;-3.28;-9.94
226.72;-3.31;-10.03
226.44;-3.42;-10.15
226.78;-3.28;-9.539999999999999
227.45;-2.99;-9.109999999999999
227.29;-3.06;-9.220000000000001
WTF..... why sometime normalizedouble doesn't works????????????????????????????????????
how this is possible?????????????????
here is my code:
thanks for any help