Optimal F by Ralph Vince. Position Sizing and Risk Analysis — Strategy by Smollet

By Smollet

Performance Metrics

Description

Even a profitable strategy can produce weak results when position sizing is poorly calibrated. A position that is too small limits capital growth, while excessive exposure can turn an ordinary losing streak into a severe drawdown. MM: Optimal F analyzes the actual trade results of your strategy and identifies the historical risk level that produced the highest geometric capital growth.The script implements the Optimal F concept developed by Ralph Vince. The method searches for the fraction of capital that maximizes the compounded result of the complete trade sequence, represented by Terminal Wealth Relative, or `G(f)`. Optimal F is not designed to maximize the profit of an individual trade. Its purpose is to optimize the long-term compounded growth of the entire system.How the Script WorksThe strategy must first be tested using a fixed position size of one contract or one unit of the traded instrument.For every closed trade, the script calculates the financial result per contract. It then identifies the largest historical losing trade: Max Loss per ContractEvery trade is normalized relative to this loss: R = Profit per Contract / Max Loss per ContractThe script then tests values of `f` from 0.00 to 1.00 and calculates the following result for each value: G(f) = Π(1 + f × R)A curve showing the relationship between `f` and `G(f)` is displayed on the chart.The script reports four main values:Best F — the value of `f` that produced the highest historical geometric growth.Best G(f) — the maximum theoretical growth multiplier for the analyzed trade sequence.Max Loss — the largest closed loss per contract.Recommended Contracts — the calculated position size based on the current account equity.The number of contracts is calculated using: Contracts = Equity × Selected F / Max Loss per ContractExample:Equity = 100,000Selected F = 0.21Max Loss per Contract = 9,775Contracts = 100,000 × 0.21 / 9,775Contracts = 2.15For futures trading, the result is rounded down: 2 contractsThe table displays the value in the following format: 2 (2.15)The first number is the whole-contract position size. The value in parentheses is the exact calculated position size before rounding.What Optimal F Actually MeansA result such as: Best F = 0.21does not mean that the strategy should enter a position using 21% of account equity as the nominal position value.It means that the position size should be calculated so that a repetition of the largest historical loss per contract would represent approximately 21% of the current account equity.For this reason, Optimal F cannot be replicated by simply setting:Order size = 21% of equityin the TradingView strategy settings.The percentage of equity used as nominal position value and the percentage of equity exposed to the largest historical loss are different measurements.Full F and Fractional FFull Optimal F maximizes historical geometric growth, but it usually produces aggressive position sizing, large equity fluctuations, and deep drawdowns. It does not optimize equity-curve smoothness and does not impose a maximum drawdown limit.Ralph Vince specifically discussed Half F, or 50% of the calculated Optimal F, as an attractive practical compromise. In his example, Half F reduced variability and expected drawdown by approximately half, although more trades were required to reach the same capital objective. He also noted that using a smaller fraction of Optimal F generally produces a smoother equity curve.Example:Best F = 0.21Full F = 0.21Half F = 0.105Quarter F = 0.0525Half F is calculated as:Selected F = Best F × 0.50This should not be treated as a universal rule. Half F is a more conservative starting point that can be compared with Full F and other fractional values.How to Use the Script1. Insert your own strategy code into the designated strategy section.2. Disable: "Enable Optimal F Position Sizing"In this mode, the strategy should be tested using one contract.3. Verify that the following strategy properties are configured correctly:Initial CapitalCommissionSlippageMarginThese parameters directly affect trade results, the largest losing trade, and the calculated Optimal F.4. Run the backtest and record:Best FMax Loss per ContractRecommended Contracts5. Select the fraction of Optimal F that you intend to apply:Full FHalf FQuarter FA more conservative starting point is: Selected F = Best F × 0.506. Enter the selected value into: Optimal F7. Enter the calculated maximum loss per contract into: Max Loss8. Enable: "Enable Optimal F Position Sizing"The strategy will now dynamically recalculate its position size before every new trade using the current account equity.9. For futures trading, enable: Rounds contracts numberThe calculated position size will be rounded down to a whole number of contracts. When the calculated size is below one contract, the strategy will continue trading one contract.Important LimitationsOptimal F is calculated from historical trades. A future loss may exceed the largest loss observed in the backtest.Full Optimal F often creates excessive exposure. Results should therefore be evaluated using more than Net Profit alone. Important metrics include:Maximum DrawdownRecovery FactorEquity Curve StabilityLargest Losing TradeMaximum Losing StreakFor a more objective evaluation, calculate Optimal F on one section of historical data and apply the fixed values to a separate out-of-sample period.Insert your own strategy into MM: Optimal F, run the analysis using one contract, and determine the level of risk that is actually supported by the historical structure of your strategy’s profits and losses.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView