Donchian Mid-Line
[[donchian_mid]] is the midpoint of the Donchian Channel. On each candle, it first computes the highest high and the lowest low over the length window, then takes the average of those two bounds. The result is a center line that does not represent an average of prices, but the geometric center of the market’s recent range.
You use the Donchian Mid to track how that range shifts over time, position price relative to its recent equilibrium, or build logic around a channel already defined by its upper and lower bounds. When the line rises, it means the whole recent zone is moving upward. When it falls, the zone is moving downward. When it stays more stable, the market is evolving in a more lateral range.
Unlike a moving average, the Donchian Mid does not smooth a sequence of closes. It reacts to changes in recent extremes. This makes it especially useful when your strategy focuses on the structure of a range, its gradual recentering, or the position of price inside a Donchian Channel.
Ichimoku aliases
Several Ichimoku blocks reuse the exact same core computation as donchian_mid, with different default values.
| Alias block | Equivalent 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 = 30Search 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 = 5Shifted 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. This kind of setup can be used to build 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
| Parameter | Description |
|---|---|
idString Required | Unique identifier for the Donchian mid‑line series. |
lengthInteger 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) |
offsetInteger 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) |
symbolString 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. |
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. |
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:
| Variable | Description |
|---|---|
donchian_mid ordonchian_mid[0]Decimal | Current mid‑line value. |
donchian_mid[n]Decimal | Mid‑line value from n candles ago. |
donchian_mid.lengthDecimal | Length in use. |
donchian_mid.offsetDecimal | Horizontal shift applied (if configured). |
donchian_mid.high_sourcedonchian_mid.low_sourceString | Names of the input sources. |
donchian_mid.symbolString | Symbol used. |
donchian_mid.timeframeString | Timeframe used. |
Notes
- Numeric variables support arithmetic, comparisons, and logical operators.
- Text variables are strings intended for equality/inequality checks only.