I am about at my wits end with having to make exceptions for normalized double's that don't make sense. I have had most of my troubles with conditional if statements
There are several occurrences of this problem throughout my expert. Most I have either found a different algorithm to handle the situation or had to fudge a parameter by adding or subtracting a Point to force proper treatment. As a retired Software Automation Test Engineer for Cisco, you can only imagine how this bothers me.
I am therefore hoping that by some quirkiness of MQL4 that the NormalizedDouble 4 Digits has an extra precision where is correct 1.4225(1) > 1.4225.
Please help I am very distressed at this point.
John
Also NOTE
Have run test script and expert which use the same logic by setting smple vars and the code succeeds. e.g.
double a = 1.4225, b = 1.4225; if ( a > b ) { Print ("Greater Than"); } else if ( a == b ) { Print ("Equal To"); } else if ( a < b ) { Print ("Less Than"); }
Use the function DoubleToStr(YourDouble,Digits).
This sounds like you are confirming my theory that the NormalizedDouble to Digits is actually a larger precision?
If this is the case then I am confused as to my solution to use DoubleToStr()
Would I be forcing a type.
NOTE I hate using needless cycles.
string t, tAnchor; o o o trigger = NormalizeDouble(iCustom(Symbol(), Period(), "_VTN Trigger", UPPER, 0),Digits); triggerAnchor = NormalizeDouble(iCustom(Symbol(), Period(), "_VTN Trigger", UPPER, 1),Digits); string t = DoubleToStr(trigger, Digits), tAnchor = DoubleToStr(triggerAnchor, Digits); if ( t> tAnchor ) { text = StringConcatenate("DynamicStoploss(): trigger ", trigger, ">", triggerAnchor, " triggerAnchor; "); _arrow = Red; } //OR trigger = NormalizeDouble(iCustom(Symbol(), Period(), "_VTN Trigger", UPPER, 0),Digits); triggerAnchor = NormalizeDouble(iCustom(Symbol(), Period(), "_VTN Trigger", UPPER, 1),Digits); t = DoubleToStr(trigger, Digits), tAnchor = DoubleToStr(triggerAnchor, Digits); trigger = t; triggerAnchor = tAnchor; if ( trigger > triggerAnchor ) { text = StringConcatenate("DynamicStoploss(): trigger ", trigger, ">", triggerAnchor, " triggerAnchor; "); _arrow = Red; }
Wrong. Use only for print functions.
text = StringConcatenate("DynamicStoploss(): trigger ", DoubleToStr(trigger,Digits), ">", DoubleToStr(triggerAnchor,Digits), " triggerAnchor; ");
OK so WE ARE off topic
The problem is that the Expert Advisor is stating that
1.4225 > 1.4225 is true.
This is what I am trying to address.
the trigger and triggerAnchor are obtained from a custom indicator.
The numbers are normalized to the precision of the currency pair.
The SELL condition under test is nearly perfect. The trade enters but a condition immediately closes the trade when the Dynamic stoploss detects that the trigger has become less than the trigger Anchor, an indication that a headfake is probable. And the trade exits for a spread loss. The actual trade goes short and never looks back hitting first and second targets.
My conundrum is that my dynamic stoploss routine is sensing a headfake when there is none. 1.4225 > 1.4225 is false but the conditional statement takes it as true.
I have upgraded to build 223 and this still occurs.
ARGGGGGH.,
Thanks so much I vaguely remember reading about this.
BUT
can you explain WHY one needs to perform such a bizare statement for MQL?
I have no CompareDoubles(d1,d2) function
???
Its in the stdlib.mq4 library.
- 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 am about at my wits end with having to make exceptions for normalized double's that don't make sense. I have had most of my troubles with conditional if statements
There are several occurrences of this problem throughout my expert. Most I have either found a different algorithm to handle the situation or had to fudge a parameter by adding or subtracting a Point to force proper treatment. As a retired Software Automation Test Engineer for Cisco, you can only imagine how this bothers me.
I am therefore hoping that by some quirkiness of MQL4 that the NormalizedDouble 4 Digits has an extra precision where is correct 1.4225(1) > 1.4225.
Please help I am very distressed at this point.
John