Loading…

Optimal F Sizing Demonstrator

Optimal f is the fraction of the largest historical loss that maximises the geometric growth rate of a fixed sequence of trades. It is a real, well defined number, and it is also - by Vince's own writing - a figure whose drawdown most real accounts cannot survive. A sizing demonstrator that shows only the "optimal" number without that context is not honest about what it produced. This EA collects the most recent closed trades from account history, normalises each one's profit to a single lot using OrderProfit() divided by OrderLots(), and brute-force searches f across its full range for the value that maximises terminal wealth relative (TWR) over that trade series - the exact method from Vince's own books, which has no closed-form solution and is always found this way. It then reports two lot sizes for the current chart symbol: the full optimal f figure, and a fractional f figure at a configurable fraction of it, because fractional f is what Vince's later writing actually recommends anyone trade. Money per point for the lot conversion is read live from MODE_TICKVALUE and MODE_TICKSIZE for the current symbol, scaled against the historical biggest loss per lot - never a hardcoded contract size, since that would silently misprice the recommendation for anything other than a standard forex lot. Notes and limitations Read-only demonstrator - it never places, modifies or closes an order. Optimal f is undefined without at least one losing trade in the lookback window and is shown as such. Past trades are not a guarantee of the same biggest loss recurring; a new worst loss after this EA calculates will invalidate the figure until the next closed trade is included. The full optimal f lot size is explicitly a teaching figure - trading it live is what the method's own author warned against. The MQL5 version assumes each closed position produced exactly one exit deal (no partial closes splitting a trade's profit across several exit deals); a position closed in several pieces is read as several separate "trades" by the deal scan, which is a reasonable approximation for this teaching tool but not an exact match to MQL4's one-record-per-order model in that specific case.

Expert advisor · MT5 · v1.0 · Free

About Optimal F Sizing Demonstrator

Optimal F Sizing Demonstrator is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Lookback trades, Magic filter and Current symbol only. MQL source code included.

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

Settings

SettingDefaultWhat it does
Lookback trades100Closed trades (most recent first) included in the optimal f search
Magic filter-1Restrict history to this magic number (-1 = every magic number)
Current symbol onlyfalseRestrict history to this chart's symbol
F test step0.01Resolution of the f search between 0.01 and 0.99
Fraction of optimal0.25Fractional f shown alongside full f - Vince's own guidance is well under 1.0
Recalc seconds30Seconds between recalculations

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

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

Expert advisors (EA) for MT4 & MT5 · PolyMaria