Discussing the article: "Adaptive Position Sizing in MQL5: A Prototype Risk Engine with Generalized Kelly and Bootstrap Calibration"

 

Check out the new article: Adaptive Position Sizing in MQL5: A Prototype Risk Engine with Generalized Kelly and Bootstrap Calibration.

This article presents a modular position sizing engine for MetaTrader 5 that operates on normalized R-multiples. A layered pipeline combines enriched trade statistics, a generalized Kelly edge estimate, volatility-aware adjustment, Monte Carlo calibration under ruin and drawdown limits, a continuous risk policy, an exposure guard, and a broker-aware lot calculator. The output is a broker-valid lot size with an optional CSV audit trail, providing a transparent prototype for implementing modern risk controls in native MQL5.

A typical Expert Advisor risks a fixed percentage of the account on every trade. This one-line rule ignores the strategy's statistical edge and current volatility. It also ignores drawdown paths that may not appear in a single historical backtest. As long as the strategy performs normally, a 1% fixed risk may be acceptable. During a deep drawdown, unusually volatile conditions, or a weak historical edge, that fixed percentage can be far too aggressive. Volatility inflates stops, a series of losses eats away at the safety margin, and the strategy's statistical advantage turns out to be weaker than it appeared in a single backtest.

The problem is not that 1% is too much or too little. The problem is that the position size is not based on the distribution of strategy outcomes and is not controlled by the probability of ruin or tail drawdowns. What is needed is a module separate from the signal logic that accepts normalized trade results in R-multiples and produces a risk fraction and lot size that shrink automatically in poor trading regimes and never exceed configured drawdown and ruin limits.

The engine described here replaces that fixed percentage with a layered, adaptive decision process. It works with R-multiples, defined as each trade's profit or loss divided by its initial monetary risk, so that all outcomes become comparable regardless of account size. From those normalized outcomes, the engine:

  • Computes enriched trade statistics, including distribution moments and tail metrics.
  • Estimates a growth-optimal fraction (generalized Kelly) directly from the empirical R distribution.
  • Adjusts the fraction using a volatility regime multiplier and a continuous performance‑degradation model.
  • Runs an iterative bootstrap Monte Carlo calibration that finds the maximum risk fraction satisfying user‑defined limits on ruin probability and drawdown.
  • It applies a final safety layer of absolute exposure limits.
  • Outputs a broker-valid lot size and an optional CSV audit trail.

The project is presented as a research prototype: a complete, executable blueprint that shows how to combine these techniques in MQL5. It is not a turnkey institutional risk engine. Its limitations are documented, and every module can be extended or replaced.


Author: Stanley Kimathi Kibaara