Error Zero Divide, yet there is a loop condition if not zero then only run the code !!!

 

strange behavior from MQL5 !!!

Even though I have a condition != 0, still code goes through the loop and returns zero divide in 'FxEAPrintDataStats.mq5' (60,78)

//--- Calculate Rate of Change for BandWidth M5
double M05_ROC_BW;
//---  RISING Index[1] < Index[0] | FALLING RISING Index[1] > Index[0]
if(M05_BWPrevious[index] != 0)
  M05_ROC_BW = (M05_BWPrevious[index-1] - M05_BWPrevious[index]) / M05_BWPrevious[index] * 100;
else
  M05_ROC_BW = 0;

any ideas what is wrong here !!!

 
Print(M05_BWPrevious[index-1]);
Print(M05_BWPrevious[index]);
 
Marco vd Heijden:

Thanks Marco for reply. Yes I do check values by using Print statement, and know my first row value is Zero, hence the condition if(M05_BWPrevious[index] != 0) applied.

But still it by passes, the if condition and returns zero divide error.

on a positive note, after an hour or so, complier has started recognizing this if condition and does not give error any more. STRANGE behavior.

 
Anil Varma:

Thanks Marco for reply. Yes I do check values by using Print statement, and know my first row value is Zero, hence the condition if(M05_BWPrevious[index] != 0) applied.

But still it by passes, the if condition and returns zero divide error.

on a positive note, after an hour or so, complier has started recognizing this if condition and does not give error any more. STRANGE behavior.

just quick idea: maybe you need to check that the value isnt empty?

 
Revo Trades:

just quick idea: maybe you need to check that the value isnt empty?

Thanks Revo

yeh it make sense, will try it if the error comes again.

Reason: