← Algo & Backtesting

Parameter sweeps: testing variants of one strategy honestly

Is a 30% stop better than 25% or 40%? Saving five near-identical copies of a strategy to find out leaves you with five strategies to maintain. A sweep runs variants of one strategy head-to-head over the same dates and lets you apply the winner to the original — and it makes overfitting very easy, so this post covers that too.

What a sweep is

A sweep is several backtests of the same strategy, each with one or more settings changed, run over identical dates and friction so the only difference is the setting.

Each changed combination is saved as a named variant — "SL 50", or "SL 50 + rebal 70". A variant is not a copy of the strategy. It stores only the changes, so it keeps applying cleanly after you edit the base strategy, and you can re-run the same comparison later on a different date range.

What you can vary

The sweep panel shows only the sections your strategy actually uses, with the same controls as the Builder, so a variant is always something the Builder could have saved:

If a strategy has neither, the panel says there is nothing to vary. Sweeps are available in single-strategy mode only; a portfolio has no single set of parameters to vary. An entry signal file or chart script, if you add one, applies identically to the original and every variant.

Parameter sweep ticked on the Backtest page: the strategy's adjustment rule and guards as editable fields, with the Original baseline run.
Parameter sweep ticked on the Backtest page: the strategy's adjustment rule and guards as editable fields, with the Original baseline run.

How results are shown, and what Use this does

The original always runs as the baseline. A sweep holds up to 20 variants plus the original, because each one is a full replay.

ColumnMeaning
Run / ChangesThe variant name and a plain summary such as "Leg 1 SL: 30 → 50".
Total P&LNet result over the range. Rows are sorted best first, and the top one is flagged.
vs originalHow far that variant is above or below what you already trade.
Win rate, Max DD, TradesEnough to see whether a higher P&L came with a deeper hole.

Every run is also saved to Backtest History under the strategy name with the variant label, and Report opens its full report. Use this writes that variant's settings into the saved strategy itself — no copy is made. A forward test or live run picks the new settings up from its next entry.

Backtest History filtered to one sweep: the original and each SL and target variant with net P&L, trades, win rate and max drawdown.
Backtest History filtered to one sweep: the original and each SL and target variant with net P&L, trades, win rate and max drawdown.

The honest part: overfitting

Run enough variants and one of them will win by chance. That is not a flaw in the software; it is arithmetic. With 20 variants over the same two years, the best one is partly the best rule and partly the luckiest fit to those particular days. Its edge over the original is the most inflated number on the screen.

Some habits that keep a sweep honest:

A worked example

A hypothetical strategy with a 30% per-leg stop is swept over 2022–2023 against 20%, 25%, 40% and 50%. The 40% variant tops the table at ₹1,32,000 against the original's ₹1,20,000 — +₹12,000, about ₹24 a trading day over roughly 500 days — with a Max DD ₹9,000 deeper.

Then both are run on 2024–2025, which the sweep never saw. The original makes ₹95,000 and the 40% variant ₹93,000. The out-of-sample gap is gone and the deeper drawdown remains. Here the right call is to keep the original. Had the 40% variant still led on the later range with similar drawdown, Use this would have been reasonable.

Where to find it

  1. In Algo, open Backtest and pick a single strategy.
  2. Tick Parameter sweep. The composer shows the strategy's stops and adjustment rules.
  3. Change values, type a Variant name and click Save as variant. Repeat; Reset to original puts the controls back.
  4. Set the range and friction, then click Run Sweep.
  5. Read the table, open Report on the rows that matter, and only then use Use this.

For the general method of testing option strategies, see options backtesting in India.

Common questions

How many variants can a parameter sweep run?

Up to 20 variants per strategy, plus the original, which always runs as the baseline. Each is a full backtest over the same dates.

Does Use this create a copy of my strategy?

No. It writes the winning variant's settings into the saved strategy itself, so the settings that won are the ones that trade. Running forward tests and live runs pick them up from their next entry.

Can I sweep a portfolio?

No. A sweep varies one strategy's settings, so it is available in single-strategy mode only.

How do I know a sweep result is not overfitting?

Pick the winner on one date range and confirm it on a later range the sweep never saw. Prefer settings where neighbouring values do similarly well, and check that drawdown and trade count support the difference.

More on Algo & Backtesting

More in Algo & Backtesting · App: Algo & Backtest · Definitions: glossary · All: every article