Friday, January 8, 2010

MetaTrader - Account and Position Sizing

Welcome back, Forex fans.

Let's talk about account and position sizing.

We all know that Forex is risky and we stand a higher-than-normal chance of blowing up an account versus most other types of investments.

From a personal perspective, I want to keep my forex exposure to less than 5% of my entire portfolio. So assuming I have a 100K portfolio, I'm looking allocating no more than $5000 to Forex. For testing purposes, i'm planning a $1000 account size for any given trading strategy. This way if the account goes into 50% drawdown, I've lost only one half of 1% of my entire portfolio. Besides, we can always increase the account size if things work out.

Once I have the account setup and Expert selected, how much do I allocate to each trade?

The great thing about MetaTrader accounts (that I didn't have with FXCM) is the ability to trade in fractions of a lot. With FXCM, if I had a 10K account, I could only trade in 10K lots. With a 100K account, I could only trade in 100K lots. No so with MetaTrader where I can trade all the way down to 0.01 lots. So for a $1000 account, I can trade 0.01 of the full 100K size which is $1000 worth of currency. Or I can trade 0.10 of the full 100K which is 10,000 worth of currency. So this means I can be much more granular in term of how much I want allocate to each position.

With my forex account at only 5% of my total portfolio, I can safely allocate between 5% and 10% of my account to each position. Any more than that and we stand the risk of blowing our account up with just a few loosing trades. Any less than that, and we aren't getting the most of the account as is possible. It doesn't mean I need to risk the entire 5% on each trade, but its a starting point.

Ideally, we also want to lower our bet size as the account shrinks and increase it as the account grows to take advantage of compounding.

In the original Turtle Trader Rules Richard Dennis and William Ekhard calculate their exposure to each position based on the dollar volatility of the contract as measure by the ATR or Average True Range. They also calculated their stops as a percentage of account equity based on the ATR.

So each position size is a function of account size, volatility of the pair and amount we want to risk. Let's paste the following code into the Start() function of the EA called AccountStuff that we created in the last post:

int start()
{
double dContractSize = 100000.0;
double dRisk = 0.05;
double dATR = iATR(Symbol(), 1440, 14, 0);

Print("ATR is: ", dATR);
if (dATR > 0.1) dATR = dATR / 100.0;

// Calculate how much contract value represented by one ATR
double dUnits = dContractSize * dATR;

// Calculate how much account we want to risk
double dAccountPct = AccountBalance() * dRisk;

// Calcuate lots
double dLots = dAccountPct / dUnits;

// Normalize double
dNormalLots = NormalizeDouble(dLots,2);
Print("Units is: ", dUnits);
Print("AccountPct: ", dAccountPct);
Print("Lots: ", dNormalLots);

return(0);
}

This code starts by setting some constants for risk and contract size. Then it calculates the Average True Range for the pair 14 days. The 1440 parameter means daily and the period is 14. For more information, see Meta Trader development course.


Next the code calculates the value change in the contract for one movement of ATR into the variable dUnits. Then it calculates the amount of the account that represents 5% into dAccountPct. Finally we divide the amount to risk (dAccountPct) by one ATR if contract value (dUnits) to and round to 2 decimal places to come up with the number of lots.

Now save and compile that code and fix any syntax errors. Then drag the EA onto various currency pairs and examine the output on the Experts tab. For EUR/USD and a $1000 account, the lots come to 0.03 representing about 3K worth of currency per position.

If you get a divide by 0 error, then you probably don't have enough history to calculate the ATR. Select Tools, History center and add more data for the tradable and timeframe.

Now assume you have a good year with your EA and your account grows to 1,600. Now replace the AccountBalance() function about with a constant of 1600.0 and you'll see the lots now calculate to 0.06. Now change account balance to 10000.0 and the lots will re-calculate to 0.38. There you have it, automatic lot size adjusted for account size and underlying volatility of the pair!

Daniel Hernandez takes it one step further and calculates stop loss and take profit values based on ATR in a similar way. Take a look at his e-book for details. We'll take a look at exit and take profit strategies when we get to talking about specific EA's.

That's all for now, enjoy your weekend.

3 comments:

  1. Very good post and exactlly what i need on my mtf stoch ea , would really want some money management and position sizing like this to be attached to it , please reply to me to change id's or something. All the best ADRIAN http://www.facebook.com/suciu.adrian?ref=ts

    ReplyDelete
  2. Hello Everybody,

    Below is a list of the most recommended FOREX brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 min. deposit.

    Here is a list of the best forex tools:
    1. ForexTrendy - Recommended Odds Software.
    2. EA Builder - Custom Indicators Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    I hope you find these lists helpful...

    ReplyDelete