zero divide on Risk Management

 

Hello everyone this morning on the ea logs that I activated yesterday

I got this error but having not touched anything on these code

I do not understand what it is due to

I'll show you in what string it gives me the error



double _get_lot_size(double SLpips)
  {
   double AcFrMar, MoneyRisk, pipValue, lots = 0;

   if(Position_Size_Management == 0 || (Position_Size_Management == 1 && Last_Trade_Win == -1))
     {
      if(Risk>0 && SLpips>0)
        {
         AcFrMar = NormalizeDouble(AccountFreeMargin(),2);
         MoneyRisk = NormalizeDouble((AcFrMar*(Risk/100)),2);

         //SLpips=slDist/Point/mp;
         pipValue=MarketInfo(Symbol(),MODE_TICKVALUE);
         lots=NormalizeDouble((((MoneyRisk/SLpips)/pipValue)/mp),LotRound);
         Print("lots:",lots,",MoneyRisk:",MoneyRisk,",SLpips:",SLpips,",LotRound",LotRound,",minLot:",minLot);

         if(lots<minLot)
            lots=minLot;
         if(lots > maxLots)
            lots = maxLots;
        }
      else
         lots=Lot_Size;

      Last_Position_Size = lots;
     }

   if(Position_Size_Management == 1 && Last_Trade_Win > -1)
     {
      Print("lots:",lots, ",Last_Position_Size:",Last_Position_Size, ",Lot_Size_Mod:",Lot_Size_Mod);
      if(Last_Trade_Win == WIN_YES)
         lots = Last_Position_Size * ((Lot_Size_Mod / 100) + 1);
      if(Last_Trade_Win == WIN_NO)
         lots = Last_Position_Size * (1 - (Lot_Size_Mod / 100));
      Print("lots:",lots, ",mod:",(Lot_Size_Mod / 100));
      if(lots<minLot)
         lots=minLot;

      if(lots > maxLots)
         lots = maxLots;

      Last_Position_Size = lots;
     }

   return(lots);
  }





 
Comandantf:

Hello everyone this morning on the ea logs that I activated yesterday

I got this error but having not touched anything on these code

I do not understand what it is due to

I'll show you in what string it gives me the error

Mr. Roeder is right; debugging is an important part to learn from our own mistakes.
And we can't see enough code to Debug even if we wanted to help...

If the compiler says that this string of code divides by zero, print all the values right before the string and look.
We cannot see how Variables "pipValue" and "mp" are calculated/initialized.
Should be a really easy fix using Print().

Print - Common Functions - MQL4 Reference
Print - Common Functions - MQL4 Reference
  • docs.mql4.com
Print - Common Functions - MQL4 Reference
Reason: