Average True Range (atr)

Average True Range (ATR) measures the typical magnitude of a market’s recent movement without indicating its direction. It produces a non-negative series expressed in price units. A high value corresponds to large recent price ranges, while a low value corresponds to tighter movement. The series can reach zero, but it never becomes negative.

Each candle’s range is measured through its True Range, which captures both the distance between high and low and any gap from the previous close. These ranges are then processed with Wilder’s recursive smoothing; length controls how quickly new values influence the series. ATR therefore represents a characteristic price distance on each candle and should be read in the unit and scale of the market being analyzed.

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 compares the current ATR to its own recent average to spot when volatility rises above its usual level. atr_baseline is a simple moving average of atr over 100 candles: it represents the reference volatility of the recent candles. atr_ratio_min sets how far ATR must exceed that reference for the condition to trigger.

The condition atr / atr_baseline > atr_ratio_min is therefore true when ATR is more than atr_ratio_min times its reference: with 1.1, ATR must be at least 10% above its average; with 1.8, at least 80% above. The 1.1 to 1.8 grid explores these thresholds. A threshold close to 1.0 lets most candles through; a higher threshold keeps only the phases that are clearly more volatile than the recent average.

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

[[atr]]
id = "atr"

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

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

Dedicated symbol and timeframe

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

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

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.