Body/Candle ratio

 
Hello guys,

I'm trying to include the body_height/candle_height ratio to my entry conditions and MT is complaining about "zero-divide".

This is how i try ty calculate it:

double low = iLow(NULL, 0, 1);
double high = iHigh(NULL, 0, 1);
double close = iClose(NULL, 0, 1);
double open = iOpen(NULL, 0, 1);
double candle_height = (high-low);
double body_height = MathAbs(open-close);

double ratio = (body_height/candle_height);

Any ideas what I'm doing wrong here?

Thanks a lot!
 
I see you are using current symbol and timeframe. Try using High[i], Low[i], Open[i] and Close[i] instead... i being shift. And check whether High really isn't equal to Low.
 

If the high is equal to the low, then double candle_height = (high-low) equals zero.

Then, double ratio = (body_height/candle_height) causes a divide by zero error

Dividing by zero is not permitted, and the code exits with "divide by zero" error..

Reason: