Donchian Channels
The highest high and the lowest low of the last bars, with their midpoint: the range price has traded in.
- DC
- Built into Spectral
- Updates every tick
- donchian channels
- channel
- breakout
- highest high
- lowest low
- turtle
- range
MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.
Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Overview
Donchian Channels, developed by Richard Donchian, draw the highest high (upper band) and the lowest low (lower band) of the last Length bars, and the midpoint between them (basis). The channel is the range the market has traded in over that window.
With the default 20 bars on a daily chart, the bands are roughly the four-week high and low.
How to read it
The upper band rising to a new high, or the lower band falling to a new low, marks a breakout from the recent range; trend-following systems such as the Turtle rules buy a 20- or 55-bar high and sell a 20- or 55-bar low. A flat band means no new extreme has printed for a while; a rising lower band in an uptrend shows higher lows.
The basis splits the range in two: in a healthy uptrend price tends to stay in the upper half. A narrow channel marks consolidation; it widens again as soon as price breaks out.
Settings and limitations
Length sets the window; 20 is the standard, 55 the slower Turtle channel and 10 a common exit channel. The bands include the current bar, so price cannot close outside them: a breakout shows as the band moving with price. Set Offset to 1 to draw each bar's channel from the bars before it, so a breakout bar closes visibly outside the channel.
The channel appears after Length bars. Works on every bar size.
Notes
Matches TradingView's Donchian Channels (highest high, lowest low and their average, with an offset). Some platforms build the channel from closes instead of highs and lows; this one uses highs and lows.
Settings
Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.
| Setting | Type | Default | Range or options | What it does |
|---|---|---|---|---|
| Length | Whole number | 20 | 1 – 500 | Bars whose highest high and lowest low form the channel, including the current bar. |
| Offset | Whole number | 0 | -500 – 500 | Draw the channel this many bars later (positive) or earlier (negative). 1 compares each bar with the channel of the bars before it, as breakout traders do. |
Presets
Each preset is its own entry in the Indicators toolbox, with these settings changed.
| Toolbox entry | Short name | Settings |
|---|---|---|
| Donchian Channels (10) | DC 10 | Length: 10 |
| Donchian Channels (55) | DC 55 | Length: 55 |
What it draws
Lines
- Basisdashed · 1 px
#C4A46A - Upper bandsolid · 1.5 px · primary
#58A6FF - Lower bandsolid · 1.5 px
#58A6FF
Zones
- Channel fillfilled at 6% opacity
#58A6FF
Source
Save it as donchian-channels.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.
// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
schemaVersion: 2,
id: 'donchian-channels',
name: 'Donchian Channels',
shortName: 'DC',
version: '1.0.0',
author: 'Spectral',
description: 'The highest high and the lowest low of the last bars, with their midpoint: the range price has traded in.',
pane: 'price',
live: { lookback: 'length' },
inputs: {
length: { type: 'integer', label: 'Length', default: 20, min: 1, max: 500, description: 'Bars whose highest high and lowest low form the channel, including the current bar.' },
offset: { type: 'integer', label: 'Offset', default: 0, min: -500, max: 500, description: 'Draw the channel this many bars later (positive) or earlier (negative). 1 compares each bar with the channel of the bars before it, as breakout traders do.' },
},
plots: {
basis: { label: 'Basis', color: '#C4A46A', lineWidth: 1, lineStyle: 'dashed', offset: 'offset' },
upper: { label: 'Upper band', color: '#58A6FF', lineWidth: 1.5, primary: true, offset: 'offset' },
lower: { label: 'Lower band', color: '#58A6FF', lineWidth: 1.5, offset: 'offset' },
},
zones: {
band: { label: 'Channel fill', color: '#58A6FF', opacity: 0.06, offset: 'offset' },
},
presets: [
{ id: 'dc-10', name: 'Donchian Channels (10)', shortName: 'DC 10', inputs: { length: 10 } },
{ id: 'dc-55', name: 'Donchian Channels (55)', shortName: 'DC 55', inputs: { length: 55 } },
],
docs: {
overview: 'Donchian Channels, developed by Richard Donchian, draw the highest high (upper band) and the lowest low (lower band) of the last Length bars, and the midpoint between them (basis). The channel is the range the market has traded in over that window.\n\nWith the default 20 bars on a daily chart, the bands are roughly the four-week high and low.',
howToRead: 'The upper band rising to a new high, or the lower band falling to a new low, marks a breakout from the recent range; trend-following systems such as the Turtle rules buy a 20- or 55-bar high and sell a 20- or 55-bar low. A flat band means no new extreme has printed for a while; a rising lower band in an uptrend shows higher lows.\n\nThe basis splits the range in two: in a healthy uptrend price tends to stay in the upper half. A narrow channel marks consolidation; it widens again as soon as price breaks out.',
settings: 'Length sets the window; 20 is the standard, 55 the slower Turtle channel and 10 a common exit channel. The bands include the current bar, so price cannot close outside them: a breakout shows as the band moving with price. Set Offset to 1 to draw each bar\'s channel from the bars before it, so a breakout bar closes visibly outside the channel.\n\nThe channel appears after Length bars. Works on every bar size.',
notes: 'Matches TradingView\'s Donchian Channels (highest high, lowest low and their average, with an offset). Some platforms build the channel from closes instead of highs and lows; this one uses highs and lows.',
},
calculate(ctx) {
const { bars, inputs, ta } = ctx;
const upper = ta.highest(bars.map((bar) => bar.high), inputs.length);
const lower = ta.lowest(bars.map((bar) => bar.low), inputs.length);
const basis = upper.map((value, index) => (value === null || lower[index] === null ? null : (value + lower[index]) / 2));
return { plots: { basis, upper, lower }, zones: { band: { upper, lower } } };
},
};Adapt it with an LLM
Paste this into your assistant and replace the second-to-last line with the change you want.
Start from this Spectral custom indicator: https://spectral.trade/indicators/donchian-channels.js Format reference: https://spectral.trade/docs/custom-indicators.llm.md Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match. Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow. Change I want: <describe the change> Answer with the complete file in one code block, ready to save as <id>.js.


