Objective function (optimization criterion)

The objective function of a strategy optimization is the single number the optimizer maximizes to rank parameter configurations, such as net profit, profit factor, Sharpe ratio or SQN. The choice determines which configuration wins and what kind of risk the winner is likely to carry.

Senzoukria · Glossary · Updated September 2026


What the criterion rewards

  • Net profit rewards size and exposure: the configuration that trades the most or holds the largest positions usually wins, together with its drawdown.
  • Profit factor rewards selectivity: a configuration with very few trades and no losers scores infinitely well.
  • Expectancy per trade rewards large average trades, regardless of how many there were.
  • Sharpe or Sortino per trade rewards consistency of trade results.
  • SQN multiplies a per-trade Sharpe by the square root of the trade count, so it rewards consistency and sample size together.
  • Custom ratios such as return over drawdown reward what a specific account rule cares about.

An example of the same grid, two winners

Configuration A takes 12 trades with a profit factor of 4.0 and a net result of +1,800. Configuration B takes 140 trades with a profit factor of 1.4 and a net result of +5,600. Maximizing profit factor selects A; maximizing net profit or SQN is likely to select B. With a minimum of 30 trades imposed on every configuration, A is excluded before the ranking. The constraint matters as much as the criterion: without it, the selection drifts toward tiny samples whose ratios are extreme by chance.

Changing the criterion after seeing which configuration each one selects is itself a form of data snooping. The criterion belongs in the written hypothesis.

In Senzoukria

The parameter sweep and the walk-forward of the automatic backtest offer four selection criteria: SQN (the default, labeled as accounting for the number of trades), profit factor, expectancy per trade and Sharpe per trade. A configuration with fewer than 10 trades is given a score of minus infinity so it can never be selected; a configuration with no losing trade, whose profit factor is infinite, is mapped to a large finite score so the ranking stays deterministic. The walk-forward then applies the chosen criterion inside each training window and evaluates the winner on the following test window, and the Gauntlet judges the selected path with statistics that do not depend on the criterion, such as a permutation p-value and the deflated Sharpe.

Common mistakes

  • Optimizing net profit and then being surprised by the drawdown of the winner.
  • Optimizing profit factor without a minimum trade count.
  • Choosing the criterion that makes the favorite configuration win.
  • Reading the optimized value as an estimate of future performance; it is the maximum of many.

In the same section

This page in other languages

Frequently asked questions

What is the best objective function for optimizing a trading strategy?
There is no universal best. A criterion that combines average result, dispersion and trade count, such as SQN, is less prone to picking tiny samples than profit factor or net profit. Whatever is chosen should reflect the constraint that matters for the account, and should be fixed before the run.
Why does the desktop reject configurations with fewer than 10 trades?
Because ratios computed on a handful of trades are extreme by chance. Three winning trades give an infinite profit factor, and without the floor that configuration would be selected in almost every sweep.

Keep reading