Leverage Space Demonstrator
Ralph Vince's "Leverage Space Model" (The Mathematics of Money Management, 1992, and later works) defines optimal f as the fraction of the largest historical loss that maximises the geometric growth rate of equity across a set of trade results. It is one of the most cited and least honestly implemented ideas in retail trading writing - most articles quote the formula's existence without ever running it on real numbers. This tool actually runs it: it samples this account's own recent matching closed trades, normalises each one to a per-1.0-lot result (so mixed trade sizes cannot distort which trade counts as the worst loss), and searches for the f in (0,1) that maximises the sum of ln(1 + f * result/worstLoss) using golden-section search - the correct, simple tool for this one-dimensional, provably concave optimisation. The result is shown plainly, including the uncomfortable part: full optimal f is famous for being far too aggressive for real trading, because the model's own optimum implies drawdowns approaching the size of the largest historical loss ALONG THE OPTIMAL PATH, not as a failure mode. This demonstrator does not round that off - it shows the suggested size at full f*, then at the commonly recommended half-f and quarter-f fractions, side by side, so the trade-off between growth rate and drawdown severity is visible rather than asserted. Notes and limitations Optimal f assumes the sampled trade-result distribution repeats going forward and that trades are independent draws from it - real trading satisfies neither assumption exactly: edges drift, and consecutive trades are rarely fully independent. Optimal f is also dominated by a single number, the single worst historical loss - one outlier trade in the sample can swing the suggested size sharply, and a sample too small to have seen a representative worst case will understate the true risk. This tool computes what the model says from the data it is given; it does not validate that the data is representative of the future. Full f* is shown deliberately, not softened, precisely because the honest and famous criticism of optimal f is how aggressive it is - see the half-f and quarter-f lines for the commonly used practical compromise, not as an endorsement that they are "safe" either.
Expert advisor · MT4 · v1.0 · Free
About Leverage Space Demonstrator
Leverage Space Demonstrator is a script for MetaTrader 4. It has 6 settings, such as Lookback trades, Min trades required and Magic filter. MQL source code included.
Files in the download: LeverageSpaceDemonstrator.ex4, LeverageSpaceDemonstrator.mq4, LeverageSpaceDemonstrator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Lookback trades | 50 | Closed trades sampled, most recent first |
| Min trades required | 20 | Minimum sample size (including at least one loss) before f* is shown |
| Magic filter | -1 | Magic number filter (-1 = every magic number) |
| Current symbol only | false | Restrict the sample to this chart's symbol |
| Search iterations | 60 | Golden-section search iterations (60 is far more than the precision needs) |
| Recalc seconds | 30 | Minimum seconds between recalculations |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Risk & Lot Size · MT4 Expert Advisor · MQL4 Source Code