Average Directional Index (adx)
[[adx]] measures the strength of a market move on a 0 to 100 scale. You can use it to filter entries, compare strategy setups, or test a trend-strength threshold in grid search.
ADX does not tell you market direction. A high value means the current move is strong, whether it is bullish or bearish. A lower value indicates a less directional market or a weaker trend.
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 = 16Search 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 = 20Trend filter with threshold
This example combines an [[adx]] block with a [[constant]] block to search which ADX level best separates choppy from trending markets.
[[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 timeframe
This ADX block uses a dedicated daily timeframe. The high, low, and close prices are taken from this timeframe (timeframe = "D"), rather than from the primary timeframe defined in [backtest]. See the Exchanges, Symbols and Timeframes page for alignment rules between this timeframe and the primary timeframe.
[[adx]]
id = "adx"
timeframe = "D"Specific symbol
This block reads its candles from the specific symbol BINANCE:ETHUSDT. The high, low, and close prices are taken from this symbol. See the Exchanges, Symbols and Timeframes page for alignment with the main symbol.
[[adx]]
id = "adx"
symbol = "BINANCE:ETHUSDT"Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name identifying the ADX series; the block exposes one numeric series with this identifier. |
di_lengthInteger Optional | Window used to smooth +DM, –DM, and True Range before they are normalised into +DI/–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_lengthInteger Optional | Window used to smooth the DX series (difference between +DI and –DI) into ADX; 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) |
symbolString 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. |
timeframeString 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 one numeric series and its parameters (DI and ADX windows), along with its input sources, symbol, and timeframe.
Assume the block is configured as:
[[adx]]
id = "adx"Then:
| Variable | Description |
|---|---|
adx or adx[0]Decimal | Current ADX value. |
adx[n]Decimal | ADX value from n candles ago. |
adx.di_lengthDecimal | DI calculation window used for adx. |
adx.adx_lengthDecimal | ADX smoothing window used for adx. |
adx.high_sourceadx.low_sourceadx.close_sourceString | Names of the high, low, and close input series used by the ADX series. |
adx.symbolString | Symbol used by the ADX series. |
adx.timeframeString | 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.