Grid Search for Trading Strategy Optimization
Grid search is an exhaustive parameter optimization method that tests every combination of parameter values on a fixed grid. You set a minimum, maximum, and step size for each parameter; grid search takes the Cartesian product of those value lists, runs a backtest at every point, and ranks the results. It is the most thorough search method and completely deterministic — but its cost grows multiplicatively with each parameter you add.
Definition
Grid search — a search that evaluates the full Cartesian product of every parameter's value list. With periods {10, 20, 30} and thresholds {60, 70, 80}, grid search runs all nine combinations. Nothing is left untested, so the best point on the grid is guaranteed to be found.
How does grid search work?
Grid search follows a fixed four-step procedure. Each step is deterministic — given the same parameter ranges and step sizes, the search will always produce the same set of backtests in the same order, and the leaderboard will always be identical.
- Define each parameter range. A minimum, maximum, and step — e.g. RSI period from 10 to 30 in steps of 5 gives {10, 15, 20, 25, 30}. Each enabled parameter contributes its own list of discrete values to the grid. Parameters that are left at a fixed value are not expanded — only those with a range contribute to the Cartesian product.
- Build the grid. Take the Cartesian product of every enabled parameter's value list. Each point in the resulting grid is one complete parameter set — a specific combination of every tunable value. With two parameters of five values each, the grid has twenty-five points; with three parameters of five values each, it has one hundred and twenty-five.
- Backtest every point. Run the strategy at each parameter combination and record its full metrics — Sharpe ratio, Sortino ratio, maximum drawdown, total return, trade count, and more. No point is skipped, estimated, or approximated. Every combination that falls within the grid receives its own independent backtest on the full historical data window.
- Rank by objective. Sort the results by your chosen metric (e.g. Sharpe ratio) to produce a leaderboard of the best parameter sets. Because every combination was tested, the top result on the leaderboard is the true optimum on the grid — not an estimate or approximation, but the actual best point that existed within the ranges you defined.
The combinatorial explosion problem
The defining weakness of grid search is that its cost is the product of the value counts for each parameter — not the sum. Adding a parameter does not add backtests; it multiplies them. A strategy with one parameter and ten values needs ten backtests. Add a second parameter with ten values and you need one hundred. Add a third and you need one thousand. The table below shows how quickly that arithmetic becomes prohibitive.
| Parameters | Values each | Total backtests |
|---|---|---|
| 1 | 10 | 10 |
| 2 | 10 | 100 |
| 3 | 10 | 1,000 |
| 4 | 10 | 10,000 |
Because the cost is the product of the value counts, backtester.run refuses to start a grid search whose total combinations exceed your plan's iteration cap (20 on Free, 100 on Pro, 500 on Quant) rather than silently dropping combinations and giving you a partial result. If the platform rejects your grid, you will always know why: the full grid was never run, so no partial leaderboard is returned. To fit within the cap, narrow a range, widen a step, or switch to random search, which lets you explore the same space with a fixed budget of backtests.
The multiplicative cost structure also means that the relationship between granularity and trial count is not intuitive. Halving the step size of a single parameter doubles its value count and doubles the total grid. Halving the step size of all three parameters in a three-parameter search multiplies the grid by eight. Before widening a range or tightening a step, recalculate the trial count: multiply the value counts for every enabled parameter and compare to your plan's cap.
When should you use grid search?
Grid search is the right tool in a specific and relatively narrow set of circumstances. Outside those circumstances, random search or Bayesian optimization will give you more value for the same budget. Use grid search when:
- You have one or two parameters to tune. With one or two parameters, a fine-grained grid is typically within the iteration cap and the exhaustive nature of grid search is a genuine advantage — you are guaranteed to find the best combination, not just a good one.
- You want a complete, deterministic map of the parameter space. Random search covers more ground per trial in high dimensions, but it leaves gaps. Grid search has no gaps. Every point you defined is tested, which makes the result fully reproducible and the leaderboard exhaustive.
- You intend to read the result as a sensitivity analysis. The grid-search leaderboard is also a landscape map: you can see not just the best combination but how performance varies across adjacent values. A broad plateau of high-Sharpe combinations signals a robust strategy with a real edge that is not fragile to small parameter changes. An isolated peak — one combination far better than all its neighbours — signals overfitting to the historical data, where the strategy has been tuned to a noise artefact rather than a genuine market dynamic. Grid search makes this diagnostic easy because every point on the map is filled in.
- Determinism matters for your workflow. If you need to be able to reproduce a result exactly — for audit, documentation, or peer review — grid search is the safest choice. There is no random seed to manage, no sampling distribution to document. The same ranges and step sizes always produce the same leaderboard.
Grid vs random vs Bayesian search
The three search methods available in backtester.run differ primarily in how they allocate their budget across the parameter space. Each is the best choice in a different context; the table below summarises the key differences.
| Method | Coverage | Cost growth | Determinism |
|---|---|---|---|
| Grid | Complete on the grid | Multiplicative | Fully deterministic |
| Random | Probabilistic | Linear in budget | Reproducible via seed |
| Bayesian | Focused on promising regions | Fewest trials | Adaptive |
The most common mistake is reaching for grid search out of habit when a strategy has three or more parameters. At that point the grid almost always exceeds the iteration cap — and even when it does not, random search finds comparably strong results in far fewer trials because it samples more distinct values of each parameter for the same budget. Grid search's exhaustiveness is only an advantage when you can actually afford the full grid.
Bayesian optimization occupies a different niche: it is the method to reach for when each backtest is slow (long histories, intraday data) and you want the best result from the absolute fewest trials. It learns from each result and focuses subsequent trials on the most promising region of the parameter space. The cost is per-trial overhead from the surrogate model, which matters less as backtest time dominates.
Run a grid search without writing code
Describe your strategy in plain English on backtester.run, set ranges for the parameters you want to tune, and run an exhaustive grid search across real market data — with a ranked leaderboard of every combination.
Start free →Frequently Asked Questions
- What is grid search in strategy optimization?
- Grid search is an exhaustive parameter search that tests every combination of values on a fixed grid. You define a minimum, maximum, and step for each parameter; grid search runs a backtest at every point in the resulting Cartesian product and ranks the results. It is the most thorough method and fully deterministic.
- What is the combinatorial explosion problem in grid search?
- The number of backtests is the product of the value counts for each parameter. Two parameters with 10 values each is 100 runs; a third turns it into 1,000. Each added parameter multiplies the cost, so grid search becomes impractical past two or three parameters.
- When should I use grid search?
- Use grid search when you have one or two parameters and want a complete map of how performance varies across them — which also doubles as a sensitivity analysis. It is the right choice when determinism and exhaustiveness matter more than speed.
- How many grid points can I run on backtester.run?
- Each plan has an iteration cap — 20 on Free, 100 on Pro, 500 on Quant. Grid search refuses to start if your ranges would produce more combinations than the cap, rather than silently truncating, so you always know the whole grid was tested.
- Is grid search better than random or Bayesian search?
- Only for small parameter spaces. Grid search guarantees it finds the best point on the grid, but its cost grows multiplicatively. With three or more parameters, random search covers the space more efficiently and Bayesian optimization finds strong results in fewer trials.