Donchian Mid-Line

[[donchian_mid]] produces the center line of a Donchian Channel. On each candle, it finds the highest high and the lowest low over the length window, then returns the midpoint between those two bounds. It therefore represents the geometric center of the recent range, not the average of the prices within it.

offset can shift this series forward in time. When it is greater than zero, the value available on a candle is the midpoint that was calculated offset candles earlier. This is a time shift, not a forecast.

The line rises or falls as the midpoint of the extremes shifts upward or downward. It can remain flat while price continues to move between the two bounds. A flat line therefore means that the center is unchanged; it does not by itself establish that the market is range-bound.

Ichimoku aliases

Several Ichimoku blocks reuse the exact same core computation as donchian_mid, with different default values.

Alias blockEquivalent donchian_mid
[[tenkan_sen]]length=9, offset=0
[[kijun_sen]]length=26, offset=0
[[senkou_span_b]]length=52, offset=26

These blocks keep their own TOML syntax, but their base calculation is donchian_mid. [[tenkan_sen]], [[kijun_sen]], and [[senkou_span_b]] keep these values fixed. If you need to vary length or offset, use [[donchian_mid]].

Block declaration

A strategy can contain multiple [[donchian_mid]] blocks. Each block outputs one numeric series representing the midpoint of the Donchian Channel, identified by the value of its id field.

The [[donchian_mid]] block has no source parameter because it is always computed from the candle high and low prices.

Examples

Minimal setup

This block computes the Donchian mid-line with the default length 20 because length is omitted.

[[donchian_mid]]
id = "donchian_mid"

Custom fixed setup

This block uses a custom length value.

[[donchian_mid]]
id     = "donchian_mid"
length = 30

Search for the optimal length

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

[[donchian_mid]]
id           = "donchian_mid"
length.start = 10
length.stop  = 50
length.step  = 5

Shifted equilibrium reference

This example uses the Donchian Mid as a recent equilibrium level, then applies a shift of 3 candles. The condition becomes true when the closing price moves back above that shifted reference. The example therefore builds a simple filter around a range midpoint that is less sensitive to immediate price changes.

[[donchian_mid]]
id     = "range_mid"
offset = 3

[[condition]]
id            = "reclaim_mid"
condition     = "close > range_mid"
next_block_id = "..."

Parameters

ParameterDescription
id
 String
 Required
Unique identifier for the Donchian mid‑line series.
length
 Integer
 Optional
Window used to compute highest high and lowest low; 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)
offset
 Integer
 Optional
Shift applied to the mid‑line; must be ≥ 0.
Default value: 0.

Usage:
• Fixed: offset = value
• Grid search:
 – offset.start = min_value
 – offset.stop = max_value
 – offset.step = value (optional, default 1)
symbol
 String
 or Array
 Optional
Market symbol (for example "BINANCE:BTCUSDT") or list of symbols (for example ["BINANCE:BTCUSDT", "BINANCE:ETHUSDT"]). Symbols must include the exchange prefix in the EXCHANGE:SYMBOL format (for example KUCOIN:BTCUSDT). If omitted, the block inherits the [backtest] symbol. When multiple symbols or timeframes are listed, the engine runs one backtest per symbol/timeframe combination.
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.

Note: high and low sources are selected automatically; no source parameter is needed.

Available variables

Use the identifiers below directly in your expressions. The Donchian mid‑line block exposes one numeric series and its parameters (length and optional offset), together with input sources, symbol, and timeframe.

Assume the block is configured as:

[[donchian_mid]]
id = "donchian_mid"

Then:

VariableDescription
donchian_mid or
donchian_mid[0]
Decimal
Current mid‑line value.
donchian_mid[n]
Decimal
Mid‑line value from n candles ago.
donchian_mid.length
Decimal
Length in use.
donchian_mid.offset
Decimal
Horizontal shift applied (if configured).
donchian_mid.high_source
donchian_mid.low_source
String
Names of the input sources.
donchian_mid.symbol
String
Symbol used.
donchian_mid.timeframe
String
Timeframe used.

Notes

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