OPEN-SOURCE SCRIPT
ATR-limited Donchian Channel

The ATR-limited Donchian Channel is a modified version of the classic Donchian Channel that adapts more quickly to changing market conditions.
While a traditional Donchian Channel is based only on the highest high and lowest low over a given lookback period, this version introduces an ATR-based constraint that prevents the channel lines from extending too far away from price. This makes the channel more responsive and reduces lag compared to the standard Donchian Channel.

How it works
Why use this version?
Typical use cases
✅ This indicator is designed for traders who want the structure of a Donchian Channel but with an adaptive, volatility-sensitive adjustment that makes it react faster and more reliably than the classic version.
While a traditional Donchian Channel is based only on the highest high and lowest low over a given lookback period, this version introduces an ATR-based constraint that prevents the channel lines from extending too far away from price. This makes the channel more responsive and reduces lag compared to the standard Donchian Channel.
How it works
- The upper band is based on the highest high of the last N candles, but it cannot exceed a maximum distance of ATR × Factor above the current median price (midpoint of high and low).
- The lower band is based on the lowest low of the last N candles, but it cannot drop more than ATR × Factor below the median price.
- If the Donchian Channel would normally extend further than this ATR-limited boundary, the line is capped and marked in blue.
- Otherwise, the upper band is drawn in red and the lower band in green.
- A middle line is also plotted as the average of the modified upper and lower bands.
- An optional offset allows you to shift the channel backward or forward in time for easier visual alignment.
Why use this version?
- Faster reaction: By constraining the channel with ATR, the indicator adapts quicker to volatility changes and avoids long periods of overextended levels.
- Noise control: ATR filtering prevents extreme spikes or outlier highs/lows from stretching the channel unnecessarily.
- Visual clarity: Color-coding highlights when ATR filtering is active, making it easy to distinguish capped vs. natural Donchian levels.
Typical use cases
- Trend-following breakout systems, but with volatility-aware limits.
- Identifying dynamic support and resistance zones that adjust to market conditions.
- Filtering false breakouts by monitoring when the Donchian channel is capped by ATR.
✅ This indicator is designed for traders who want the structure of a Donchian Channel but with an adaptive, volatility-sensitive adjustment that makes it react faster and more reliably than the classic version.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.