DocsRun Modes

Optimization

Optimization tests every combination of parameter values to find the set that scores highest on a chosen metric. It runs a full backtest for each combination (grid search).

How It Works

  1. For each parameter marked optimize: true, a range of values is generated from its min, max, and step
  2. The Cartesian product of all ranges produces the full grid of combinations
  3. Each combination runs a complete backtest
  4. Results are ranked by the optimization target metric
  5. The best-scoring combination is returned along with all results

Grid Size

The total number of combinations is the product of step counts:

fastLength:  min=5,  max=25, step=5  → 5 values  (5, 10, 15, 20, 25)
slowLength:  min=20, max=60, step=10 → 5 values  (20, 30, 40, 50, 60)
rsiPeriod:   min=7,  max=21, step=7  → 3 values  (7, 14, 21)

Total combinations = 5 x 5 x 3 = 75 backtests

Limit: The maximum grid size is 50,000 combinations. If your ranges produce more, reduce the number of parameters or increase the step sizes.

Optimization Targets

TargetWhat It Maximises
Sharpe Ratio (default)Risk-adjusted return
Total ReturnPercentage return on capital
Total ProfitAbsolute profit amount
Win RatePercentage of winning trades
Profit FactorGross profit / gross loss
Calmar RatioReturn / max drawdown
Max DrawdownMinimises maximum drawdown
CompositeBlended: 40% Sharpe + 30% win rate + 30% profit factor
AllReturns the best result for each major metric

Fixed Capital

Optimization always uses fixed (non-compounding) capital for each backtest. This prevents early-period results from snowballing via compound growth, which would bias the parameter search toward strategies that got lucky early.

Execution Modes

ModeBehaviour
SynchronousBlocks until complete — good for small grids
AsynchronousReturns a job ID immediately; progress is streamed via SSE (Server-Sent Events)

Large optimizations automatically run asynchronously. You can monitor progress in real time and the results are saved for 7 days.

Tips

  • Start with coarse steps (large step sizes) to explore broadly, then refine with finer steps around the best region
  • Use Sharpe Ratio as the default target — it balances return and risk
  • If you see the best result at a boundary (min or max), extend the range
  • Watch out for overfitting: a perfect-looking result on one date range may not generalize. Use Walk-Forward Analysis to validate.
  • Keep the grid under 5,000 combinations for fast iteration; save larger grids for final validation
optimizationgrid searchparameter tuningsharpetargetcombinations