# Margin required for opening a position

106

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

506

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.

106

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?

2650

You may need to include
 AccountStopoutLevel( )

506

- 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?

Sorry, my previous answer was based on the account currency being USD, which is not your case. In your case, the value returned by the MarketInfo function will vary according to the exchange rate.

Theoritically, 13.92 is the maximum lot size you can open. Practically, you may need to account for AccountStopOutLevel as phy mentioned, which may be different from broker to broker.

204

```double MarginCalculate(string symbol, double volume){
double leverage = AccountLeverage();
double contract = MarketInfo(symbol, MODE_LOTSIZE);
return(contract*volume / leverage);
}```
15551

Zypkin: Is there any other way to check which is the max size in lots I can open with the current freemargin
1. AccountFreeMarginCheck - Account Information - MQL4 Reference
2. But FM for opening is not enough. See last item.
• You place the stop where it needs to be - where the reason for the trade is no longer valid. E.g. trading a support bounce the stop goes below the support.
• Account Balance * percent = RISK = |OrderOpenPrice - OrderStopLoss| * OrderLots * DeltaPerlot (Note OOP-OSL includes the SPREAD)
• Do NOT use TickValue by itself - DeltaPerlot
• You must normalize lots properly and check against min and max.
• You must also check FreeMargin to avoid stop out
70

sysmaya:

```double Margin=MarketInfo(Symbol(),MODE_MARGINREQUIRED);
double FreeMargin=AccountFreeMargin();
double howLots=NormalizeDouble(FreeMargin/Margin,2);

Print ("howLots=",DoubleToStr(howLots,2));```