Donchian Channels mark the highest high and lowest low over a chosen number of bars, with a middle line halfway between them. A 20-period channel gives you a rolling price range. It can help define a breakout, but the boundary used for that breakout needs to come from the bars that existed before the signal.
That distinction explains a common frustration: price makes a new high, the upper line rises with it, and the finished candle appears to touch the channel rather than close above it. The line is doing its job. The current bar has become part of its own measurement.
Use the channel to describe the range, then specify which completed range your entry rule compares against. A current-bar plot and a prior-bar breakout threshold can be useful together without being the same series.
Donchian Channel formula: highs, lows and the midrange
Choose a lookback length N. The upper boundary is the highest high in those N bars. The lower boundary is their lowest low. The middle line is the average of those two boundary values.
Upper = highest high over N bars.
Lower = lowest low over N bars.
Middle = (Upper + Lower) ÷ 2.
Channel width = Upper − Lower.
This calculation uses extrema. It does not first calculate an EMA, a standard deviation or an ATR. The upper and lower lines can stay flat while prices move inside the range, then change abruptly when a new extreme enters or an old extreme leaves the lookback.
The middle line is a midrange. It is not the average of every closing price, and it is not the statistical median of those closes. Suppose three bars have a highest high of 110, a lowest low of 90, and closes of 105, 104 and 104. The channel middle is 100; the average close is approximately 104.3333. Those are different measurements.
A 20-period calculation means 20 bars of the selected calculation timeframe. On a five-minute chart using the chart timeframe, it follows five-minute bars. On a daily calculation, it follows daily bars. The number 20 does not retain the same elapsed time when you change the timeframe or session.
Why a close cannot exceed its own inclusive upper channel
For a conventional OHLC bar, the close cannot exceed that bar's high. If the upper channel includes the current high, the upper channel cannot be lower than that high. Consequently, the close is less than or equal to the high, which is less than or equal to the inclusive upper boundary.
Current close ≤ current high ≤ current-inclusive upper channel. The lower side has the equivalent relationship: current close ≥ current low ≥ current-inclusive lower channel. A strict close outside these inclusive boundaries is impossible under that definition.
For a breakout rule, compare the current close with the highest or lowest value from the previous N completed bars. At bar t, those previous bars are t−1 through t−N. A current-inclusive N-bar plot instead uses t through t−N+1. One bar enters, one leaves, and the two windows have different endpoints.
TradingView's Pine execution documentation confirms that ta.highest(high, 20) compares the current high with the previous 19 highs. A history reference to the preceding result, such as ta.highest(high, 20)[1] when calculated consistently on every bar, gives the completed channel value from one bar earlier.
With a fixed 20-bar length and sufficient history, that preceding value covers the previous 20 bars. Keep the calculation in a consistent scope and require enough completed observations. An incomplete opening lookback should not quietly become a different strategy.
A worked breakout example separates the two boundaries
Use N=3 to make the window easy to check. Suppose the previous three highs are 100, 99 and 98, and the previous lows are 95, 96 and 95.5. The completed prior upper is 100 and the completed prior lower is 95.
The new bar reaches 103 and closes at 102. The condition “close above the previous three-bar high” is true because 102 is greater than 100. The current-inclusive upper becomes 103, so the close remains below the line drawn from the new window.
The downside works the same way. If the previous lower is 95 and the new bar trades down to 93 before closing at 94, the close is below the prior lower. The inclusive lower updates to 93, leaving that close above the new lower line. The direction of the trade changes; the indexing issue does not.
Now change the first example to a high of 103 and a close of 99. Price traded beyond the old upper, but it did not close beyond it. That is a wick breakout under an intrabar rule and a failed qualification under a strict close rule. A close exactly at 100 also fails a strict greater-than condition.
Choose whether the event requires a touch, a strict break, a close, or a defined number of ticks beyond the old level. Those choices produce different signals. Write the comparison before reviewing the outcome.
TradingView Donchian Channels settings
Open Indicators, search for Donchian Channels, and select the built-in indicator. Open its settings beside the indicator name. A community strategy can use displaced windows, extra filters or different entry rules even when “Donchian” appears in its title.
| Input | Baseline | What to record |
|---|---|---|
| Length | 20 | The number of bars in each high-low lookback |
| Offset | 0 | Where the calculated series is displayed |
| Timeframe | Chart | The timeframe supplying the observations |
| Wait for timeframe closes | Relevant when using a higher calculation timeframe | Whether values wait for the higher-timeframe bar to finish |

