OPEN-SOURCE SCRIPT
Donchian Quantile Channel [forexobroker]

Donchian Quantile Channel [forexobroker] replaces the classic Donchian min/max envelope with robust order-statistics. The upper rail is the 90th-percentile high, the lower rail is the 10th-percentile low, and the middle spine is the 50th-percentile close, all measured over the same lookback. Channel width is then ranked against its own 200-bar history to mark expansion versus compression. Breakouts only fire when the channel is in the expansion half of its own history, which screens out quiet-channel pokes that classic Donchian treats the same as real range breaks.
🔶 ALGORITHM
1. A lookback N (default 50) defines the quantile window.
2. Upper rail = percentile_nearest_rank(high, N, 90); spine = percentile_nearest_rank(close, N, 50); lower rail = percentile_nearest_rank(low, N, 10). Using percentile_nearest_rank ignores single extreme prints that would otherwise pin a min/max envelope.
3. Width = upper - lower, ranked over the width-rank lookback (default 200 bars) using percentrank.
4. The expansion gate compares the current width rank to the Min Width Rank input (default 50). Above the threshold means the channel is wider than half its own history.
5. Crossovers of close against the upper or lower rail are detected with crossover/crossunder.
6. Signals only fire when a rail is broken inside the expansion regime, position state is flat or opposite, cooldown is satisfied and barstate.isconfirmed is true.
🔶 SIGNAL LOGIC
- Buy: close crosses above the upper quantile AND width rank is above the minimum AND session filter passes AND not already long AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: close crosses below the lower quantile AND width rank is above the minimum AND session filter passes AND not already short AND cooldown bars elapsed AND barstate.isconfirmed.
A single posState flag prevents same-side re-entry until the opposite signal resets it.
🔶 INPUTS
- Channel group: quantile lookback N default 50, upper percentile default 90, middle default 50, lower default 10, width-rank lookback default 200.
- Signal Logic group: min width rank percent (default 50) for the expansion gate, cooldown bars default 15.
- Filters group: session restriction toggle off by default with a 0000-2400 default window.
- Visual group: gradient fill, dashboard, 3-layer glow toggles plus full color overrides and dashboard background.
🔶 ALERTS
DQC Buy, DQC Sell, DQC Any Signal, DQC Upper Break, DQC Lower Break, DQC Spine Cross Up, DQC Spine Cross Dn, DQC Expansion, DQC Compression, DQC Extreme Width, DQC Extreme Squeeze, DQC Webhook JSON.
🔶 LIMITATIONS
- Percentile rails are step-like; on short lookbacks they move only when a window slot rolls off, so the channel can sit flat for several bars even as price moves.
- The expansion gate hides breakouts in quiet markets; on instruments that habitually trend on low realised range the filter will skip valid trades.
- Cooldown is a fixed bar count; it does not adapt to timeframe shifts.
- Percentiles are non-anticipatory but the channel itself only stabilises once N bars of history exist; early history shows wider, less reliable rails.
- The instrument target is ES; on illiquid symbols the upper/lower rails can be pinned to the same single print across multiple bars.
🔶 ALGORITHM
1. A lookback N (default 50) defines the quantile window.
2. Upper rail = percentile_nearest_rank(high, N, 90); spine = percentile_nearest_rank(close, N, 50); lower rail = percentile_nearest_rank(low, N, 10). Using percentile_nearest_rank ignores single extreme prints that would otherwise pin a min/max envelope.
3. Width = upper - lower, ranked over the width-rank lookback (default 200 bars) using percentrank.
4. The expansion gate compares the current width rank to the Min Width Rank input (default 50). Above the threshold means the channel is wider than half its own history.
5. Crossovers of close against the upper or lower rail are detected with crossover/crossunder.
6. Signals only fire when a rail is broken inside the expansion regime, position state is flat or opposite, cooldown is satisfied and barstate.isconfirmed is true.
🔶 SIGNAL LOGIC
- Buy: close crosses above the upper quantile AND width rank is above the minimum AND session filter passes AND not already long AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: close crosses below the lower quantile AND width rank is above the minimum AND session filter passes AND not already short AND cooldown bars elapsed AND barstate.isconfirmed.
A single posState flag prevents same-side re-entry until the opposite signal resets it.
🔶 INPUTS
- Channel group: quantile lookback N default 50, upper percentile default 90, middle default 50, lower default 10, width-rank lookback default 200.
- Signal Logic group: min width rank percent (default 50) for the expansion gate, cooldown bars default 15.
- Filters group: session restriction toggle off by default with a 0000-2400 default window.
- Visual group: gradient fill, dashboard, 3-layer glow toggles plus full color overrides and dashboard background.
🔶 ALERTS
DQC Buy, DQC Sell, DQC Any Signal, DQC Upper Break, DQC Lower Break, DQC Spine Cross Up, DQC Spine Cross Dn, DQC Expansion, DQC Compression, DQC Extreme Width, DQC Extreme Squeeze, DQC Webhook JSON.
🔶 LIMITATIONS
- Percentile rails are step-like; on short lookbacks they move only when a window slot rolls off, so the channel can sit flat for several bars even as price moves.
- The expansion gate hides breakouts in quiet markets; on instruments that habitually trend on low realised range the filter will skip valid trades.
- Cooldown is a fixed bar count; it does not adapt to timeframe shifts.
- Percentiles are non-anticipatory but the channel itself only stabilises once N bars of history exist; early history shows wider, less reliable rails.
- The instrument target is ES; on illiquid symbols the upper/lower rails can be pinned to the same single print across multiple bars.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script open-source
Nello spirito di TradingView, l'autore di questo script lo ha reso open source, in modo che i trader possano esaminarne e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricordiamo che la ripubblicazione del codice è soggetta al nostro Regolamento.
🔵Gain access to our powerful tools : forexobroker.com/tv
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
🔵Join our free telegram for updates : t.me/dominicwalsfxhtrader
All scripts & content provided by Forexobroker are for informational & educational purposes only.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.