EA reading "Zero Divide" error message.

 

So My EA is throwing out a "Zero Divide" error message.

I am aware as to what the zero divide error message is all about and I have found the culprit, but what I don't understand is why my EA is attempting to trade despite me having a controls in place to circumvent this. 

This portion of my EA works on candlestick lengths, whereby the last three candlesticks must at least be a length of 3 pips. The length of each candlestick is divided by the one preceding it in order to measure significant retracements (pretty neat eh?!). These retracements are measured as a percentage (expressed as a decimal) and are compared against a predefined percentage.

In other words the candle body must be no greater than 20% in length (or 0.20) of the one following it, thereby giving a significant retracement in the price. 

Below is only the relevant code which I have set up, but as a key I have attached the following image as I appreciate it's very hard to explain someone else's coding,

int PCM = 3;

if(
         /*Other parameters*/
         && (0.20                    >= ( bullHammer / bearNail))
         && (Transform( PCM, 2 )     <=   bullHammer)
         && (bearNail                >=   Transform(PCM,2))
         && ((bullScrew/bearNail)    <=   0.20) 
){

/*Open Position*/

}

double Transform (double Value, int Transformation){

   static double pipSize = 0;   
   if(pipSize == 0) pipSize = Point * (1 + 9 * (Digits == 3 || Digits == 5));

   switch(Transformation){ 
   
      case 0: return(Value/Point);
      case 1: return(Value/pipSize);
      case 2: return(Value*Point);
      case 3: return(Value*pipSize);  
      default: return(0);
          
   }
}

When the "bullScrew" bodylength is "0", meaning it's a doji - where the open & close prices are the same - it will read "0/<length of bearNail>"

However, surely this should not be a problem because - for example - 0/10 (bullScrew length in pips/bearNail length in pips) - should just result in zero. 

I fail to see why my EA is having a fit over the "zero divide" error when the calculation I have given it would just result in zero anyway.

Note: bullScrew can also be a bear candle. 

Many thanks.

Files:
 
BCCI:

So My EA is throwing out a "Zero Divide" error message.

I am aware as to what the zero divide error message is all about and I have found the culprit, but what I don't understand is why my EA is attempting to trade despite me having a controls in place to circumvent this. 

This portion of my EA works on candlestick lengths, whereby the last three candlesticks must at least be a length of 3 pips. The length of each candlestick is divided by the one preceding it in order to measure significant retracements (pretty neat eh?!). These retracements are measured as a percentage (expressed as a decimal) and are compared against a predefined percentage.

In other words the candle body must be no greater than 20% in length (or 0.20) of the one following it, thereby giving a significant retracement in the price. 

Below is only the relevant code which I have set up, but as a key I have attached the following image as I appreciate it's very hard to explain someone else's coding,

When the "bullScrew" bodylength is "0", meaning it's a doji - where the open & close prices are the same - it will read "0/<length of bearNail>"

However, surely this should not be a problem because - for example - 0/10 (bullScrew length in pips/bearNail length in pips) - should just result in zero. 

I fail to see why my EA is having a fit over the "zero divide" error when the calculation I have given it would just result in zero anyway.

Note: bullScrew can also be a bear candle. 

Many thanks.

use the debugger and check the values before the divide....

doubles especially prices are not often equal

 
Paul Anscombe:

use the debugger and check the values before the divide....

doubles especially prices are not often equal

Thanks for your reply. What do you mean when you say "doubles especially prices are not often equal", equal to what?

All the best, 

 

Doubles are rarely equal. Understand the links in:
          The == operand. - MQL4 programming forum #2 2013.06.07

 

I don't understand with this code

static double pipSize = 0;   
   if(pipSize == 0) pipSize = Point * (1 + 9 * (Digits == 3 || Digits == 5));

Why you using static on pipSize with value 0 and then using If statement to set another value?

And on debugger it shows which line of code that contain the problem, can you tell us which specific line of code that cause the problem?

 
Luandre Ezra: Why you using static on pipSize with value 0 and then using If statement to set another value?

One time initialization. It would have been better if it was just done on load.

static double pipSize = Point * (1 + 9 * (Digits % 2 == 1));
// Or
static double pipSize = Digits % 2 == 1 ? 10*Point : Point;