The official Donchian Channels manual lists Length 20 and Offset 0 as the defaults. Keep those as a recorded baseline while learning how the inclusive plot changes. Show both boundaries, use a distinct middle line, and keep the fill light enough to read the candles.
The TradingView indicators guide covers choosing and organizing indicators by the question each one answers. For Donchian, the useful question is which highs and lows define the current range, rather than how many additional lines can confirm a trade.
Plot offset and historical data references do different jobs
A display offset changes the location at which a calculated value appears. Moving a completed channel value one bar to the right can make the prior boundary visible beside the current candle. It does not change the underlying formula into a forecast.
A strategy condition should explicitly reference the intended historical boundary. Merely setting a plotted offset does not rewrite an expression elsewhere in a script. A chart can look correctly displaced while its entry calculation still compares the close with an inclusive current-bar maximum.
Platform labels also need context. TradingView's plot displacement and another platform's “offset” for selecting historical observations need not use the same sign convention or describe the same operation. Check what the field actually controls before transferring a signed value between platforms.
When the channel is calculated on a higher timeframe, the current higher-timeframe high and low can continue developing. A five-minute candle should not be tested against an hourly boundary that became known only at the end of that hour. Record the calculation timeframe and confirmation setting with the entry rule.
An old extreme can leave without a new price move
A rolling channel can narrow because an old high or low stops belonging to its window. That is different from a new breakout or a sudden change in the latest close.
Take three hypothetical bars with highs 110, 106 and 105, lows 90, 99 and 100, and closes 105, 104 and 104. The first bar supplies both extremes. Upper is 110, lower is 90, middle is 100 and width is 20.
A new bar has high 104, low 101 and close 104. When the oldest bar leaves the three-bar lookback, the remaining highs are 106, 105 and 104, while the remaining lows are 99, 100 and 101. Upper becomes 106, lower 99, middle 102.5 and width 7. The last close is still 104.
The channel contracted and its middle moved even though the newest close repeated the preceding close. The calculation is describing a different collection of extremes. Treat the width change as a historical range observation, rather than proof that the next candle must expand in a particular direction.
If you normalize width by the middle value, state whether the display is a ratio or a percentage. A zero middle makes that particular normalization undefined. Raw width remains upper minus lower and keeps the instrument's price units.
A Donchian Channel strategy needs more than a breakout line
A testable close-based rule might require a completed close above the prior 20-bar high, then enter using the next available execution. A downside rule can mirror it below the prior low. Specify the entry order, any directional filter, the invalidation level and the exit rule separately.
If the closing price creates the signal, that final price is known only after the candle finishes. The next tradable price can differ from it. A backtest that identifies a finished breakout and grants an earlier intrabar fill uses information that was not yet available at that earlier time.
For an illustrative long setup, suppose the signal closes above the old upper and the chosen invalidation is below the signal candle's low. Measure from the planned entry to that invalidation before choosing quantity. A later entry after a gap changes that distance; the original signal close does not preserve the original risk automatically.
A retest entry is another rule. It can offer a different distance to invalidation, but some breakouts never return to the old boundary. Count those missed trades honestly. Combining a breakout entry's earliest fill with a retest entry's later, tighter stop does not describe one executable setup.
New-high conditions and crossover events are not identical
Price can close above the prior upper on consecutive bars. In the worked example, the first close is 102 against a prior upper of 100. If the next bar closes at 104 after the channel upper has reached 103, the second close also exceeds its prior upper.
A crossover test adds a requirement about the previous relation: the previous close must have been at or below the comparator used on that previous bar. Because 102 was already above 100, the next true new-high condition need not be another crossover event.
Decide whether the strategy wants every qualifying new high, the first crossing after an inside state, or one entry while no position is open. Position eligibility, re-entry and pyramiding are additional rules. Using the word “breakout” does not settle them.
False breakouts need an invalidation chosen before entry
A range can produce repeated new highs and lows without a sustained move. A strict close rule filters out some wick-only events, but it cannot guarantee continuation. One qualifying candle can still be followed by a close back inside the old range.
For example, a rule could treat a close back below the broken upper as failure, or use a fixed protective stop below the signal structure. Those are different exits with different timing and risk. Specify whether the protective stop remains active while a close-based failure condition waits for the candle to finish.
Keep the reference level clear after entry. The old boundary that was broken is a known price. The moving channel continues to replace observations. Switching from the old level to a new, more convenient level after a losing candle changes the trade you originally planned.
The ATR guide explains another way to describe recent range and evaluate stop distances. ATR can be an additional distance input, but increasing the stop distance still requires recalculating size within the chosen money-risk allowance.
Entry and exit channels can use different lengths
A strategy can enter from a longer breakout lookback and exit using a shorter opposite boundary. For example, a test might compare a 20-bar entry range with a 10-bar exit range. These are illustrative choices, rather than a complete named trading system.
A shorter exit window can react sooner to a pullback, while a longer exit can retain more of a trend and give back more unrealized profit. The middle line is another possible reference. Choose one rule for a comparison instead of selecting whichever exit looks best after each trade.
A trailing stop also needs an update convention. Suppose an illustrative long stop starts at 96 and successive eligible channel levels are 94, 98 and 97. A rule that takes the greater of the previous stop and the new eligible level produces 96, 98 and 98. It tightens when permitted and does not loosen.
That ratchet is a strategy choice, not a property supplied by drawing a channel. State when a level becomes eligible and when the updated order can take effect. Following a current lower band downward during a losing bar can expand risk instead of limiting it.
Donchian, Bollinger and Keltner measure different things
Donchian uses the highest and lowest observations in its window. Standard Bollinger Bands use an average and price dispersion. Modern Keltner Channels commonly use an average with an ATR-based distance. Similar-looking envelopes can therefore respond differently to the same bars.
The Bollinger Bands guide covers standard deviation, %B and BandWidth. Those measures describe dispersion and relative location; they do not turn the Donchian midrange into an average close.
The Keltner Channels guide explains separate EMA and ATR lengths and the two-boundary Bollinger/Keltner squeeze. Donchian's high-low range requires neither of those lengths. Choose the tool for the question and keep each definition visible when comparing them.
Risk, costs and parameter testing decide whether a setup is usable
A shorter Donchian lookback follows a more recent collection of extremes. A longer one covers more history. At the same point in time, the longer range includes at least as much history, so its upper cannot be below the shorter upper and its lower cannot be above the shorter lower when the inputs and window endpoints match.
That nesting describes the calculation; it does not establish an optimal period. Compare a small set of lengths on the intended symbol, timeframe and session. Keep validation data separate from parameter selection and include commissions, spread and adverse execution assumptions.
Calculate quantity from the planned entry-to-stop distance, the instrument's money value per unit and costs. The position sizing calculator guide covers whole-contract rounding and a zero result when the minimum permitted quantity exceeds the budget.
Then control repeated attempts. Several failed breakouts can consume a session allowance even when every trade respects its individual stop. For a prop firm evaluation, compare the strategy's planned exposure with the applicable loss rules before paying for a plan.

Compare HDP discounts
Lucid 30% · Tradeify 30% · TPT 50%.
See current offers ↗Eligible partner plans only.
Record net expectancy, drawdown, losing streaks and sample size alongside win rate. There is no universal Donchian win rate: results depend on the market, dates, entry, exit and cost model. A percentage from one backtest does not describe every strategy that draws the same channel.
For each potential trigger, save the prior upper and lower, current high, low and completed close, signal time, planned fill and actual or modeled fill. Keep rejected signals and missed retests in the record too. This makes an indexing error visible: a row can show close 102 above a prior upper of 100 while the final plot correctly shows an upper of 103. It also separates a rule that never qualified from a valid signal that received a different execution price.
Donchian Channels FAQ
What is a Donchian Channel?
It is a rolling highest-high and lowest-low range with a middle line halfway between the boundaries. The lookback length determines which bars contribute their extremes.
What is the Donchian Channel formula?
Upper is the highest high over N bars, lower is the lowest low, and middle is their sum divided by two. State whether the window includes the current bar.
Is the middle line a moving average?
No. It is the midrange of two extremes. It does not average every closing price and is not the statistical median of the closes.
Why does price touch the upper line instead of closing above it?
If the current high belongs to the channel, the upper updates to include that high. A conventional close cannot exceed its own high. Compare the close with the prior completed range for a strict close breakout.
How do I define a Donchian breakout?
One close-based definition compares the current completed close with the highest high or lowest low of the previous N completed bars. Intrabar, touch and tick-buffer rules are different definitions.
What are the TradingView default settings?
The built-in manual specifies Length 20 and Offset 0. The official Inputs image also shows the chart timeframe and the higher-timeframe confirmation option.
Does Offset 1 change a strategy's calculation?
A plot offset changes the displayed location. It does not rewrite a separate entry expression. Reference the intended prior channel value explicitly when defining a strategy condition.
Can the channel narrow while the latest close stays unchanged?
Yes. An old extreme can leave the rolling window. The highest high, lowest low and midrange can change even when the newest close repeats the previous close.
What are the best Donchian Channel settings?
There is no universal optimum. Use a recorded baseline and test a small set of alternatives for the intended market, session, timeframe and execution costs on separate validation data.
Is Donchian better than Bollinger Bands?
They measure different inputs. Donchian uses extrema; standard Bollinger Bands use price dispersion around an average. Evaluate either within a defined entry, exit and risk model.
Can I use separate entry and exit channels?
Yes. A strategy can use one lookback for entry and another for exit. Record both lengths, the referenced bars, protective stop and update timing before comparing results.
Does a narrow channel predict the next direction?
No. It describes a small historical high-low range under the chosen settings. It does not guarantee a breakout direction, timing or size.
Do Donchian Channels repaint?
Current-bar extremes can change while that bar develops. Higher-timeframe values can also remain unconfirmed until the higher bar closes. Distinguish these updates from confirmed-bar calculations.
What is the win rate of a Donchian strategy?
The indicator has no universal win rate. A result belongs to specific entry and exit rules, data, dates and costs; assess expectancy and drawdown as well as the fraction of winning trades.
