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, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.