Which high and low own the boundaries of the current rolling window? That is the practical question behind Donchian Channels. This tutorial builds the answer from finalized data, shows the exact arithmetic, and gives you a laboratory for breaking the indicator safely.
The mental model in one minute
The channel is the trailing highest high and lowest low, including the current row. Its middle is the midrange of those two extrema—not an average price.
The output is a measurement. It is not an order, forecast, confidence interval, or promise that a familiar-looking market pattern will repeat.
Contract before chart
- Variant: The calculation window includes the current bar. A causal breakout detector often compares the current price with the previous bar's completed channel instead.
- Defaults: period=20.
- First publication: index 19 after the first complete 20-bar window.
- Data: finalized, causal observations on one price basis.
- Missing, malformed, or mixed-basis input: reject rather than repair silently.
Formula and symbols
| Symbol | Meaning | Unit |
|---|---|---|
| high inside the active window | price units | |
| low inside the active window | price units | |
| highest high in the window | price units | |
| lowest low in the window | price units | |
| arithmetic midpoint of U and D | price units |
Calculate it by hand
For a three-row window, highs are [12, 15, 14] and lows are
[9, 11, 10].
- Upper channel:
max(12, 15, 14) = 15. - Lower channel:
min(9, 11, 10) = 9. - Middle:
(15 + 9) / 2 = 12. - Width:
15 - 9 = 6.
If the next row arrives, the oldest high 12 and low 9 leave the window. The lower boundary changes if no tied 9 remains. The middle moves even if the upper boundary stays fixed.
That calculation is deliberately small enough to audit without code. The 240-row fixtures then show how the same rule behaves through warm-up, regime changes, ties, gaps, shocks, and expiry.
The complete algorithm
- Take the trailing n highs and lows, including the current row.
- Publish their maximum high and minimum low.
- Compute the midrange
(upper + lower) / 2and widthupper - lower. - On tied extrema, the value persists until the final tied owner expires.
- For a breakout detector, compare the current observation with the previous completed channel; do not silently change the channel formula.
The flow exposes the point where a result becomes unavailable, where recursive state begins, or where a rolling owner expires.
See the mechanism
The map connects formula terms to the exact data they consume.
Follow a complete causal trace
Only rows at or before the active observation may influence the displayed state. Warm-up is shown as unavailable rather than silently converted to zero.
Memory is part of the definition
Finite n-row ownership. A new extreme updates immediately; an old boundary changes only when its final owning observation expires.
The current high is always less than or equal to the current-inclusive upper channel. Therefore current high > current upper is impossible by construction.
This is why two indicators can react differently to the same shock even when their plotted bands appear similar.
Six ways to try to break it
| Scenario | Teaching job | Expected lesson |
|---|---|---|
breakout-ladder | Fresh-extreme ladder | New highs and lows update only the affected boundary. |
rolling-expiry | Rolling-window expiry | A boundary changes when its owning extreme leaves the window. |
tie-boundary | Tied-extreme boundary | The value survives until the last tied extreme expires. |
flat-channel | Flat channel | Upper, lower, and middle coincide with zero width. |
current-versus-prior | Current-window versus prior-window boundary | The current high can equal the current-inclusive upper channel; breakout logic must compare with a prior completed channel. |
responsive-ten | Responsive ten-bar channel | A shorter window accepts and expires extrema faster. |
Predict the active component before opening the lab. Then jump to the relevant checkpoint and inspect the formula trace rather than guessing from line shape.
Interactive laboratory
Open the Donchian Channels guided lab. It contains six 240-row scenarios. Change the period or multiplier where the formula exposes one; the lab recomputes immediately, stops playback, resets to an informative state, and preserves the same calculation path used by Step. Use the checkpoint selector to compare first publication, mechanism, boundary, memory, platform reconciliation, and mature state.
Production implementation
The Python and
TypeScript references
are topic-scoped and intentionally readable. They validate before calculating,
return aligned arrays, and use None/null for unavailable states. Shared
fixtures establish parity; independent family checks establish properties
without trusting either implementation as the oracle.
When production output disagrees with a chart, log:
- symbol and source ownership;
- timeframe, session, timestamp, and bar finality;
- adjustment basis;
- parameter values and first-ready index;
- the earliest divergent component;
- window inclusion, seed, denominator, multiplier, equality, and null policy;
- the earliest revised observation.
Compare, do not conflate
| Nearby topic | What changes |
|---|---|
| Bollinger Bands | use a mean and dispersion, not extremum ownership. |
| Keltner Channels | move recursively instead of expiring finite-window owners. |
| A breakout strategy | adds prior-window comparison and order rules outside this calculation. |
Misuse boundary
- Do not: Calling the midpoint a moving average of price.
- Do not: Testing breakout against the same current-inclusive boundary and expecting a strict exceedance.
- Do not: Ignoring tied extremes when diagnosing the exact expiry row.
The synthetic examples establish implementation behavior only. No historical association, transaction cost, out-of-sample result, or investment suitability claim is made.
Historical example decision
No named historical episode is used. The mechanism is learned more cleanly from controlled synthetic paths, and a named case would require point-in-time, licensed, adjustment-consistent OHLC evidence before publication.
Summary
You can now state the precise question Donchian Channels answers, calculate it, explain its memory, diagnose a platform mismatch, and separate a measurement from a trading claim. Use the family comparison rather than chart resemblance to choose the next concept.
Primary evidence
See the topic reference ledger for source roles, dates, and limitations.
Rendered from the canonical Mermaid sources linked by this article.
Donchian Channels calculation flow
Purpose: show the exact selected state, readiness branch, and output.
Takeaway: the formula, memory, and unavailable state are part of the contract, not chart formatting.
ReferencesPrimary sources and evidence notesExpand the source trail, evidence role, and limitations behind the engineering choices.
Expand the source trail, evidence role, and limitations behind the engineering choices.
Donchian Channels (DC)
- Organization or authors: TradingView
- Source type: Maintained platform documentation
- Publication, version, or access date: accessed 2026-07-26
- URL or identifier: Donchian Channels (DC)
- Accessed: 2026-07-26
- Jurisdiction: not jurisdiction-specific
- Evidence role: sourced definition, maintained implementation, or bounded historical context
- Supports: Documents highest-high, lowest-low, and midpoint channel formulas.
- Limitations: Breakout strategy timing is separated as a package-derived causal boundary.
A Century of Profitable Trends
- Organization or authors: CMT Association
- Source type: Institutional research paper
- Publication, version, or access date: 2026
- URL or identifier: A Century of Profitable Trends
- Accessed: 2026-07-26
- Jurisdiction: not jurisdiction-specific
- Evidence role: sourced definition, maintained implementation, or bounded historical context
- Supports: Provides historical context and describes highest-high/lowest-low Donchian boundaries.
- Limitations: Performance research is not reproduced or used as evidence that this implementation is profitable.
Public evidence boundary
The fixture is author-generated synthetic teaching material. Every displayed number is an author-derived calculation from those inputs. No provider observation, historical return, causal claim, forecast, or profitability result is published. Platform documentation supports only the named platform convention; local seeds, nulls, equality, and scope remain implementation choices.
Full dependency-light reference implementations in both supported languages.
function finite(v:number[],n:string){if(!Array.isArray(v)||!v.length||v.some(x=>!Number.isFinite(x)))throw new Error(`${n} must contain finite numbers`)}
function period(v:number,n="period"){if(!Number.isInteger(v)||v<1)throw new Error(`${n} must be a positive integer`)}
export function donchian_channels(high:number[],low:number[],p=20){finite(high,"high");finite(low,"low");period(p);if(high.length!==low.length||high.some((h,i)=>h<low[i]))throw new Error("high and low must align with high >= low");const upper:(number|null)[]=Array(high.length).fill(null),lower:(number|null)[]=Array(high.length).fill(null),middle:(number|null)[]=Array(high.length).fill(null),width:(number|null)[]=Array(high.length).fill(null);for(let i=p-1;i<high.length;i++){upper[i]=Math.max(...high.slice(i-p+1,i+1));lower[i]=Math.min(...low.slice(i-p+1,i+1));middle[i]=((upper[i] as number)+(lower[i] as number))/2;width[i]=(upper[i] as number)-(lower[i] as number)}return{upper,lower,middle,width}}
The embedded lab now expands to its full document height, keeping the article as the only scroll surface.