Fellow coders,
No disrespect intended, but there's absolutely no excuse for having your EAs and indicators fall over with 'division by zero' errors.
All you need is to include a function similar to this:
//+------------------------------------------------------------------+
double Divide(double n, double d)
//+------------------------------------------------------------------+
{
if (d == 0) return(0); else return(n/d);
}
at the end of your source.
And then instead of coding:
C = A/B;
use
C = Divide(A,B);
A and B can be expressions, as complex as you like.
That way, should B ever evaluate to zero, the error is trapped and handled. Returning a value of 0 might not be ideal, but it's better than having your executable fall over.
No disrespect intended, but there's absolutely no excuse for having your EAs and indicators fall over with 'division by zero' errors.
All you need is to include a function similar to this:
//+------------------------------------------------------------------+
double Divide(double n, double d)
//+------------------------------------------------------------------+
{
if (d == 0) return(0); else return(n/d);
}
at the end of your source.
And then instead of coding:
C = A/B;
use
C = Divide(A,B);
A and B can be expressions, as complex as you like.
That way, should B ever evaluate to zero, the error is trapped and handled. Returning a value of 0 might not be ideal, but it's better than having your executable fall over.