Objective

[[objective]] defines the criteria used to rank backtest combinations during optimization. Each objective produces its own ranking.

Its formula uses backtest variables such as netprofit, max_drawdown_percent, or closedtrades. Indicator outputs and candle series (OHLCV) are not available in objective formulas.

Some variables are reserved for objectives and are not available in the strategy’s trading expressions.

See Objectives for more details, examples, and the full list of available variables.

Block declaration

A strategy can contain multiple [[objective]] blocks.

Examples

Sortino ratio

The Sortino ratio ranks combinations from portfolio-equity returns while only measuring downside volatility.

See Sharpe and Sortino Ratios.

[[objective]]
id        = "sortino"
formula   = "sortino_ratio"
ascending = false

Calmar ratio

The Calmar ratio ranks combinations by comparing compounded annual growth to maximum drawdown over the backtest.

See Calmar Ratio.

[[objective]]
id        = "calmar"
formula   = "calmar_ratio"
ascending = false

Recovery factor

The recovery factor compares final net profit to the maximum drawdown in absolute terms. A score of 4 means that net profit is four times larger than the worst drawdown observed.

[[objective]]
id        = "recovery_factor"
formula   = "netprofit / max_drawdown"
ascending = false

Block parameters

ParameterDescription
id
 Text
 Required
Unique identifier of the objective.
formula
 Text (expression)
 Required
Expression evaluated from backtest variables to compute the objective value.
ascending
 Boolean
 Optional
Sort order for the ranking. When true, the engine minimizes the objective; when false, it maximizes it. Default value: false.

Defaults

When no objective block is declared, the engine automatically injects the following objective:

[[objective]]
id        = "netprofit"
formula   = "netprofit"
ascending = false

Evaluation and ranking

  • The objective expression is evaluated once at the end of the backtest to obtain its final value.
  • When the result is NaN, the combination is excluded from the corresponding ranking.
  • Ties are broken by keeping the combination with the smallest internal combination number.
  • When multiple objectives are declared, each one maintains its own ranking.