Calculate the volume size (in MT4)

I thought of putting together a small formula that I use to calculate the volume size (in MT4), based on your risk %

I would like to know whether this formula is correct.

A = Risk amount

If risk percentage is 2% and the account balance is X

A = X * 2%
B = Buy / Sellprice - Stop Loss (calculating total pips risked)
C = 1 pip value

Volume (Lot Size: VL) = (A / B) / C

X = 750
A = 15
B = 1.2530 - 1.2500 = 30
C = 0.5
VL = (15 / 30) /0.50
VL = 1

Comments are very much appreciated


It’s better to use “MODE_TICKVALUE” to obtain buy or Sellprice, Here is the code :

double Lots ;
double Price = Marketinfo(Symbol(),MODE_TICKVALUE);
int Risk = 2;
int Stoploss =30;

Lots = ((accountfreemargin()Risk )/100)/(StoplossPrice));


Hi Donsls !

I don’t know about other traders, but to me, it seems to be one of the major flaws in MT4. Only Oanda has best in-built calculator regarding different parameters of trades such as dollar value of pips, trade value, etc. Anyways, below is the formula of how the lot size is calculated in MT4 (with assumptions, because I don’t know which broker you are demo trading with:

[B][U]Account Curency: USD[/U][/B]

  1. Trading Capital [B][U]USD 1000[/U][/B]

  2. Leverage [B][U]500[/U][/B]

  3. Current Quote, as an example, [B][U]EUR USD 1.30000[/U][/B] (for simplicity)

  4. Total Available Units : ( Trading Capital x Leverage ) divided by the current quote 1.30000 = EUR 384,615

  5. Risk % = 2%

Given the above, the lot size is calculated as follows:

= Total Available Units (from Point 4 above) x Risk %
= EUR 384,615 x 2%
= 7692 units or 0.77 lot (rounded to the nearest)

Now comes [B][U]“the most important part”[/U][/B]. The above 2% (Risk %) is not the actual % your trading capital is at risk.

The [B][U]effective risk %[/U][/B], by which your account is risk at depends on [B][U]leverage and stop loss[/U][/B].

Continuing from above, if you are long EUR USD at 1.30000 using 7692 (or 0.77 lot), and you put a stop loss of 20 pips, the amount at risk is USD 15.38.

[B][U]How ?[/U][/B]

With the lot size of 7692, the pip value is USD 0.77 (don’t confuse this with lot size because lot size is always in base currency). If the pip value is USD 0.77, the 20 pips would be worth USD 15.38 (20 pips x USD 0.77 pip value - your calculator may show 15.4, that’s because of rounding). Now if the trade goes against you and your trade hits the stop loss, you would simply lose USD 15.38.

If you divide this USD 15.38 by $1000 (which is your trading capital, it comes to 1.53%. So 1.53% of your trading capital is effectively at risk, not 2%. The reason is leverage. If your account leverage is 1000, the 20 stop loss would be equal to USD 30.77, which is 3% of trading capital.

[B][U][This is what scalpers do, they set their Risk % (Point 5 above) really high and set their stop losses really small.][/U][/B]

So, now you see the Margin in MT4. Margin is simply Lot Size x Quote (in EUR USD) divided by leverage.

So in the above example, the margin will be USD 20.

Free Margin is Equity - Margin. ($1000 - $20)
Margin Level is Equity Divided by Margin [($1000 / 20) x 100] = 5000% (but this will be slightly different because when you open a trade, it will be negative because of spread, and equity also reduces accordingly.

Now the above margin should not drop to Margin Call %, which is set by your broker. My broker’s Margin Call is 50%.

What does this mean is that if the above 5000% drops to 50%, I will get a margin call and I will not be able to place new trades.

Stop Out Level, assume 10%, means the above should not drop to 10%, if it did, you will be stopped out.

I do understand that the above may be difficult for you to understand, but I would suggest you to use Oanda platform and see how these things are calculated. Then do the same in MT4 and make a wrong trade. After making the loss trade, post the pic here or simple the figures and leverage, and I’ll help you understand it.