1. ## 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?

2. Probably the open is equal to close.

3. To prevent the zero divides from happening, you need to make it a condition that the calculation only runs if the open and close aren't equal. Like this:

PHP Code:
``` if(Close0 != Open1)  Proportion1=(Close0-Open0)/(Close0-Open1); if(Close1 != Open1)  Proportion2=(Close2-Open2)/(Open1-Close1); if(Close2 != Open2)  Proportion3=(Close0-Open0)/(Close2-Open2); // and so on...  ```
If Close0 does equal Open1, etc, the values for Proportion1, Proportion2, etc will be their last stored value. Depending upon how the rest of your code works, you may need to assign them a different value in a new line before the condition. Like this:

PHP Code:
``` Proportion1 = 1; // or whatever value you need it to be if(Close0 != Open1)  Proportion1=(Close0-Open0) / (Close0-Open1); // and so on...  ```
One other tip. If you leave a space before and after the division slash (/) as I have done above, you will find it easier to search for divisions within your code because you won't be finding any comments.