Loading…

Drawdown Throttled Risk Scaler

Most risk management code uses one fixed percentage of equity per trade, chosen once and left alone regardless of how the account is actually performing. That is backwards for anyone serious about capital preservation: risk should shrink automatically while an account is in a losing stretch, and only come back once there is real evidence the stretch is over. This library is that automatic shrink-and-restore mechanism, built as a configurable ladder rather than one hardcoded rule. DrtAddLadderStep builds the ladder - as many drawdown%->multiplier steps as wanted, for example 5% drawdown cuts risk to 75%, 10% cuts to 50%, 15% cuts to 25%. DrtUpdate is called with current equity on every tick or bar; it tracks the running peak, computes the current drawdown percentage, and applies the deepest step that has been reached. Cutting and restoring are deliberately not symmetric. Cutting happens the instant equity crosses a step - no delay, because reacting fast to a fresh losing stretch is the entire point of a throttle. Restoring is different: a cut is only lifted once drawdown has recovered past that step's trigger by an extra, configurable recoveryBufferPercent margin. Without that margin, equity sitting almost exactly on a boundary - a few points either side of the 10% line, say - would flip the risk multiplier up and down on every tick that crosses it, which is exactly the kind of noisy behaviour a drawdown throttle exists to prevent, not cause. The buffer can be set to 0.0 for simple symmetric behaviour if that noise is not a concern for a given account. The lot-sizing helpers (DrtCalculateLots, DrtRiskMoney, DrtMoneyPerPoint) all derive money-per-point from the broker's own reported tick value and tick size rather than assuming a contract size - a 100,000-unit forex lot is not the same as a gold or index contract, and hardcoding that number is a documented, repeated way risk code silently miscalculates on the wrong instrument. On MQL4 that reads MarketInfo(symbol, MODE_TICKVALUE) and MODE_TICKSIZE; on MQL5 the same read is SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE) and SYMBOL_TRADE_TICK_SIZE - genuinely equivalent broker-reported figures, not an approximation, and both versions scale the result by the actual lot size passed in rather than assuming 1.0 lots. Notes and limitations - DrtAddLadderStep enforces strictly increasing trigger order; add steps from shallowest to deepest drawdown, one call per step. - Peak equity only ever increases inside the throttle's own state - it is not read from account history, so DrtInit's startingEquity should be a realistic current or recent peak, not an arbitrarily low number that would make every future equity value look like a new high. - This library computes a risk multiplier and, optionally, a matching lot size; it does not open, close or modify any order or position itself. Feed its output into your own OrderSend call (MQL4) or CTrade/OrderSend request (MQL5). - Money figures assume the account currency matches the broker's reported tick value currency, the same assumption the underlying MarketInfo/ SymbolInfoDouble call itself makes on either platform; a cross-currency account still needs its own conversion step. - The recovery buffer is a single value applied to every ladder step uniformly; a per-step buffer is out of scope for this library.

Script · MT4 · v1.0 · Free

About Drawdown Throttled Risk Scaler

Drawdown Throttled Risk Scaler is a script for MetaTrader 4. It has 4 settings, such as Starting equity, Base risk percent and Stop loss points. MQL source code included.

Files in the download: DrawdownRiskThrottle.mqh, DrawdownRiskThrottle.txt, DrawdownRiskThrottleDemo.mq4.

Settings

SettingDefaultWhat it does
Starting equity10000.0Simulated starting account equity
Base risk percent2.0Base per-trade risk before throttling, percent of equity
Stop loss points300Simulated stop distance for the lot-size example, in points
Recovery buffer percent1.0Extra drawdown-percent recovery required before a cut lifts

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Risk & Lot Size · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria