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".
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
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.
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

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear Traders
Please help
What do you mean by error 'zero divide'
Thanks in advance