Strategy optimiser: find the best inputs without overfitting the past
The SuperCharting strategy optimiser backtests a strategy across input ranges to find the best settings, with filters, criteria and checks against overfitting.
The strategy optimiser runs your strategy again and again with different input values and ranks the results by the measure you choose, such as net profit or profit factor. In SuperCharting it is built into the Strategy Tester: you tick the inputs to search, give each a From, To and Step, pick a search method and run. The chart does not change until you apply a result.
An optimiser always finds settings that fit the past well. That is not the same as settings that will work next month. Past results do not guarantee future results, and the second half of this page is about using the optimiser without fooling yourself.
How to optimise a strategy in SuperCharting
- Add a strategy to the chart, for example the EMA crossover from write your first strategy on XAUUSD 1 hour.
- Click the blue Optimise button in the Strategy Tester toolbar, or right-click the strategy's name in the chart legend and choose Optimise strategy…. The Optimise strategy dialog opens with the strategy, symbol and timeframe in its title.
- On the Optimise tab, choose the objective: tick Maximise (untick it to minimise) and pick the measure, for example Net profit.
- Choose a Method and the number of Cycles. The note beside it shows the size of the parameter space in combinations.
- In the table, tick Active for the inputs to search and set From, To and Step. For an option list, type the choices separated by ";".
- Optionally set a Result filter and Save criteria.
- Click Run optimisation. A progress bar shows the cycle count; Stop ends the run early.
- Open the Results tab and click Apply best to chart, or click any row to apply that set instead.
The settings, one by one
Objective
The measure the optimiser ranks by. The list includes Total P&L, Net profit, Net profit %, Gross profit, Gross loss, Profit factor, Max drawdown, Max drawdown %, Total trades, Percent profitable, Avg trade, Ratio avg win / avg loss, Largest winning and losing trade, Avg bars in trade, Commission paid, Net profit long and short, and Recovery factor. To find the smallest drawdown, untick Maximise and choose Max drawdown %.
Search methods
- Random: random values for every active input each cycle. A good first look at the whole space.
- Random improvement: changes one input of the best set at a time and keeps the change if the result improves.
- Sequential improvement: walks each input through its range in priority order, starting from the current best.
- Annealing: a random search that narrows around the best result as the run goes on; it often finds good settings in fewer cycles.
- Brute force: tests every combination, in priority order. Exhaustive, and the cycle count becomes the number of combinations.
The Priority column sets the order in which inputs are walked. By default the first cycle tests the settings already on the chart, so you can see whether anything beats them; tick Skip the current settings as a starting point to leave them out.
Result filter and Save criteria
The Result filter keeps results above (Keep ≥) or below (Keep ≤) a value of one measure; for example keep Total trades ≥ 30. Save criteria are extra rules that must all pass, such as Percent profitable > 50 and Max drawdown % < 15, added with + Add criterion. A result that fails is still listed, greyed, but can never become the best.
Sweep across timeframes
Tick Sweep across timeframes and type a list such as 15m, 1h, 4h, 1D. The whole search is repeated on each timeframe, which tells you quickly whether an idea only works on one of them.
Templates and results
Get template downloads the input table as a CSV with the columns Parameter, From, To, Step, Default and Priority; Upload CSV loads one back, and Reset ranges starts the table again. On the Results tab, Download CSV saves every test, and the Chart tab plots one input against the objective, or two inputs against each other.
An example run
On XAUUSD 1 hour, search the EMA crossover's Fast length from 5 to 20 step 1 and Slow length from 20 to 60 step 5. That is 16 × 9 = 144 combinations, so Brute force with 144 cycles tests them all. Set the objective to Profit factor and a Result filter of Total trades ≥ 30, so a set with five lucky trades cannot win. Then open the Chart tab with Fast length on X: a broad hill of good values is a much better sign than one tall spike surrounded by losses.
How to avoid overfitting
Overfitting means the settings have learned the noise in one stretch of history. These habits keep it in check:
- Search few inputs. Three or four key inputs at most. Each extra input multiplies the combinations and the chance of a lucky fit.
- Use sensible steps. EMA lengths of 10, 12, 14 are enough; 10, 10.1, 10.2 only finds noise.
- Demand enough trades. Filter out results with too few trades to mean anything.
- Prefer stable areas. Pick a value in the middle of a region of good results, not the single best point.
- Keep data aside. Limit the Strategy Tester's Testing period to the older part of the history, optimise there, then test the chosen settings once on the newer part without changing them. The backtesting guide walks through this.
- Check another symbol. If settings tuned on NSE:NIFTY collapse on NSE:BANKNIFTY, the edge is probably fitted, not real.
- Keep costs on. Optimise with realistic commission and slippage, or the best result will be the one that trades most.
The optimiser's own Help tab gives the same advice: the best backtest is fitted to the past, so check it on another period or symbol before trusting it.
Frequently asked questions
Does the optimiser change my chart while it runs?
No. Each cycle is a separate backtest on the chart's loaded bars. The chart only changes when you apply a result.
How many cycles should I run?
Around 100 to 200 is a good start with Random or Annealing. Use Brute force when the parameter space is small enough to test completely.
Can TV Pilot optimise for me?
On accounts where the site owner has enabled it, TV Pilot can run an optimisation over input ranges you describe in chat. The same overfitting cautions apply.
Is the optimiser free?
SuperCharting is currently free to use, and the optimiser is part of the Strategy Tester on every account.