Lot size not calculating

 

Hi,

In the following simple code, i seek to evaluate lot size for 3 possible cases, but it is not returning the size based on the risk in pips (say 50 pips).

Please help what correction is required.

enum Money_Management 
{
   Equity_Percent = 1, // % Equity
   Fixed_Lot_Size = 2, // Fixed Lot Size
   Fixed_Money = 3, // Fix Money Based Options
};


input string Mera_MM = "Mera Money Manager"; // === Breakeven ===
extern bool MM = true;
input Money_Management money_op = Equity_Percent; // Money Management options
extern double EquityRisk = 5; //% of Equity
extern double FixedLotRisk = 0.5;
extern double FixedMoneyRisk = 250; //Fixed Money Risk (USD or EUR)
extern double LotDigits = 2;
extern int RiskPips = 30;

double lots = 0.0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---


//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   GetLots();  
  }
//+------------------------------------------------------------------+


// Money Managment Block
double GetLots()
{
   double minlot = MarketInfo(Symbol(), MODE_MINLOT);
   double maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
   double leverage = AccountLeverage();
   double lotsize = MarketInfo(Symbol(), MODE_LOTSIZE);
   double stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
   double MinLots = 0.01;
   double MaximalLots = 50.0;
   
   if(MM)
   {
      switch(money_op)
      {
         case Equity_Percent: lots = FixedLotRisk;;
               lots = NormalizeDouble(AccountFreeMargin() * EquityRisk/100 / 1000.0, Digits);
               Print("Fixed Equity Risk Lots = ",lots);
               if(lots < minlot) lots = minlot;
               if (lots > MaximalLots) lots = MaximalLots;
               if (AccountFreeMargin() < Ask * lots * lotsize / leverage) 
               {
                  Print("We have not money. Lots = ",lots," , Free Margin = ",AccountFreeMargin());
                  Comment("We have not money. Lots = ",lots," , Free Margin = ",AccountFreeMargin());
               }
         case Fixed_Lot_Size: lots = NormalizeDouble(FixedLotRisk,Digits);
               Print("Fixed Lots Lots = ",lots);
               if (AccountFreeMargin() < Ask * lots * lotsize / leverage) 
               {
                  Print("We have not money. Lots = ",lots," , Free Margin = ",AccountFreeMargin());
                  Comment("We have not money. Lots = ",lots," , Free Margin = ",AccountFreeMargin());
               }
         case Fixed_Money: lots = NormalizeDouble(FixedMoneyRisk / 1000.0, Digits);
               Print("Fixed Money Lots = ",lots);
               if(lots < minlot) lots = minlot;
               if (lots > MaximalLots) lots = MaximalLots;
               if (AccountFreeMargin() < Ask * lots * lotsize / leverage) 
               {
                  Print("We have not money. Lots = ",lots," , Free Margin = ",AccountFreeMargin());
                  Comment("We have not money. Lots = ",lots," , Free Margin = ",AccountFreeMargin());
               }
      }

   }
      else lots = NormalizeDouble(FixedLotRisk,Digits);
      return(lots);
}

 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893