Algorithmic and Mechanical Forex Strategies | OneStepRemoved

  • Articles
  • Sophisticated Web Sites
  • Automated Trading
  • Testimonials
  • Contact

Common Money Management Formulas

August 10, 2011 by Shaun Overton 25 Comments

All of the EAs that we program generally use one of three types of money management. I don’t really like that term, though. I believe that position sizing formula is generally more accurate.

The options are:

  • Fixed Lot Size
  • Use a percentage of available margin
  • Lose a certain percentage of the account balance whenever the stop loss is hit.

Most MetaTrader users are accustomed to using fixed lots in their forex money management. It’s far and away the most common method found in commercial EAs. If you’ve watched any of the videos on this site or spoken with me, you know that I generally have a low opinion of most commercial EAs. Just because everyone does it does not mean that it’s a good idea!

Whenever a customer order mentions the idea of using a Risk input to control the lot size for their money management, it typically means to use a selected percentage of the available margin. Say, for example, that you trade a $10,000 account on 1% margin (100:1 leverage) and want to use 2% of available margin on any given trade. If you have no open positions, then the margin to use is $10,000 * 2% = $200.

The lot size is the outcome of the following formula:
Lots = Margin to Use / Margin Required per standard lot

Going back to our example, you simply plug in the numbers:
$200 / $1000 per standard lot (100:1 margin) = 0.2 lots, which is 2 mini lots.

The MQL4 code for this is
double lots = (AccountFreeMargin() * Risk) / MarketInfo( Symbol(), MODE_MARGINREQUIRED);

The advantage to this method is that the lot size remains consistent barring a dramatic change in available margin. I don’t actually see that as an advantage, but many traders like seeing the same lot size on most trades.

The disadvantages are numerous. If you like to trade on high leverage and trade many different instruments, you can easily get yourself into a margin call. If your strategy calls for placing a stop based on price action, the amount lost will vary depending on where the stop is placed. Some trades might lose $20 while others lose $100.

double lots = Risk * AccountEquity() / MarketInfo(Symbol(), MODE_TICKVALUE) / Stop;

My favorite forex money management method is to select my lot size based on the equity loss if my stop is hit. If I risk 0.5% on a $10,000 account and my stop loss is 20 pips away, then desired lot size is
lots = 0.5% * $10,000 / $10 per tick per standard lot / 20 pips = 0.25 lots, or 2.5 mini lots

The lot size decreases whenever the stop loss distance increases, and vice versa. A 60 pip stop loss would require a lot size of
lots = 0.5% * $10,000 / $10 per tick per standard lot / 60 pips = 0.083 lots, or 0.8 micro lots after accounting for rounding.

The varying lot size drives most traders crazy. I believe such rationale ignores the logic of trading. Trading is a statistical outcome, a distribution of events that theoretically returns a net result greater than zero. We call this profit in daily life.

If your trading system is x% accurate and you know the profit factor is greater than 1, why on earth a trader would haphazardly bet different dollars amount on every trade is beyond me. The effect is no different than randomly choosing to bet $10 on this trade and $100 on the next. The random, system-less money management of choosing position sizes for your trading system would overwhelm the nice, even distribution that you’re expecting from the signals.

Filed Under: NinjaTrader Tips, Trading strategy ideas

Comments

  1. mperk says

    January 13, 2013 at 21:06

    Hello,

    The problem I have is that I need to calculate lot size based on a set percentage of USED MARGIN. The reason being that I trade 12 currency pairs with a recovery system. I’m having a difficult time working backwards, for some reason.With the following inputs how is Lot Size calculated based on a set percentage of USED MARGIN:
    Standard lot = 100,000
    Leverage = 50
    Account Equity = $10,000
    Used Margin Risk max per trade = 5% = $500
    AUDUSD = $10.00
    Stop Loss = 20 pips = $200
    Lot Size = ???

    Thanks

    Reply
    • Shaun Overton says

      January 14, 2013 at 13:50

      Thank you for the question. The lot size is
      used margin * leverage

      $500 * 50 = 25,000 units, or 2.5 mini lots (0.25 lots in MetaTrader’s standard notation).

      Reply
  2. swiz says

    March 14, 2013 at 09:09

    hi,
    can you write MM like this:
    Risk=5 means stop loss = 5% of account balance

    thank you

    Reply
    • Shaun Overton says

      March 17, 2013 at 20:27

      Hi swiz,

      Yes, this is possible to do. Are you asking me something specific? I get the feeling that maybe I didn’t understand you correctly.

      Reply
  3. Milton Pang says

    July 1, 2014 at 17:49

    do you recall John Burch from forex-tools-cafe.com? He created trademan v4 which looked for the past highest high and low and set those as sl and trade position size to give the amount of lots for the trade. I think he might of passed on but his website still exists and the software sells for a cool $18 dollars.
    BTW your enthusiasm for what you do rather infectious.
    Milt

    Reply
    • Shaun Overton says

      July 1, 2014 at 19:50

      Thanks, Milton!

      Reply
  4. Thomas Ng says

    January 28, 2015 at 05:07

    Talking about this line: “My favorite forex money management method is to select my lot size based on the equity loss if my stop is hit.” How would you describe it in MQL4 though?

    Thanks Shaun….hope you don’t mind to share the code

    PS you got a good EA there but it is very unfortunate you only open a MAM or PAMM account

    Reply
    • Shaun Overton says

      January 28, 2015 at 11:49

      Thanks, Thomas. The code is already in the middle of the article in a different font. Please look again.

      Reply
  5. David says

    January 4, 2016 at 22:31

    hi Shaun,
    I’m trying to figure out how to calculate below figures with a ratio of $500:0.01micro lot
    Account Balance = $500
    Leverage = 200
    Risk % = 10
    can you please give me a formula with every $500 increase, lot size increase by 0.01 micro lot?

    Reply
    • Shaun Overton says

      January 6, 2016 at 09:03

      Hi David,

      Thanks for asking. You’re making it more complicated than it needs to be. Leverage and risk are extraneous variables for the equation that you’ve proposed.

      The formula is:
      $500 (account equity) * 0.01 lots / $500 = 0.01 lots.

      If your account equity grew to $1,200, the formula gives you:
      $1,200 * 0.01 lots / $500 = 0.02 lots (I rounded down).

      I hope that helps.

      Reply
  6. MOHAMMED says

    January 15, 2016 at 12:07

    Well is educative

    Reply
    • Shaun Overton says

      January 18, 2016 at 11:51

      I’m glad you learned something.

      Reply
  7. Sam Trinston says

    January 15, 2016 at 13:57

    Your formula (and weakness in MT4) is that one alwats needs to calculate LOTS – which doesn’t help when trading a multi-instrument portfolio. For example 1 lot of EURUSD isn’t the same as 1 lot of GBPJPY – that is, they expose different quantities of USD$ to the market. So if you are looking to create a system that ensures you expose USD$x then the formula becomes a lot more complex

    Reply
    • Shaun Overton says

      January 18, 2016 at 11:50

      Actually, that’s not the true. The formulae provided use MarketInfo, which returns the values in terms of the account currency. It already compensates for multiple instruments and currencies.

      Reply
  8. regani says

    January 20, 2016 at 01:22

    thankq .. more use ful infomormation.. use full to me thankqs

    Reply
    • Shaun Overton says

      January 22, 2016 at 09:48

      I appreciate you letting me know. It’s feedback like that that keeps me going.

      Reply
  9. Andrea says

    January 10, 2017 at 12:22

    i try your formula
    lots = 0.5% * $10,000 / $10 per tick per standard lot / 20 pips = 0.25 lots, or 2.5 mini lots

    but if i calculate it

    0.5*10.000/10/20 = 25 not 0.25
    it’s wrong, how i can correct?

    Reply
    • Shaun Overton says

      January 10, 2017 at 12:45

      0.5% needs to be 0.005.

      Reply
  10. Philipp says

    March 16, 2017 at 07:06

    Hallo Herr Shaun Overton,

    ich habe auch ein Problem. Vielleicht könnten sie mir beim Code helfen:

    Gehandelt wird auf der Dax.

    Long Trade: 3% Risiko pro Trade – Position sollte auf 0,10lot auf / abgerundet werden. SL ist -15Pips
    Short Trade: 4% Risiko pro Trade – Position sollte auf 0,10lot auf / abgerundet werden. SL ist -20 Pips.

    Danke für Ihre Hilfe!

    Reply
    • Shaun Overton says

      March 23, 2017 at 13:04

      Make sure that your stop loss is a positive number. You wrote a negative number in your post.

      The formulas should work on the DAX or any instrument. It’s not FX specific.

      Reply
  11. Andrew Coles says

    June 24, 2017 at 10:45

    It is often easier to specify Stop Loss as a Rate difference, i.e. from the current Ask or Bid Rate to a Support or Resistance Level respectively, rather than in Pips. This is typically how an EA would form the Stop Loss Value, or alternatively as some (sub one) multiple of Average True Range.

    Here is a minimal EA, to demonstrate Lot size Calculation. It includes normalization of the raw Lot size formed into Lot Step sizes the Server will accept, within minimum and maximum Lot sizes also.

    Example Balance Risk and Stop Loss are provided as input Statements, for ease:

    #property strict

    input double StopLossRate = 0.00500; // Stop Loss with 50 Pips (Non JPY)
    input double Balance_Risk = 0.012; // 1.2% of Account Balance risked

    //+——————————————————————+
    //| Expert initialization function |
    //+——————————————————————+
    void OnInit()
    {
    double tickVal;
    double powTerm;
    double rawLots;
    double stpLots;
    double lotSize;
    double maxLots;

    tickVal = MarketInfo (NULL, MODE_TICKVALUE);
    Print (“TICKVALUE = “, tickVal);

    rawLots = (Balance_Risk * AccountEquity() * Point) / (tickVal * StopLossRate);
    Print (“rawLots = “, rawLots);

    stpLots = MarketInfo (NULL, MODE_LOTSTEP);
    lotSize = stpLots * NormalizeDouble (rawLots / stpLots, 0);
    Print (“Normalized lotSize = “, lotSize);

    if (lotSize maxLots)
    {
    lotSize = maxLots;
    }
    }

    Print (“Trade lotSize = “, lotSize);
    }

    //+——————————————————————+
    //| Expert deinitialization function |
    //+——————————————————————+
    void OnDeinit(const int reason)
    {
    //—

    }
    //+——————————————————————+
    //| Expert tick function |
    //+——————————————————————+
    void OnTick()
    {
    //—

    Reply
    • Shaun Overton says

      June 26, 2017 at 07:04

      Thanks for adding this!

      Reply
  12. Andrew Coles says

    June 24, 2017 at 11:20

    [Private Note]

    It seems as though the .LT. sign on the minimum Lot Size stripped out some of the submitted code.

    It might be easier to send you the MQ4 File, if you think it might be helpful to post, or expand your already very helpful Page.

    The “powTerm” Variable can be removed. This was just a Test-bed for an EA written, that runs on M15 Time Frame. Very challenging to get into profit. I wanted a lot of Trades, for rapid Equity growth.

    I had considerable problems getting the MT4 Back-tester to work. Eventually achieved a Profit Factor of 1.29 over a 7 Month Back-test with a few combinations of Parameters.

    I could not get a Break Even Stop Loss to work in the Back-test EA Version. The operational EA is radically differently coded (written for real-time, with fault tolerance).

    Expect to go Live shortly, if forward Demo Test is consistent with the Back-test Results. Currently migrating the Entry Filters proven in the Back-test EA, into the Operational EA. The latter has already run (with minor Bugs), at a small loss on Demo.

    Reply
    • Calvin says

      December 31, 2018 at 05:22

      Please do share your code snippet. Thanks!

      Reply
  13. Ilan Tree says

    July 2, 2017 at 12:27

    I added a post in my recent blog discussing some useful MQl4 functions when verifying and calculating lot size based on currency and risk parameters – http://www.ilantree.com/useful-mql4-lot-size-functions/, happy to exchange ideas with you.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

FREE trading strategies by email

Trending

Sorry. No data so far.

Archives

  • Dominari
  • How does the forex market work?
  • Indicators
  • MetaTrader Tips
  • MQL (for nerds)
  • NinjaTrader Tips
  • Pilum
  • QB Pro
  • Stop losing money
  • Test your concepts historically
  • Trading strategy ideas
  • Uncategorized
  • What's happening in the current markets?

Translation


Free Trading Strategies

Privacy PolicyRisk Disclosure

Copyright © 2023 OneStepRemoved.com, Inc. All Rights Reserved.