Average True Range (atr)

[[atr]] measures market volatility, meaning the average size of price movements over a given period. It is calculated from the True Range, which takes into account both the distance between the candle’s high and low and the gaps between two consecutive candles.

ATR is then smoothed with an RMA (Running Moving Average, also known as Wilder’s moving average). This gives you a series that tracks changes in volatility while remaining more stable than a raw sequence of True Range values.

ATR does not measure market direction. It is mainly used as context, for example to filter market phases, adapt a stop, or compare the current volatility level with its recent level.

Block declaration

A strategy can contain multiple [[atr]] blocks. Each [[atr]] block produces a distinct ATR series identified by its id field.

[[atr]] has no source parameter because ATR is always computed from the candle high, low, and close prices.

Examples

Minimal setup

This block uses the default ATR length 14 and reads high, low, and close from the main symbol and timeframe defined in [backtest].

[[atr]]
id = "atr"

Custom fixed setup

This block uses a custom length value.

[[atr]]
id     = "atr"
length = 18

Finding the optimal length

This block explores a range of values for length to identify the best-performing length.

[[atr]]
id           = "atr"
length.start = 10
length.stop  = 20

Adaptive volatility filter

This example uses ATR as a volatility filter. atr_baseline (SMA of atr) is the reference, and atr_ratio_min defines the threshold to exceed: the condition becomes true when atratr_baseline>atr_ratio_min. The 1.1 to 1.8 bounds are starting points to optimize for the symbol, timeframe, and strategy. With a threshold close to 1.0, the filter stays permissive (it lets more signals pass). With a higher threshold, the filter becomes stricter and only keeps periods of stronger volatility.

[[constant]]
id    = "atr_ratio_min"
start = 1.1
stop  = 1.8
step  = 0.1

[[atr]]
id = "atr"

[[moving_average]]
id     = "atr_baseline"
source = "atr"
type   = "sma"
length = 100

[[condition]]
id            = "volatility_filter"
condition     = "atr / atr_baseline > atr_ratio_min"
next_block_id = "..."

Dedicated timeframe

This ATR 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.

[[atr]]
id        = "atr"
timeframe = "D"

Specific symbol

This block reads its candles from the specific symbol BINANCE:ETHUSDT. See the Exchanges, Symbols and Timeframes page for alignment with the main symbol.

[[atr]]
id     = "atr"
symbol = "BINANCE:ETHUSDT"

Parameters

ParameterDescription
id
 String
 Required
Unique name identifying the ATR series.
length
 Integer
 Optional
Look‑back period for ATR; must be ≥ 1 when specified.
If length is omitted, the default value is 14.

Usage:
• Fixed: length = value
• Grid search:
 – length.start = min_value
 – length.stop = max_value
 – length.step = value (optional, default 1)
symbol
 String
 or Array
 Optional
Market symbol from which the ATR 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

Use the identifiers below directly in your expressions. The ATR block exposes one numeric series and its length, together with the input sources, symbol, and timeframe.

Assume the block is configured as:

[[atr]]
id = "atr"

Then:

VariableDescription
atr or atr[0]
Decimal
Current ATR value.
atr[n]
Decimal
ATR value from n candles ago.
atr.length
Decimal
Length in use.
atr.high_source
atr.low_source
atr.close_source
String
Names of the input sources.
atr.symbol
String
Symbol used.
atr.timeframe
String
Timeframe used.

Notes

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