Zero Divide

 

Hi,

I have a proble when during a Strategy Testing i always get an error "zero divide".

The only division I have are these lines -

Proportion1=(Close0-Open0)/(Close0-Open1);
Proportion2=(Close2-Open2)/(Open1-Close1);
Proportion3=(Close0-Open0)/(Close2-Open2);

Proportion4=(Close2-Open2)/(Close0-Open0);

Proportion5=(Open0-Close0)/(Open1-Close0);
Proportion6=(Open2-Close2)/(Close1-Open1);
Proportion7=(Open0-Close0)/(Open2-Close2);

Proportion8=(Open2-Close2)/(Open0-Close0);

I think these lines can't be divided by zero because of the different prices each time...

What should I add or change to eliminate this error?

 
If OpenPrice is the same As Closeprice you would have a zero divide error. Doji's are a typical example.
 

Thanks for your reply. But Dojis appear seldom and I get this error millions of times when I start my EA in the Strategy Tester.

Anyway, could you tell me how can I use these proportions without getting "zerodivide" error?

 

well if you are using every tick mode and you will get a zero divide every time when bid == Open

the solutions depends what you intend to do when you get open==close. some simple solution would be:

if((Close0-Open1)!=0){
Proportion1=(Close0-Open0)/(Close0-Open1);
}else{
 
}

you have to do that for each expression.

 
Thanks a lot, it worked.
Reason: