Volatility
Donchian Breakout Signals: Use the Prior Channel
Build Donchian breakout conditions against prior completed bars. Compare close and wick tests and define a failed break without impossible current-bar comparisons.
Donchian Channel Signal Interpretation
Quick-reference guide to 6 signal types you will see on the chart.
| Signal Type | Indicator Condition | Market Meaning | Interpretation limits |
|---|---|---|---|
| Upper breakout | Close, or high in wick mode, exceeds the highest high of the previous N completed bars | A new extreme relative to an already known boundary. | The same-bar highest high cannot be strictly below that bar’s close. |
| Lower breakout | Close, or low in wick mode, falls below the lowest low of the previous N completed bars | A corresponding downside event. | A break does not establish continuation. |
| Midpoint reference | Average of the prior upper and lower boundaries | Center of the selected extreme-price range. | Not a moving average of all closes or guaranteed support. |
| Next-bar failed upper break | Prior bar was an upper break; current close returns below the upper boundary used for that break | A precisely defined one-bar failure test. | Not proof that traders were trapped or that a short will profit. |
| Next-bar failed lower break | Prior bar was a lower break; current close returns above its original lower boundary | The opposite one-bar failure test. | Other failure windows require a different rule. |
| Channel width | Prior upper boundary minus prior lower boundary | Distance between the selected extremes. | Expansion can follow a new extreme; it cannot certify a genuine breakout. |
Donchian Channel Pine Script Signal Code
Educational indicator example. Review its exact rules and compare its plots with your intended calculation in TradingView. It does not place orders or establish profitability.
Pine Script v6
//@version=6
indicator("Prior Donchian Channel Event Examples", overlay=true)
length = input.int(20, "Channel Length", minval=1)
closeOnly = input.bool(true, "Require Close Beyond Boundary")
showMiddle = input.bool(true, "Show Midpoint")
upper = ta.highest(high, length)[1]
lower = ta.lowest(low, length)[1]
midpoint = (upper + lower) / 2.0
upBreak = barstate.isconfirmed and (closeOnly ? close > upper : high > upper)
downBreak = barstate.isconfirmed and (closeOnly ? close < lower : low < lower)
failedUp = barstate.isconfirmed and upBreak[1] and close < upper[1]
failedDown = barstate.isconfirmed and downBreak[1] and close > lower[1]
pUpper = plot(upper, "Prior channel upper", color=color.blue)
pLower = plot(lower, "Prior channel lower", color=color.blue)
plot(showMiddle ? midpoint : na, "Prior channel midpoint", color=color.gray)
fill(pUpper, pLower, color=color.new(color.blue, 92))
plot(upper - lower, "Prior channel width", display=display.data_window)
plotshape(upBreak, "Upper break", shape.triangleup, location.belowbar, color=color.green, size=size.small)
plotshape(downBreak, "Lower break", shape.triangledown, location.abovebar, color=color.red, size=size.small)
plotshape(failedUp, "Next-bar failed upper break", shape.xcross, location.abovebar, color=color.orange, size=size.tiny)
plotshape(failedDown, "Next-bar failed lower break", shape.xcross, location.belowbar, color=color.aqua, size=size.tiny)
alertcondition(upBreak, "Upper channel break", "Confirmed bar exceeds the prior completed-bar upper channel under the selected mode")
alertcondition(downBreak, "Lower channel break", "Confirmed bar exceeds the prior completed-bar lower channel under the selected mode")
alertcondition(failedUp, "Next-bar failed upper break", "Close returns below the upper boundary used by the previous bar's breakout")
alertcondition(failedDown, "Next-bar failed lower break", "Close returns above the lower boundary used by the previous bar's breakout")Example settings for Donchian Channel
Record the inputs used by the example. These settings are not an optimized trading recommendation.
| Parameter | Default | Description |
|---|---|---|
| Channel Length | 20 bars, example | Bars are not automatically days. The calculation excludes the current bar by taking the previous completed value. |
| Require Close Beyond Boundary | Enabled | Close mode and wick mode test different observations. Both marker types wait for the bar to finish in this example. |
| Show Midpoint | Enabled | Visibility only; it does not enable a pullback trading algorithm. |
| Failure window | Next bar only | Checks the boundary used for the previous break. It does not search any point within an adjustable two-to-five-bar window. |
Turn the condition into an explicit rule
Specify the calculation, confirmation time, entry and exit rules before asking Pineify to draft or revise Pine Script. Review the code and simulate realistic costs before evaluating a strategy.
Explore Pine Script codingOfficial calculation and usage references
FAQ
Donchian Channel Signals FAQ
Why would a Donchian breakout script never signal?
If the upper channel includes the current high, close cannot be greater than that highest high on ordinary OHLC bars. The lower comparison has the symmetric problem. Use a prior known boundary when the rule is a breakout beyond previous bars.
Is a wick touch the same as a breakout?
No. This example requires a strict move beyond the prior boundary. Equality is a touch. Wick mode can signal even when the bar closes back inside; close mode requires a close beyond it.
Does a 20-period channel mean twenty trading days?
Only on the relevant daily chart. On a five-minute chart it means twenty five-minute bars. Session settings and gaps also affect which observations are available.
Can channel expansion validate a breakout?
It describes how the extreme range changed. It does not measure the probability of continuation. Any filter needs its own definition and evaluation.
How does the failed-break rule avoid hindsight?
It waits until the next bar closes and compares that close with the original boundary used by the breakout. It does not move the marker back to the earlier breakout bar or claim the failure was known then.
What must I add before measuring performance?
Specify entries, exits, sizing and costs, including whether consecutive breakout bars permit additional entries. This indicator contains no trade execution or verified backtest sample.