//+------------------------------------------------------------------+ //| ExpertMoney.mqh | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #include "ExpertBase.mqh" //+------------------------------------------------------------------+ //| Class CExpertMoney. | //| Purpose: Base class money managment. | //| Derives from class CExpertBase. | //+------------------------------------------------------------------+ class CExpertMoney : public CExpertBase { protected: //--- input parameters double m_percent; public: CExpertMoney(void); ~CExpertMoney(void); //--- methods of setting adjustable parameters void Percent(double percent) { m_percent=percent; } //--- method of verification of settings virtual bool ValidationSettings(); //--- virtual double CheckOpenLong(double price,double sl); virtual double CheckOpenShort(double price,double sl); virtual double CheckReverse(CPositionInfo *position,double sl); virtual double CheckClose(CPositionInfo *position); }; //+------------------------------------------------------------------+ //| Constructor | //+------------------------------------------------------------------+ void CExpertMoney::CExpertMoney(void) : m_percent(10.0) { } //+------------------------------------------------------------------+ //| Destructor | //+------------------------------------------------------------------+ void CExpertMoney::~CExpertMoney(void) { } //+------------------------------------------------------------------+ //| Validation settings protected data. | //+------------------------------------------------------------------+ bool CExpertMoney::ValidationSettings() { if(!CExpertBase::ValidationSettings()) return(false); //--- initial data checks if(m_percent<0.0 || m_percent>100.0) { printf(__FUNCTION__+": percentage of risk should be in the range from 0 to 100 inclusive"); return(false); } //--- ok return(true); } //+------------------------------------------------------------------+ //| Getting lot size for open long position. | //+------------------------------------------------------------------+ double CExpertMoney::CheckOpenLong(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_BUY,m_symbol.Ask(),m_percent); else lot=m_account.MaxLotCheck(m_symbol.Name(),ORDER_TYPE_BUY,price,m_percent); if(lotm_account.Balance()*m_percent/100.0) return(position.Volume()); //--- return(0.0); } //+------------------------------------------------------------------+