The article presents a position sizing engine for MQL5 Expert Advisors that separates risk policy from lot conversion. Four models—fixed fractional, fixed monetary, ATR-based volatility scaling, and equity-curve scaling—share a CLotConverter that uses OrderCalcProfit() to measure real money per point. A unified CPositionSizer interface exposes CalculateLots(), making model changes straightforward while producing broker-compliant volumes across symbols.
Two different questions hide inside "what lot size should I use":
How much am I willing to lose if the stop is hit? This is a policy question. A percentage of balance, a flat dollar figure, a number that shrinks during a drawdown. It has nothing to do with the symbol being traded.
Given that dollar figure and a stop distance, what lot size produces it? This is a conversion question. It depends entirely on the symbol's tick value, tick size, contract size, and volume constraints.
Mixing these two ideas is exactly what makes sizing code fragile. A formula like balance * risk_pct / 100 / stop_points / 10.0 assumes a flat $10 per point value baked directly into the risk logic. That assumption holds for a handful of USD forex pairs and breaks on everything else. Switch the symbol to an index or a metal and the formula is simply wrong, even though the risk policy itself, "risk 1% per trade," never changed.
This engine keeps the two apart. Each risk model computes a risk_amount and hands it, along with a stop distance, to one shared CLotConverter. The converter's only job is turning that pair of numbers into a lot size the broker will accept. Adding a fifth model later means writing a small class that produces a risk_amount. The conversion math never needs touching.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Check out the new article: Building a Position Sizing Engine in MQL5 with Multiple Risk Models.
The article presents a position sizing engine for MQL5 Expert Advisors that separates risk policy from lot conversion. Four models—fixed fractional, fixed monetary, ATR-based volatility scaling, and equity-curve scaling—share a CLotConverter that uses OrderCalcProfit() to measure real money per point. A unified CPositionSizer interface exposes CalculateLots(), making model changes straightforward while producing broker-compliant volumes across symbols.
Two different questions hide inside "what lot size should I use":
Mixing these two ideas is exactly what makes sizing code fragile. A formula like balance * risk_pct / 100 / stop_points / 10.0 assumes a flat $10 per point value baked directly into the risk logic. That assumption holds for a handful of USD forex pairs and breaks on everything else. Switch the symbol to an index or a metal and the formula is simply wrong, even though the risk policy itself, "risk 1% per trade," never changed.
This engine keeps the two apart. Each risk model computes a risk_amount and hands it, along with a stop distance, to one shared CLotConverter. The converter's only job is turning that pair of numbers into a lot size the broker will accept. Adding a fifth model later means writing a small class that produces a risk_amount. The conversion math never needs touching.
Author: Ushana Kevin Iorkumbul