banner ad

Adding ‘Margin Management’ to Risk Management – Part 2

This is Part 2 of the article “Adding ‘Margin Management’ to Risk Management”. If you would like to read part one .

Margin Management

The first thing we have to know about Margin Management is Leverage. Leverage in the Forex allows us to make large trades with small amounts of money, just like leverage in physics allows us to move heavy objects with small amounts of energy. When we open a Forex trading account, we choose (or are assigned) the Leverage we will trade with, ranging anywhere from 1:1 to 400:1. (As of 2010, U.S. citizens are prohibited from using anything higher than a 50:1 leverage.)

The next thing to understand is Margin. But forget about all the confusing terms such as Used Margin, Usable Margin, etc. All you need to know is:

You must always have enough money in your account to cover the Margin you are using in a trade.

So let’s find out exactly what “Margin” is….

When you place a trade, the currency pair you are purchasing has a certain Margin cost – an amount of money you must take out of your Account Balance and deposit with your broker, depending on the Leverage. Here’s how it works….

Without any leverage, to purchase and control 1 standard lot (100,000 units) of EUR/USD would cost $130,000 (if the EUR/USD rate is $1.30).

If your leverage is 100:1, then the Margin is 1%, or $1300 to control 1 lot.

If your leverage is 200:1, then the Margin is .5%, or $650 to control 1 lot.

If your leverage is 50:1, then the Margin is 2%, or $2600 to control 1 lot.

So far, so good.

One more term: Equity. Equity is simply your Account Balance when you started the trade, plus or minus the profit/loss as the trade progresses. In other words, if the trade were closed at any moment, your Equity would be your new Account Balance, reflecting what you made or lost on the trade.

When trading the Forex, you must always have 100% of the Margin required in your account. In other words…

If you are trading 1 standard lot of EUR/USD at 100:1 leverage, and the value of that pair is $1.3000 at that moment, you need $1300 in Margin, and your Equity must be equal to or greater than $1300 at any time (100% of the Margin).

Please notice that it is your Equity and NOT your Account Balance that must be equal to or greater than 100% of your Margin. So if you are in a losing trade, and your Equity goes below 100% of the Margin required for that trade, you’re going to get a Margin call/stop out. Your broker is going to close your trade immediately.

The simplest thing is to make sure your Equity never goes below 100% of the Margin required for that trade, and the easiest way to do that is to limit the number of lots you trade.

But we still want to be trading the maximum lots possible. So let’s look again at the GBP example above….

Currency pair: GBP/USD
 Account Balance: $1000
 Risk: 10%
 Stop Loss: 5 pips
 Pip Value: $10

… and let’s start with 100:1 leverage, since the math is easier.

To control 1 standard lot of GBP/USD when the price of the GBP/USD is $1.50 at 100:1 leverage, you will need $1500 in your account to even execute the trade….

((BASE currency/ Home Currency) * units) / leverage = Margin

OR

((GBP/USD) * 100,000) / 100

OR

(1.5000 * 100,000) / 100 = $1500

(There are some good Margin Calculators online to save you this work.)

Obviously, you don’t have $1500 in your account. You only have $1000 total. So if you tried to place a trade for 1 standard lot of GBP/USD with your $1000 account, your trade would not be accepted or placed.

So how many lots CAN you control of GBP/USD with $1000 in your account?

100,000 / Leverage / Margin
(100,000 / 100) / 1500 = .66

Yes, you can afford to control .66 lots of GBP/USD with your entire $1000 account.

But you can’t afford to have that trade lose even 1 pip or you will have violated your margin requirements by no longer having 100% Margin in your account at all times. By losing just 1 pip, your Equity has dropped below the 100% Margin requirement, and your trade will be stopped out by a Margin call.

So here’s how you figure out the maximum number of lots you can trade and never risk a margin call….

You figure out how much margin you will need if your trade goes bad and losses the full amount of your stop loss in pips. In other words, however much money you will have left in your account after you lose this trade must be equal to or greater than the Margin required for those lots.

Now it’s easy….

Using the GBP example above, take your account balance when you start the trade ($1000)…

Take the percentage of risk (10%) and multiply it times the account balance ($1000 times 10% = $100).

Subtract the maximum amount you are willing to lose ($100) from the account balance ($1000), and you have the amount that will be left in your account if the trade bombs ($900).

Divide that amount ($900) by the Margin required for the currency pair ($1500), and you get the maximum number of lots you can trade without a margin call (.6).

Here it is….

(Account Balance – (Account Balance * (Risk/100))) / Margin required per standard lot =
 Max Margin Lot Size

To put the whole thing in an equation….

(Account Balance – (Account Balance * (Risk/100))) / (((Base currency/ Home Currency) * 100000)
 / leverage) = Max Margin Lot Size

(If the Base Currency is the USD and your Home or Account Currency is the USD, the Base Currency/Home Currency in the equation becomes USD/USD, or 1. So if your Account Currency is USD and you are trading USDxxx (like USD/CAD), the equation would be…

(Account Balance – (Account Balance * (Risk/100))) / ( 100000 / leverage) = Max Margin Lot Size

There’s one last thing to consider….

These margin management equations are based strictly on the price of the currency pair at the time you make the calculation, and they do NOT include the spread, any commissions you might pay, slippage, or any other costs – all of which could lower your Equity below the required margin. Usually, these additional costs do not amount to very much money, so what I do is round DOWN the result of the formulas to be just that little bit more conservative. In other words, if I get the result of .724 as the maximum number of lots I could trade under Margin Management, I might actually place the trade for .70 lots, and let the other .024 cover any additional expenses of the trade.

(Using the GBP/USD example above, if I drop down to .58 lots instead of .60 lots, it makes my required margin $870 instead of $900, and that $30 should be enough for spreads, commissions, etc.)

Let’s look at one more example of a trade, just to make sure we understand this completely….

Account Balance (Home currency): $10,000
 Leverage: 50:1
 Risk: 10%
 Currency: EUR/USD
 Current Price: 1.3100

What is the maximum number of lots we can trade and not risk a Margin call? Once again, here’s the equation…

(Account Balance – (Account Balance * (Risk/100))) / (((Base currency/ Home Currency) * 100000) / leverage) = Max Margin Lot Size

OR

($10,000 – ($10,000 * (10/100))) / (((EUR/USD) * 100000) / 50)

OR

($9000) / ((1.31 * 1000000) / 50)

OR

9000 / (1310000/50)

OR

9000 / 2620

OR

3.435 Standard Lots (rounded down to 3.43)

Using Risk Management alone, the formula says we could trade 10 lots with our $1000 risk. But clearly we can only trade 3.43 lots from a Margin Management viewpoint.

So for each trade I want to place, I run both formulas….

The Risk Management Formula…

(Account Balance * (Risk/100)) / (Stop Loss in Pips * Pip Value) = Max Risk Lot Size

… and the Margin Management formula…

(Account Balance – (Account Balance * (Risk/100))) / (((Base currency/ Home Currency) * 100000)
 / leverage) = Max Margin Lot Size (rounded down)

…and then I take the smaller of the two numbers, and that’s my lot size for that trade.

In MQL4, it would look something like this (having manually entered “leverage,” “risk” percentage, and “stoploss” in pips as extern variables into the EA)….

margin management formula

 

I hope this will assist you in maximizing your lot size while minimizing any possibility of margin calls in the future.

Stephen Davis

Tags: , , , , ,

Category: MQL Programming

About the Author (Author Profile)

Steve Fleming has been a professional programmer and Internet professional for over 15 years. AutomatedTradingSoftware.com is a way to empower the non-programmers and offers a FREE 5 day E-course showing how to build an EA (expert advisor). Steve also offers his mql programming services at very competitive rates and has programmed many, many strategies both for himself and his ever growing list of satisfied clients.

Comments (0)

Trackback URL | Comments RSS Feed

There are no comments yet. Why not be the first to speak your mind.

Leave a Reply