Average Directional Index (adx)

The Average Directional Index (ADX) measures how strongly one direction dominates recent movement without identifying whether that direction is upward or downward. It produces a series ranging from 0 to 100. A high value reflects clear directional dominance, while a low value means that upward and downward movement offset each other more closely. The same ADX level can therefore describe either a rising or a falling market.

The indicator compares an upward component (+DI) with a downward component (-DI), both normalized by True Range. di_length sets the horizon over which these components are smoothed, and adx_length then smooths their relative contrast to form the ADX. The output therefore indicates how strongly recent movement favors one direction, regardless of whether that direction is upward or downward.

Block declaration

A strategy can contain multiple [[adx]] blocks. Each block outputs one numeric series which is the ADX value.

The [[adx]] block does not expose a source parameter because ADX is always computed from the candle high, low, and close prices.

Examples

Minimal setup

This block uses the default ADX lengths: 14 for di_length and 14 for adx_length.

[[adx]]
id = "adx"

Custom fixed setup

This block uses custom di_length and adx_length values.

[[adx]]
id         = "adx"
di_length  = 15
adx_length = 16

Search for the optimal lengths

This block explores ranges of values for di_length and adx_length to identify the best-performing combination.

[[adx]]
id               = "adx"
di_length.start  = 10
di_length.stop   = 20
adx_length.start = 10
adx_length.stop  = 20

Trend filter with threshold

This example uses ADX as an entry filter. The [[constant]] block defines a threshold named adx_threshold whose value ranges from 20.0 to 30.0 during the grid search: one backtest runs for each value in the range. On each candle, the [[condition]] block compares ADX to this threshold and only lets the strategy move on to the next block when adx > adx_threshold, that is, when the market is trending strongly enough. Ranking the results then shows which threshold value performs best.

[[adx]]
id = "adx"

[[constant]]
id    = "adx_threshold"
start = 20.0
stop  = 30.0

[[condition]]
id            = "trend_filter"
condition     = "adx > adx_threshold"
next_block_id = "..."

Dedicated symbol and timeframe

This ADX block uses the daily candles from BINANCE:ETHUSDT. The high, low, and close prices come from this symbol and timeframe, independently of the primary symbol and timeframe defined in [backtest]. See Exchanges, Symbols and Timeframes for alignment rules.

[[adx]]
id        = "adx"
symbol    = "BINANCE:ETHUSDT"
timeframe = "D"

Parameters

ParameterDescription
id
 String
 Required
Unique name identifying the ADX series; the block exposes one numeric series with this identifier.
di_length
 Integer
 Optional
Number of candles over which the upward and downward pushes are averaged into +DI and -DI; must be ≥ 1 when specified.
If di_length is omitted, the default value is 14.

Usage:
• Fixed: di_length = value
• Grid search:
 – di_length.start = min_value
 – di_length.stop = max_value
 – di_length.step = value (optional, default 1)
adx_length
 Integer
 Optional
Number of candles over which the gap between +DI and -DI is smoothed into the ADX value; must be ≥ 1 when specified.
If adx_length is omitted, the default value is 14.

Usage:
• Fixed: adx_length = value
• Grid search:
 – adx_length.start = min_value
 – adx_length.stop = max_value
 – adx_length.step = value (optional, default 1)
symbol
 String
 or Array
 Optional
Market symbol from which the ADX reads its candles (high, low, and close prices). For symbol format and alignment rules, see Exchanges, Symbols and Timeframes.
timeframe
 String
 or Array
 Optional
Timeframe on which this indicator is computed.
If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].
For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes.

Available variables

The ADX block exposes the ADX series and, as read-only values, its calculation lengths, input sources, symbol, and timeframe.

Assume the block is configured as:

[[adx]]
id = "adx"

Then:

VariableDescription
adx or adx[0]
Decimal
Current ADX value.
adx[n]
Decimal
ADX value from n candles ago.
adx.di_length
Decimal
DI calculation window used for adx.
adx.adx_length
Decimal
ADX smoothing window used for adx.
adx.high_source
adx.low_source
adx.close_source
String
Names of the high, low, and close input series used by the ADX series.
adx.symbol
String
Symbol used by the ADX series.
adx.timeframe
String
Timeframe used by the ADX series.

Notes

  • Numeric variables support arithmetic, comparisons, and logical operators.
  • Text variables are strings intended for equality/inequality checks only.