Parameter sweep (grid search)

A parameter sweep, or grid search, runs the same strategy once for every combination of values in a declared set of parameters and records the result of each run. It maps how the rule behaves across its settings; the map is informative, while picking the single best cell without a correction for the number of cells is how selection bias enters a backtest.

Senzoukria · Glossary · Updated September 2026


Building the grid

Each parameter gets a list of candidate values; the grid is the Cartesian product of those lists, and each cell is one full backtest. A rule with a lookback of five values and a threshold of six values gives thirty runs; add a third parameter with four values and it becomes one hundred and twenty. The count grows multiplicatively, which is why the number of parameters swept at once matters more than the number of values on any one axis.

Values should be chosen before the sweep, on a scale that makes sense for the parameter (a lookback in bars, a threshold in ticks or in a ratio), and the list should include values you expect to be poor. A grid made only of values that already looked good is a second round of selection wearing the clothes of a test.

Reading the map, not the winner

  • Look for a region where many neighbouring cells perform reasonably; that plateau is what a rule with structure looks like.
  • A single cell far above its neighbours is more likely a coincidence of the sample than a discovery.
  • Check how the map changes when costs are raised; a plateau that survives higher slippage is worth more than a peak that does not.
  • Record the whole grid, not the top row. The count of cells is an input to any later correction for selection.

The sweep inside a walk-forward

In walk-forward analysis the grid is run on each training slice and the selection rule picks one cell per slice; the test slices then use that cell. This is the honest use of a sweep: the winner is chosen on data that precedes the data it is judged on. Running the grid on the full period and reporting the best cell is a different exercise, useful for the map and for computing overfitting statistics, and not a measure of achievable performance.

In Senzoukria

The Automatic backtest panel on the Replay screen has a Parameters to sweep control inside the walk-forward toggle. Each parameter exposed by the strategy can be given a set of values; the panel shows the resulting count as combinations times slices with an estimated duration, and refuses a grid above a maximum with the message Too many combinations, asking you to remove some values. A note explains why: every extra combination is one more draw in the same data, and past a point you are measuring the luck of an overfit rather than a strategy.

After the run, the stability chart shows the chosen configuration against its immediate neighbours on the grid, one step on one axis, with the hint that a plateau is what a real edge looks like. The Gauntlet reruns the full grid on all bars to build the matrix behind the Probability of backtest overfitting and reports the number of configurations tried alongside the Deflated Sharpe.

Common mistakes

  • Sweeping many parameters at once on a short history.
  • Building the grid from values that were already picked by eye.
  • Reporting the best full-period cell as the strategy's result.
  • Rerunning the sweep with a wider grid after a disappointing result, without counting the earlier runs.

This page in other languages

Frequently asked questions

How many combinations is too many?
It depends on how many independent trades the sample provides and on whether a selection correction is applied. The more cells relative to trades, the more likely the best cell is a lucky draw. A practical rule is to narrow ranges or sweep fewer parameters at once, to record the total count, and to read the deflated statistic rather than the raw one.
Is grid search the same as optimisation?
Grid search is one way to optimise: exhaustive over a declared set of values. Other methods search adaptively. The grid has the advantage of producing a complete map of the neighbourhood, which is what parameter stability is read from, and the disadvantage of a cost that multiplies with each parameter added.
Should the best cell of a sweep be traded?
Not on the strength of the sweep alone. The best cell on the full history was chosen on the same data that produced its result. Use the sweep inside a walk-forward so that selection precedes evaluation, check that the chosen cell sits on a plateau, raise costs and see whether it survives, and keep the count of cells in the record.

Keep reading