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 = 22Search 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 = 25Dedicated 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
| Parameter | Description |
|---|---|
upper_idString Required | Identifier for the upper band series. |
lower_idString Required | Identifier for the lower band series. |
symbolString 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. |
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. |
lengthInteger 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:
| Variable | Description |
|---|---|
donchian_up ordonchian_up[0]Decimal | Current upper band value. |
donchian_up[n]Decimal | Upper band value from n candles ago. |
donchian_lo ordonchian_lo[0]Decimal | Current lower band value. |
donchian_lo[n]Decimal | Lower band value from n candles ago. |
donchian_up.lengthDecimal | Donchian lookback length used (exposed on the upper id). |
donchian_up.high_sourcedonchian_lo.low_sourceString | Names of the input sources used (High/Low). |
donchian_up.symboldonchian_lo.symbolString | Symbol used. |
donchian_up.timeframedonchian_lo.timeframeString | Timeframe used. |
Notes
- Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are intended for equality/inequality checks.