Download MetaTrader 5

zero divide

To add comments, please log in or register
Trade like successful traders - subscribe to their signals!
Sabu John
327
Sabu John 2012.12.08 23:29 

Dear Traders

Please help

What do you mean by error 'zero divide'

 

Thanks in advance 

Gabor Torma
2676
Gabor Torma 2012.12.09 00:07  

It means your code something divide with zero.

If it's your code, you can post and we will check it.

If it's not yours, please contact the developer.

phi nuts
2184
phi nuts 2012.12.09 00:35  
dummy:

Dear Traders

Please help

What do you mean by error 'zero divide'

 

Thanks in advance 

Use your calculator (for example your Windows calculator), divide any number with zero (for example, 5) ...

double result;

result = 5/0;

and you will have zero divide error. In Windows calculator, it will say "Cannot divide by zero".

Sabu John
327
Sabu John 2012.12.09 23:40  

uThis is the code I Use for calulating lot size and I  keep SL  never at zero.In the error message it shows some difficult calculation but never involves zero

and this error comes only ehen I use higher values for risk,only when I use it as a multicurrency EA.At lower values it works. 


//+------------------------------------------------------------------+ 
//                  Find Lot Size using Risk
//+------------------------------------------------------------------+ 

double MyLotCalc()

  if (LotSize!=0) return(LotSize);
 
  if (StopLoss<=0) {Print("Set Stop Loss to Some Value in Order To Use RiskPercent"); return(SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));}
 
  double dMoneyRisk = RiskPercent*AccountInfoDouble(ACCOUNT_EQUITY)/100;
  double dMyLotLocal = (dMoneyRisk/(StopLoss * SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)))/(MyPoint/_Point);
  if (dMyLotLocal < SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)) dMyLotLocal = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN) ;
  if (dMyLotLocal > SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX)) dMyLotLocal = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX) ;
 
 
  dMyLotLocal = NormalizeDouble(dMyLotLocal,iNDigets);
  return(dMyLotLoc

 

Thanls in advance 

phi nuts
2184
phi nuts 2012.12.10 00:09  

1. Come on dummy, use SRC button to post the code ;D

 

2. When calculating lot, we should calculate using SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_STEP. You forget the last one. There's plenty example in forum, - eh ... for example - see example here  https://www.mql5.com/en/code/961

3. I'm looking at your code, and looks okay. However, if you still have that error then you to print everything, print the value of every variable !. You probably hate that, but I just spend weekend re-writing my code, and print help me pin point the logic and syntax error in my code quickly.

Sabu John
327
Sabu John 2012.12.10 00:19  
phi.nuts:

1. Come on dummy, use SRC button to post the code ;D

 

2. When calculating lot, we should calculate using SYMBOL_VOLUME_MIN and SYMBOL_VOLUME_STEP. You forget the last one. There's plenty example in forum, - eh ... for example - see example here  https://www.mql5.com/en/code/961

3. I'm looking at your code, and looks okay. However, if you still have that error then you to print everything, print the value of every variable !. You probably hate that, but I just spend weekend re-writing my code, and print help me pin point the logic and syntax error in my code quickly.

//+------------------------------------------------------------------+  
//                  Find Lot Size using Risk
//+------------------------------------------------------------------+  

double MyLotCalc()
{  
  if (LotSize!=0) return(LotSize);
  
  if (StopLoss<=0) {Print("Set Stop Loss to Some Value in Order To Use RiskPercent"); return(SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN));}
  
  double dMoneyRisk = RiskPercent*AccountInfoDouble(ACCOUNT_EQUITY)/100;
  double dMyLotLocal = (dMoneyRisk/(StopLoss * SymbolInfoDouble(_Symbol,SYMBOL_TRADE_TICK_VALUE)))/(MyPoint/_Point);
  if (dMyLotLocal < SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)) dMyLotLocal = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN) ;
  if (dMyLotLocal > SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX)) dMyLotLocal = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX) ;
  
  
  dMyLotLocal = NormalizeDouble(dMyLotLocal,iNDigets);
  return(dMyLotLoc
To add comments, please log in or register