Donchian Ribbon [UAlgo]Donchian Ribbon is a chart-overlay Donchian Channel ribbon that visualizes multiple lookback lengths at the same time. Instead of plotting a single Donchian Channel, the script builds a fixed stack of channels that increase in length and blends them into a clean, layered ribbon above and below price using progressive fills.
The goal is to make market structure and regime easier to read without clutter:
- When the ribbon expands and stays orderly (fast boundaries leading, slow boundaries following), it often reflects sustained range expansion and more directional flow.
- When the ribbon compresses and bands overlap frequently, it typically reflects consolidation, rotational behavior, and reduced clarity.
- The slowest channel provides the structural “outer frame” of the market’s recent range, while shorter channels react first and show how quickly the range is shifting.
This indicator is designed as a context tool. It does not attempt to “predict” direction by itself, but it gives a high-quality visual map of evolving highs/lows across multiple sensitivities so you can align entries, risk, and expectations with the current regime.
🔹 Features
1) Multi-Length Donchian Stack (Ribbon Engine)
The script constructs several Donchian Channels from a Base Length and a Step Length. Each band represents a different sensitivity level:
- Fast bands respond quickly to recent highs and lows.
- Slow bands respond more conservatively and define broader containment.
By stacking these lengths together, you can see short-term responsiveness and higher-level structure simultaneously.
2) Two-Sided Ribbon (Upper and Lower Envelopes)
The indicator visualizes both sides of the Donchian framework:
- Upper ribbon is built from stacked Donchian highs (highest highs per length).
- Lower ribbon is built from stacked Donchian lows (lowest lows per length).
This keeps interpretation intuitive: price pressing into the upper ribbon suggests pressure toward recent highs, while leaning into the lower ribbon suggests pressure toward recent lows.
3) Gradient Depth via Layered Fills (Clean Charts)
Instead of drawing many lines, the script fills the space between consecutive bands. Transparency is gradually adjusted from the fast band to the slow band, producing a smooth depth effect that stays readable even on busy charts.
Intermediate plots are intentionally hidden so the ribbon remains the main visual output.
4) Regime Readability (Expansion vs Compression)
Because each band has a different lookback length, the ribbon naturally communicates volatility and state:
- Expansion: spacing between fast and slow bands increases, commonly seen in stronger directional phases.
- Compression: spacing collapses and bands cluster, commonly seen in ranges, pauses, or choppy rotation.
This helps you quickly decide whether to treat price action as breakout-oriented, trend-continuation, or mean-reverting.
5) Trend Baseline Reference (Slow Midpoint)
A baseline is plotted using the midpoint of the slowest channel. This provides a stable reference that helps you judge whether price is operating in the upper or lower half of the broader range structure.
🔹 Calculations
1) Donchian High, Low, and Midpoint Per Band
Each Donchian band is computed from its own length:
- High = highest high over the lookback length
- Low = lowest low over the lookback length
- Mid = average of High and Low
id.high := ta.highest(id.length)
id.low := ta.lowest(id.length)
id.mid := math.avg(id.high, id.low)
2) Length Sequencing (Base Length + Step Length)
The indicator creates a fixed number of bands. Lengths are built as:
- Band 1: base_length
- Band 2: base_length + step_length
- Band 3: base_length + 2 * step_length
- ...
- Final band: base_length + (ribbon_count - 1) * step_length
This yields a consistent progression from fast to slow sensitivity.
int len = base_length + (i * step_length)
channels.push(DonchianChannel.new(len))
3) Iterative Updates with Arrays and Methods
All bands are stored in an array and updated every bar using a unified method call. This ensures every band follows identical rules and makes the logic scalable and maintainable.
for dc in channels
dc.update()
4) Upper Ribbon Construction (Layered Fills Between Highs)
The upper ribbon is created by filling between consecutive Donchian highs. Each layer uses the same upper tone with progressively stronger visibility toward the slow band.
fill(p_fast_high, p_mid1_high, color.new(col_upper, 90), "Ribbon Upper 1")
fill(p_mid1_high, p_mid2_high, color.new(col_upper, 80), "Ribbon Upper 2")
fill(p_mid2_high, p_mid3_high, color.new(col_upper, 70), "Ribbon Upper 3")
fill(p_mid3_high, p_slow_high, color.new(col_upper, 60), "Ribbon Upper 4")
5) Lower Ribbon Construction (Layered Fills Between Lows)
The lower ribbon is created by filling between consecutive Donchian lows with the lower tone, again using progressive transparency.
fill(p_fast_low, p_mid1_low, color.new(col_lower, 90), "Ribbon Lower 1")
fill(p_mid1_low, p_mid2_low, color.new(col_lower, 80), "Ribbon Lower 2")
fill(p_mid2_low, p_mid3_low, color.new(col_lower, 70), "Ribbon Lower 3")
fill(p_mid3_low, p_slow_low, color.new(col_lower, 60), "Ribbon Lower 4")
6) Trend Baseline (Slow Midpoint)
The baseline is the midpoint of the slowest Donchian band, plotted as a stable center reference for the broadest range framework.
plot(dc_slow.mid, "Trend Baseline",
color = color.from_gradient(0.5, 0, 1, col_lower, col_upper),
linewidth = 2)
7) Visualization Choice (Hidden Internals, Visible Structure)
To keep charts clean, most intermediate plots are hidden and the ribbon fills do the heavy lifting visually, while the slow boundaries remain visible as the outer frame.
p_fast_high = plot(dc_fast.high, "Fast High", color = color.new(col_upper, 80), display = display.none)
p_fast_low = plot(dc_fast.low, "Fast Low", color = color.new(col_lower, 80), display = display.none)
p_slow_high = plot(dc_slow.high, "Slow High", color = color.new(col_upper, 50))
p_slow_low = plot(dc_slow.low, "Slow Low", color = color.new(col_lower, 50))
Pine Script® göstergesi






















