English

## Margin required for opening a position

 323 Zypkin 2008.12.21 13:01   A question to the gurus of MQL4. MarketInfo(Symbol(),MODE_MARGINREQUIRED) returns the margin required to open one lot. Is the realtion between lots and margin required linear? In other words, if I want to open 0.1lots shall I have freemargin > MarketInfo(Symbol(),MODE_MARGINREQUIRED) * 0.1? ...same for volumes > of 1 lot? ...say to open 10lots I need freemargin > MarketInfo(Symbol(),MODE_MARGINREQUIRED) * 10 ??? Is there any other way to check which is the max size in lots I can open with the current freemargin? Thanks a lot for replies. Zyp similar
 446 blogzr3 2008.12.21 18:59 #   The relation between lots and margin is linear and is a fixed ratio, based on your type of account, i.e. it's leverage, so simple arithmetic would tell you the maximum number of lots you can open. However, as the open position moves in the negative direction, that would also eat into the margin, so you need to allow for that too.
 323 Zypkin 2008.12.21 20:40 #   blogzr3: The relation between lots and margin is linear and is a fixed ratio, based on your type of account, i.e. it's leverage, so simple arithmetic would tell you the maximum number of lots you can open. However, as the open position moves in the negative direction, that would also eat into the margin, so you need to allow for that too. ...uhmmm... not quite clear. MarketInfo(Symbol(),MODE_MARGINREQUIRED) returns the margin required to open 1.00 lot... and I expect it takes account of everything already. Let's make an example to clarify what I aim to: - balance 10 000 EUR, no order open yet. - symbol = USDCHF - running MarketInfo(Symbol(),MODE_MARGINREQUIRED) funcion returns ---> 718.29 ...which means I must have at least 718.29 EUR of free margin to open 1.00 lot position. Now, if I want to know how many lots I can buy/sell with my 10 000 EUR I do the following math: 10 000 / 718.29 = 13.92 What I expect is that 13.92 is the maximum size of an order that the system will accept from my account without raising an error message. Is that correct? similar
2644
phy 2008.12.22 00:33 #

You may need to include
 AccountStopoutLevel( )

 2 sysmaya 2016.04.08 04:41 #   ```double MarginCalculate(string symbol, double volume){    double leverage = AccountLeverage();    double contract = MarketInfo(symbol, MODE_LOTSIZE);    return(contract*volume / leverage); }```
 69 Tecuciztecatl 2016.04.09 00:06 #   sysmaya: ```double Margin=MarketInfo(Symbol(),MODE_MARGINREQUIRED); double FreeMargin=AccountFreeMargin(); double howLots=NormalizeDouble(FreeMargin/Margin,2); Print ("howLots=",DoubleToStr(howLots,2));```