Skip to content

Feature

Strategy Optimizer: Sweep, Holdout, Walk-Forward

TradingLead's Strategy Optimizer tests up to 12 parameter combinations of a completed Python or Pine backtest on the same frozen candles. It supports a full-period sweep, a train-test holdout and walk-forward analysis with 1-5 folds, selecting by training net P&L or lowest drawdown. It is built to expose overfitting, not to promise a best setting.

What it does

The Strategy Optimizer answers a practical question: if I change this input, does my strategy still work, or did I just get lucky with one setting? It takes a completed backtest and evaluates a small grid of parameter combinations on exactly the same frozen candles, so every candidate is compared fairly.

It works for both Python strategies (declared parameters the code actually reads) and TLScript-Pine strategy() scripts (declared input variables). It is designed around honest evaluation: separate training and testing windows, explicit constraints and visible warnings when a result is in-sample only.

How it works

The optimizer lives in the Optimize view of a completed run in the Backtesting panel. You choose one of three modes:

ModeWhat happensWhen to use
Full-period optimization (sweep)Every candidate runs on all frozen candles. No forced test.Quick sensitivity check. Selection is in-sample and can overfit.
Train-test split (holdout)Candidates are ranked on a training window; only the winner runs once on a later held-out window.A simple out-of-sample check.
Walk-forward1–5 rolling folds. Each fold trains, picks a winner and tests it on the next unseen window.Checking whether a tuning process holds up over time.

You pick the objective, either highest training net P&L or lowest training max drawdown. Optionally, set a minimum number of completed positions and a maximum drawdown (in account currency). Constraints use training data only. If no candidate qualifies, nothing is selected and the test is shown as skipped. It is never filled in with a fake success.

Each scored segment starts flat with the original capital. Warmup can be a cold start inside each segment or, explicitly, use preceding unscored candles to prime indicators.

Key capabilities

  • Python and Pine parameter grids, validated against declared types, bounds and options.
  • Grid entry as explicit values or numeric From/To/Step ranges, including decimals and negative steps.
  • Bounded workload: up to 12 combinations across up to 4 parameters, 1–5 folds and 65 evaluations, so runs finish in a predictable time.
  • Sampled search: a repeatable, seeded sample of up to 12 combinations from a larger space (up to 1,000 values per parameter).
  • Preview before running: exact candle offsets, dates, unused tail and evaluation count, without executing code.
  • Estimate time: optionally measure one real candidate to get a rough runtime estimate with low/high range.
  • Extra robustness checks (where available): neighbouring-parameter and higher-cost checks on the selected candidate, and independent runs on other symbols you choose.
  • Confirmed rerun: create a separate backtest of the selected parameters on the full original sample, clearly labelled as reused data.
  • Detailed HTML report: every evaluation, equity and drawdown charts, exit legs, frozen settings and source, viewable in-app or exported as a self-contained file.

How to use it

  1. Run a backtest to completion (see Backtest a strategy).
  2. Open the run's Optimize view.
  3. Choose a mode. Prefer Train-test split or Walk-forward if you plan to trust the result.
  4. Add 1–4 parameters with their candidate values, and set train/test lengths if needed.
  5. Check the preview, then click Start optimization.
  6. Compare training and held-out results fold by fold. Prefer settings whose neighbours also perform reasonably (a plateau) over a single sharp peak.
  7. Optionally Generate detailed report and Export HTML to keep a copy.

Avoiding overfitting

Optimization makes it easy to fit noise. Good practice inside TradingLead:

  • Treat full-period sweep results as in-sample: useful for sensitivity, not proof.
  • Use holdout or walk-forward analysis and look at the unseen windows.
  • Require a minimum number of completed positions so a near-inactive strategy can't "win" on low drawdown.
  • Re-check with higher costs and on other symbols.
  • The Backtesting Lab lesson Can you trust this result? walks through these ideas interactively.

Limitations

  • The search is deliberately small (12 combinations per run); it is not a genetic or exhaustive optimizer.
  • Objectives are limited to net P&L or drawdown on the training window.
  • Walk-forward folds don't carry a continuous portfolio, and later training windows may include earlier test candles.
  • A confirmed rerun of the selected parameters reuses held-out candles. It is not new out-of-sample evidence.
  • All results are simulations on past data with modelled fills and costs. They are not investment advice or a forecast.

Access

The optimizer is part of the Backtesting panel in the main TradingLead workspace (5-day free trial, then subscription; see pricing).

Steps

  1. Run a backtest to completion on the Backtesting tab.
  2. Open the Optimize view for that run.
  3. Choose Full-period optimization, Train-test split (holdout) or Walk-forward.
  4. Enter parameter values (explicit list or From/To/Step) and preview the windows.
  5. Click Start optimization and review training versus held-out results.

Limitations

  • Bounded search: at most 12 candidate combinations, 4 parameters, 5 folds and 65 evaluations per optimization.
  • Full-period sweep selects in-sample and can overfit; it has no forced out-of-sample test.
  • Walk-forward folds are independently initialized; a portfolio is not carried continuously across folds, and later training windows can include earlier test candles.
  • Objectives are limited to training net P&L or lowest training drawdown.
  • Rerunning the selected parameters on the full sample reuses held-out candles and is not new out-of-sample evidence.
  • Simulations only; no live orders and no guarantee of future performance.

Frequently asked questions

Does TradingLead support walk-forward optimization?
Yes. The Strategy Optimizer has a walk-forward mode with 1 to 5 rolling train/test folds. Each fold picks parameters on its training window and then tests the pick on the following unseen window. Every segment starts flat with the original capital.
How many parameter combinations can I test?
Up to 12 combinations across at most 4 parameters per optimization, and at most 65 segment evaluations in total. A sampled-search option can pick up to 12 combinations from a larger value space using a fixed seed.
Can I optimize a Pine Script strategy?
Yes. Pine strategy() runs can be optimized over their declared input variables. Each candidate runs in the Pine emulator with the original frozen execution settings. Results are not TradingView-equivalent.
Will the optimizer find the best settings for my strategy?
It finds the best of the combinations you entered by the training objective you chose. A best in-sample result can be overfit. Use holdout or walk-forward results, neighbour checks and other symbols before trusting it, and remember that past results don't guarantee future returns.
Does optimization fetch new data?
No. It reuses the candles, source and settings frozen in the original completed backtest, so every candidate is compared on identical data.

Last updated: