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
- For each parameter marked
optimize: true, a range of values is generated from itsmin,max, andstep - The Cartesian product of all ranges produces the full grid of combinations
- Each combination runs a complete backtest
- Results are ranked by the optimization target metric
- 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
| Target | What It Maximises |
|---|---|
| Sharpe Ratio (default) | Risk-adjusted return |
| Total Return | Percentage return on capital |
| Total Profit | Absolute profit amount |
| Win Rate | Percentage of winning trades |
| Profit Factor | Gross profit / gross loss |
| Calmar Ratio | Return / max drawdown |
| Max Drawdown | Minimises maximum drawdown |
| Composite | Blended: 40% Sharpe + 30% win rate + 30% profit factor |
| All | Returns 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
| Mode | Behaviour |
|---|---|
| Synchronous | Blocks until complete — good for small grids |
| Asynchronous | Returns 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