Trading strategy optimization is the search for the parameter values, such as indicator lengths, stop distances and filters, that make a strategy perform best on historical data. Grid search tests every combination, a genetic algorithm breeds good combinations from a population. Either way the winner only counts if it holds up on data the search never saw.
What is parameter optimization in backtesting?
Parameter optimization in backtesting runs the same strategy many times with different input values and ranks the results by a chosen measure. A moving average crossover, for example, has two inputs: the fast and the slow length. Optimization answers which pair of lengths would have worked best, and how much the result depends on that choice.
The second answer matters more than the first. A strategy that is profitable across a broad range of values is far more likely to keep working than one that is profitable at a single value. See overfitting and lookahead bias.
How does grid search work for trading parameters?
Grid search for trading parameters tests every combination of the values you choose. Three parameters with 20 values each make 20 times 20 times 20, which is 8,000 backtests. Grid search is exhaustive and simple, and it maps the whole space, which is exactly what a heatmap of the results needs.
Its limit is growth. Every added parameter multiplies the work. Five parameters with 20 values each make 3,200,000 combinations; at one second per backtest that is about 37 days of computing. Beyond three or four parameters, a full grid is rarely practical.
How does a genetic algorithm optimize a trading strategy?
A genetic algorithm optimizes a trading strategy by evolving a population of parameter sets toward better results instead of testing every combination. Each set is backtested, the better ones are kept as parents, and their values are mixed and slightly changed to form the next generation.
- Start with a random population, for example 100 parameter sets.
- Score each set with a backtest and a fitness measure such as net profit divided by drawdown.
- Select the better sets as parents.
- Cross over: combine values from two parents into a child.
- Mutate: change a few values at random, so the search does not get stuck.
- Repeat for a number of generations, or until the best score stops improving.
With 100 sets over 50 generations, the search runs at most 5,000 backtests, about 1.4 hours at one second each, instead of 37 days for the full grid of five parameters. The price is that a genetic algorithm can miss the true best point and does not map the whole space.
Grid search or genetic algorithm: which should you use?
Use grid search when the parameter space is small enough to test completely, and a genetic algorithm when it is not. A common workflow is a genetic search to find the promising region, followed by a fine grid around it to see whether that region is a plateau or a lone peak.
| Aspect | Grid search | Genetic algorithm |
|---|---|---|
| How it searches | Every combination | A population that evolves toward better results |
| Work | Multiplies with every parameter | Set by population size and generations |
| Finds the best point | Always, within the grid | Usually close to it, not guaranteed |
| Shows the landscape | Yes, a complete heatmap | Only where the search went |
| Best for | Up to about three or four parameters | Large spaces with many parameters |
On other platforms, cTrader has grid optimization and a genetic algorithm built in, MetaTrader 5 offers a complete search and a fast genetic based algorithm, and TradingView has no built in parameter optimizer (checked 2026-10-01).
How do you optimize a trading strategy without overfitting?
You optimize a trading strategy without overfitting by choosing a sound fitness measure, keeping the search small, and confirming the result on data the optimizer never saw. The goal is a stable region of good parameters, not the single highest number.
- Optimize for risk adjusted return, such as return over maximum drawdown or the Sharpe ratio, not net profit alone. Net profit rewards size and luck.
- Require a minimum number of trades, so a set with five lucky trades cannot win.
- Use coarse steps. A stop of 20, 25 or 30 pips tells you as much as every value from 20 to 30.
- Hold back an out of sample period and compare each pass's in sample and out of sample result.
- Walk forward: repeat optimize then test on rolling windows. See walk forward analysis.
- Pick from a plateau: choose values whose neighbors perform almost as well.
How does optimization work in the Orion Quant Technologies Engine?
The Orion Quant Technologies Engine has both methods. Grid search runs every combination of the parameters you choose, in parallel on your cores. Genetic search breeds a population of parameter sets toward what works, for a space too large to walk. The backtest loop and the optimizer's passes run on a core written in Rust, and a run can also be queued on our servers.
For honesty, hold back part of the range: the sweep fits on the rest, and every pass shows its out of sample result and the gap between the two. Walk forward runs on rolling or anchored windows, and a heatmap shows the result across two parameters, where a lone peak is luck and a broad plateau is a strategy. The engine is in early access through the waitlist.
Frequently asked questions
How many parameters should a trading strategy have?
As few as the idea needs. Each parameter adds a way to fit noise and multiplies the search. Many robust strategies get by with two to four inputs. A useful check is the number of trades per parameter: if a strategy with six parameters made only sixty trades, the result says more about the tuning than about the market.
What should I optimize for: profit, drawdown or Sharpe ratio?
A measure that combines return and risk is usually the better target, such as net profit divided by maximum drawdown, or the Sharpe ratio. Net profit alone favors parameter sets that take larger risks or rely on a few big trades. Whatever you choose, set a minimum number of trades so a short lucky streak cannot win the search.
Is a genetic algorithm better than grid search?
Neither is better in general. Grid search is complete and shows the whole landscape, but its work multiplies with every parameter. A genetic algorithm handles large spaces with far fewer backtests, but may miss the best point and only explores where it searched. For two or three parameters use a grid; for more, start genetic and refine with a grid.
How do I know if my optimized parameters will work in the future?
You cannot know for certain, but you can raise the odds. Confirm the parameters on an out of sample period, run a walk forward test, check that neighboring values perform almost as well, and look at the result under doubled costs and a Monte Carlo reshuffle of the trades. A strategy that passes all of these is worth paper trading.
Research and testing only. A backtest shows how rules behaved in the past, not what they will earn. Nothing here is investment advice.