Donchian Channels

[[donchian]] defines a price range from recent extremes. The upper band is the highest high observed over the last length bars, and the lower band is the lowest low observed over that same window. You can use it to spot breakouts, frame price inside its recent trading range, or compare several channel lengths in a grid search.

When price crosses one of the two bands, it means that it is moving outside its recent range to the upside or the downside. A widening channel reflects more distant extremes and therefore a more active market. A tighter channel indicates a narrower trading range instead. The Donchian Channel does not try to smooth price: it directly highlights the market’s upper and lower bounds over the period being studied.

Block declaration

A strategy can contain multiple [[donchian]] blocks. Each block generates two distinct numeric series: the upper band and the lower band of the Donchian Channel. These two series are identified with the upper_id and lower_id fields.

The [[donchian]] block does not have a source parameter because the Donchian Channel is always computed from the candle high and low prices.

Examples

Minimal setup

This block computes both Donchian Channel bands with the default length 20.

[[donchian]]
upper_id = "donchian_up"
lower_id = "donchian_lo"

Custom fixed setup

This block uses a custom length value.

[[donchian]]
upper_id = "donchian_up"
lower_id = "donchian_lo"
length   = 22

Search for the optimal length

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

[[donchian]]
upper_id     = "donchian_up"
lower_id     = "donchian_lo"
length.start = 15
length.stop  = 25

Dedicated symbol/timeframe

This block computes the Donchian channel on BINANCE:BTCUSDT and timeframe 60. Because length is omitted, the block uses the default length 20.

[[donchian]]
upper_id  = "donchian_up"
lower_id  = "donchian_lo"
symbol    = "BINANCE:BTCUSDT"
timeframe = "60"

Parameters

ParameterDescription
upper_id
 String
 Required
Identifier for the upper band series.
lower_id
 String
 Required
Identifier for the lower band series.
symbol
 String
 or Array
 Optional
Market symbol(s) from which this block reads its candles (high, low). If omitted, the block inherits the [backtest] symbol. For symbol format, arrays, 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.
length
 Integer
 Optional
Lookback window; must be ≥ 1.
Default value: 20.

Usage:
• Fixed: length = value
• Grid search:
 – length.start = min_value
 – length.stop = max_value
 – length.step = value (optional, default 1)

Available variables

You can use the identifiers below directly in your expressions. The Donchian Channel block exposes two numeric series (upper band and lower band), along with their parameters and calculation context.

Assume the block is configured as follows:

[[donchian]]
upper_id = "donchian_up"
lower_id = "donchian_lo"

Then:

VariableDescription
donchian_up or
donchian_up[0]
Decimal
Current upper band value.
donchian_up[n]
Decimal
Upper band value from n candles ago.
donchian_lo or
donchian_lo[0]
Decimal
Current lower band value.
donchian_lo[n]
Decimal
Lower band value from n candles ago.
donchian_up.length
Decimal
Donchian lookback length used (exposed on the upper id).
donchian_up.high_source
donchian_lo.low_source
String
Names of the input sources used (High/Low).
donchian_up.symbol
donchian_lo.symbol
String
Symbol used.
donchian_up.timeframe
donchian_lo.timeframe
String
Timeframe used.

Notes

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