Download MetaTrader 5

zero divide error on m1 chart !!

To add comments, please log in or register
Sell products right in MetaTrader. Millions of traders are waiting for this!
Dimitar Pavlov
1165
Dimitar Pavlov 2016.09.02 13:18 

Hi can anyone fix the zero error divide ( the error is only when the indicator is put on m1 chart)

Thanks

 :)

Files:
ForexMTN.mq4 3 kb
Daniel Stein
24725
Daniel Stein 2016.09.02 17:12  

Please post the line numbers behind the zero divide error... 

Dimitar Pavlov
1165
Dimitar Pavlov 2016.09.02 17:19  
ForexMTN EURUSD,M1: zero divide in 'ForexMTN.mq4' (62,51)

Daniel Stein
24725
Daniel Stein 2016.09.02 17:29  

This calculation of Minr seems to result in a zero

Minr = 0.2 * (Temp / 5.0);

And this causes the zero divide error in the following two lines

AboveBuff[i] = 3.0 * (High[i]  - Main) / Minr;

BelowBuff[i] = 3.0 * (Low[i]   - Main) / Minr;

Dimitar Pavlov
1165
Dimitar Pavlov 2016.09.02 17:40  

thanks i fixed it :

instead of   Temp = 0.0

i did

Temp = 0.000001 

Damian Mateusz Dziadosz
5741
Damian Mateusz Dziadosz 2016.09.02 22:25  

Another solution is :

Minr = 0.2*(Temp*(MathPow(5,-1));
AboveBuff[i] = 3.0 * (High[i]  - Main) * (MathPow(Minr,-1));
BelowBuff[i] = 3.0 * (Low[i]   - Main) * (MathPow(Minr,-1));
Stuart Browne
5794
Stuart Browne 2016.09.03 02:34  

Always good to check any divisor in MQL that could give you a zero error. I always use a simple function:

double dblNotZero(double aValue)
{
   if (aValue==0) return(0.00001);
   else return(aValue);
}



Then pre-check any division that may produce a zero:

 

X = Y / dblNotZero(Z);
Bernhard Schweigert
5660
Bernhard Schweigert 2016.09.12 21:53  
Stuart Browne:

Always good to check any divisor in MQL that could give you a zero error. I always use a simple function:



Then pre-check any division that may produce a zero:

 

truely good advice
To add comments, please log in or register