SteveHopwood wrote:
Described briefly, the ea modifies the stop loss and take profit of pending trades to reflect those of an open trade. The ea kept on insisting that the various sl/tp's were not equal even though they are.
I had the same problem.
Compared 2 doubles which were Normalized before ( NormalizeDouble ) and went almost crazy
because they should have been identical but the if( a == b) resulted in false.
hanover helped me.
Now I use his MathFix function. And all is fine.
Example: Double A;
Double B;
I compare them like this:
Code: Select all
if (mf(A) == mf(B)) {
code .....
}
Just copy the following functions into your code:
Code: Select all
//+------------------------------------------------------------------+
//| Function: Better than NormalizeDouble |
//+------------------------------------------------------------------+
double mf(double value) {
return(MathFix(value,Digits));
} //------------END FUNCTION-------------//
//+------------------------------------------------------------------+
double MathFix(double n, int d=0)
//+------------------------------------------------------------------+
// Corrects a rounding/accuracy bug in MQL4's MathRound() function
// (use MathFix(n) instead of MathRound(n)
// Rounds n to d decimal places, e.g.
// MathFix(2.54,1) returns 2.5
// MathFix(2.57,1) returns 2.6
// MathFix(2.99) returns 3
{
return(MathRound(n*MathPow(10,d)+0.000000000001*MathSign(n))/MathPow(10,d));
} //------------END FUNCTION-------------//
//+------------------------------------------------------------------+
int MathSign(double n)
//+------------------------------------------------------------------+
// Returns the sign of a number (i.e. -1, 0, +1)
// Usage: int x=MathSign(-25) returns x=-1
{
if (n > 0) return(1);
else if (n < 0) return (-1);
else return(0);
} //------------END FUNCTION-------------//