You are right. It should be
if(lot<m_symbol.LotsMin()) return(0.0);
@hornsALERT is right. It should return 0.0 when lot<LostMin() for the limits of desired Margin
The code from standard library that quoted by @och just return 0.0 or m_symbol.LotsMin(), return 0.0 when lot<m_symbol.LotsMin() is OK, otherway why not return lot instead of m_symbol.LotsMin()? Does anyone explain?
lot=m_account.MaxLotCheck(...);
The function m_account.MaxLotCheck(...); in AccountInfo.mqh alredy check for minvol and maxvol (see code below). I think, it is not necessary to recheck like the code above.
//+------------------------------------------------------------------+ //| Access functions OrderCalcMargin(...). | //| INPUT: name - symbol name, | //| trade_operation - trade operation, | //| price - price of the opening position, | //| percent - percent of available margin [1-100%]. | //+------------------------------------------------------------------+ double CAccountInfo::MaxLotCheck(const string symbol,const ENUM_ORDER_TYPE trade_operation, const double price,const double percent) const { double margin=0.0; //--- checks if(symbol=="" || price<=0.0 || percent<1 || percent>100) { Print("CAccountInfo::MaxLotCheck invalid parameters"); return(0.0); } //--- calculate margin requirements for 1 lot if(!OrderCalcMargin(trade_operation,symbol,1.0,price,margin) || margin<0.0) { Print("CAccountInfo::MaxLotCheck margin calculation failed"); return(0.0); } //--- if(margin==0.0) // for pending orders return(SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX)); //--- calculate maximum volume double volume=NormalizeDouble(FreeMargin()*percent/100.0/margin,2); //--- normalize and check limits double stepvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP); if(stepvol>0.0) volume=stepvol*MathFloor(volume/stepvol); //--- double minvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN); if(volume<minvol) volume=0.0; //--- double maxvol=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX); if(volume>maxvol) volume=maxvol; //--- return volume return(volume); } //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi All,
I tried to understand ExpertMoney.mqh. Is there someone who can explain this part of that class?
Even if we are using a derivated class and if we are surcharging CheckopenLong and checkOpenClose, according to me the end of thoses functions should be :
....
if(lot<m_symbol.LotsMin()) return(m_symbol.LotMin());
if(lot>m_symbol.LotsMax()) return(m_symbol.LotMax());
//---
return(lot);
----------- extract from standard library
//+------------------------------------------------------------------+
//| Getting lot size for open long position. |
//| INPUT: no. |
//| OUTPUT: lot-if successful, 0.0 otherwise. |
//| REMARK: no. |
//+------------------------------------------------------------------+
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(lot<m_symbol.LotsMin()) return(0.0);
//---
return(m_symbol.LotsMin());
}