CExpertMoney classes and required margin check

 

I like the idea of having dedicated classes for money management within MQL5: CExpertMoney and derived classes, especially CMoneyFixedRisk, which allows to defined a percent of risk for a trade (e.g. 2%).

I though that these classes are meant as "ready to go" but now it seems to me that they are not really mature.

E.g. I found out that while in the parent class, CExpertMoney, there is a check for the available margin:

//+------------------------------------------------------------------+
//| Getting lot size for open short position.                        |
//+------------------------------------------------------------------+
double CExpertMoney::CheckOpenShort(double price,double sl)
  {
   if(m_symbol==NULL)
      return(0.0);
//---
   double lot;
   if(price==0.0)
      lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_SELL,m_symbol.Bid(),m_percent);
   else
      lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_SELL,price,m_percent);
   if(lot<m_symbol.LotsMin())
      return(0.0);
//---
   return(m_symbol.LotsMin());
  }

but in the derived class, CMoneyFixedRisk, there is no such check, only static, balance-independent min and max volumes are checked, which means that at OrderSend(...) there will be an 10019 error thrown (TRADE_RETCODE_NO_MONEY, "There is not enough money to complete the request").

//+------------------------------------------------------------------+
//| Getting lot size for open short position.                        |
//+------------------------------------------------------------------+
double CMoneyFixedRisk::CheckOpenShort(double price,double sl)
  {
   if(m_symbol==NULL)
      return(0.0);
//--- select lot size
   double lot;
   double minvol=m_symbol.LotsMin();
   if(sl==0.0)
      lot=minvol;
   else
     {
      double loss;
      if(price==0.0)
         loss=-m_account.OrderProfitCheck(m_symbol.Name(),ORDER_TYPE_SELL,1.0,m_symbol.Bid(),sl);
      else
         loss=-m_account.OrderProfitCheck(m_symbol.Name(),ORDER_TYPE_SELL,1.0,price,sl);
      double stepvol=m_symbol.LotsStep();
      lot=MathFloor(m_account.Balance()*m_percent/loss/100.0/stepvol)*stepvol;
     }
//---
   if(lot<minvol)
      lot=minvol;
//---
   double maxvol=m_symbol.LotsMax();
   if(lot>maxvol)
      lot=maxvol;
//--- return trading volume
   return(lot);
  }

(both functions MaxLotCheck() and OrderProfitCheck() are defined within CAccountInfo class).


I'm a bit dissapointed since it means that for real use I cannot take those classes and use (it was my naive expectation), but I need to derive my own class for fixed percent risk money management and the provided classes are nothing more than just very simplistic examples.

Also this gives me a feeling, that I cannot rely on any of the provided object oriented classes but need to be very careful and double check each line of their framework code, instead of focusing on the EA logic only.

Am I right or did I misunderstand something?

Reason: