Loading…

Drawdown Scaled Position Sizer

Fixed-fractional sizing risks a constant percentage of equity per trade, but a constant percentage of a shrinking account is still a shrinking risk in absolute terms only - it does nothing to slow the RATE of risk-taking during a losing streak. This EA adds a second layer: the risk percentage itself is scaled down as the account's drawdown from its own all-time equity peak deepens, so position size falls faster than equity alone would explain, and is restored to full size the instant a new equity peak is made - which needs no special handling, because the scale factor is a pure function of the CURRENT drawdown reading rather than a remembered "reduced" state that has to be reset. The scale factor is 1.0 with no drawdown and falls in a straight line to a configurable floor at a configurable maximum drawdown percentage, never going lower. The risk-money figure that comes out of equity times risk percent times scale factor is converted to a lot size through the symbol's tick value and tick size, never a hardcoded contract size - this is what keeps the formula correct on metals, indices and JPY crosses exactly as it is on a standard forex lot, and what makes the resulting lot size scale properly with the risk money behind it rather than drifting off by a fixed ratio. The entry signal is a plain fast/slow EMA crossover, deliberately unremarkable, because the point of this EA is the sizing formula, not the signal. Notes and limitations - The equity peak is initialised to the account's equity at the moment the EA is attached, not to any earlier historical high - reattaching the EA after a drawdown resets the reference point. - Sizing is based on equity, which includes floating profit and loss from any other open position on the account, not only this EA's own trades - on an account running several EAs, size the risk percentage and drawdown thresholds accordingly. - The scale factor falls linearly between 0% and InpMaxDrawdownPercent drawdown; it is not a curve tuned to any particular risk-of-ruin target, only a straightforward proportional reduction. - The entry signal has no claimed edge; it exists only to generate trades for the sizing formula to size. - Requires AutoTrading enabled and trading permitted at the terminal, account and program level (IsTradeAllowed() on MQL4; the three TERMINAL_TRADE_ALLOWED / ACCOUNT_TRADE_ALLOWED / ACCOUNT_TRADE_EXPERT checks on MQL5). - On MQL5 netting, this EA refuses a new entry outright if a foreign- magic position already sits on the symbol, rather than risk merging into it.

Expert advisor · MT5 · v1.0 · Free

About Drawdown Scaled Position Sizer

Drawdown Scaled Position Sizer is an expert advisor (trading robot) for MetaTrader 5 based on Moving Average. It can size trades from your balance and risk percent. It has 11 settings, such as Base risk percent, Max drawdown percent and Min scale factor. MQL source code included.

Files in the download: DrawdownScaledSizer.ex5, DrawdownScaledSizer.mq5, DrawdownScaledSizer.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Base risk percent1.0Risk per trade at a NEW equity high, % of current equity
Max drawdown percent20.0Drawdown % at which sizing bottoms out at InpMinScaleFactor
Min scale factor0.20Floor on the sizing scale factor once InpMaxDrawdownPercent is reached
Fast ma period10Fast EMA period for the placeholder signal
Slow ma period30Slow EMA period for the placeholder signal
Stop loss pips30Stop loss per trade, in pips - also the risk unit the sizing is based on
Take profit pips45Take profit per trade, in pips (0 = none)
Magic number20260836Magic number for orders opened by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per trade action before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Risk & Lot Size · Moving Average · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria