# ExpertMoney.mqh

486

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)

else

if(lot<m_symbol.LotsMin()) return(0.0);

//---

return(m_symbol.LotsMin());

}

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
• www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
62

You are right. It should be
`if(lot<m_symbol.LotsMin()) return(0.0);`

18

@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,                           |
//|         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
{
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);
}
//+------------------------------------------------------------------+```