Constant

[[constant]] defines a named numeric value used as a reusable threshold or constant in your rules. Its value changes during grid search without creating a time series or depending on a symbol or timeframe.

Block declaration

A strategy can contain multiple [[constant]] blocks. Each block specifies an identifier and a value interval. One backtest is run for each value in the interval.

Integer example

[[constant]]
id    = "overbought"
start = 70
stop  = 76
step  = 2

Decimal example

[[constant]]
id    = "take_profit_pct"
start = 0.5
stop  = 1.0
step  = 0.1

Using constants in rules

Reference a constant by its id, like a variable:

[[position]]
id         = "k_above_oversold"
position   = "above"
reference  = "stoch_k"
comparison = "oversold"    # uses the "oversold" constant
[[condition]]
id        = "buy_condition"
condition = "rsi > overbought and k < oversold"

You can also constrain the search space globally to discard incoherent combinations (see the “Hyperparameter Combinations” page):

[constraints]
condition = "oversold < overbought"

Block parameters

ParameterDescription
id
 Text
 Required
Unique name of the exposed constant.
start
 Decimal or Integer
 Required
Start bound of the interval.
stop
 Decimal or Integer
 Required
End bound of the interval.
step
 Decimal or Integer
 Optional
Increment between successive values.

Exposed variables

The Constant block exposes a scalar variable accessible via its id:

VariableDescription
<id>
Decimal
Current value of the constant, usable in expressions (conditions, positions, etc.).

Notes

  • ids must be unique within the strategy.
  • A [[constant]] does not feed indicator internal parameters (e.g., length, offset). Indicator parameter ranges are defined directly in the corresponding indicator block.