[blackcat] L2 Better Donchian Trend Ranges

2 495
█ OVERVIEW

Better Donchian Trend Ranges rebuilds the classic Donchian channel into an adaptive trend-following system: a stepped basis with ATR hysteresis freezes sideways noise, robust percentile extremes remove spike distortion, and dual-zone bands frame trend ranges. Version 2 adds a signal engine: state-machine entries/exits, cooldown governance, ATR stop-loss/take-profit levels, labels, a dashboard and 10 alert channels.

█ CONCEPTS

• Robust Donchian extremes: channel borders use percentile-filtered highs/lows (Robust Extremes %), so single-bar spikes no longer distort the range.
• Stepped basis with hysteresis: the midline only moves when price drifts further than Step Hysteresis x ATR, turning chop into flat steps.
• Two width engines: standard deviation (default) or an ATR Keltner hybrid; width refreshes only on each step, preserving the channel property.
• Dual-zone TP framing: every border splits into an inner and outer ATR-offset zone, producing weak and strong take-profit triggers.
• Signal governance (V2): a position state machine arbitrates every signal with same-bar entry/exit exclusivity and a cooldown window to suppress whipsaw flip-flops.

█ HOW TO USE

1 — Add the indicator to any chart; it overlays price. Defaults suit most liquid markets on 15m and higher timeframes.
2 — Read bias first: bars and basis color green in uptrends, red in downtrends; the background tint shows the current state (long/short/flat).
3 — Trade trend shifts: LE/SE labels mark governed long/short entries on basis crossovers.
4 — Exit into strength: XL/XS labels mark band take-profit exits — weak (inner zone) or strong (XL+/XS+, outer zone).
5 — ATR Stop Loss/Take Profit lines plot automatically while a position is active; tune them in the Risk group.
6 — Create alerts from the condition list: trend shifts, weak/strong TP zones, and governed Long/Short Entry & Exit events.

Input Parameters
• Donchian Length (50): lookback for extremes and basis.
• Range Multiplier (3): band width scaling.
• Step Hysteresis x ATR (0.35): deadband before the basis steps; higher = calmer.
• Robust Extremes % (5): percentile trimming of spikes; 0 = classic Donchian.
• Band Width Engine: ATR (off) + ATR Width Boost (1.5): Keltner-style width option.
• Same-bar Entry/Exit Exclusivity (on), Cooldown Bars (3), Exit on Opposite Trend Shift (off): signal governance.
• ATR Length (14), Stop Loss xATR (2.0), Take Profit xATR (3.0): risk reference levels.
• Visual toggles: signal labels, position background, bar coloring, dashboard, classic raw TP marks.

█ SIGNALS

• LE / SE labels: governed entries (trend shift accepted while flat or reversing).
• XL / XS labels: take-profit exits from the inner band zone (weak).
• XL+ / XS+ labels: take-profit exits from the outer band zone (strong).
• Background tint: green = long state, red = short state, none = flat.
• Dashed circles: midpoints of the transition zones between basis and bands.
• Dashboard: live position, trend bias, ATR, active TP/SL and cooldown remaining.
• 10 alertcondition channels plus dynamic per-event alert messages (once per bar close).

█ IMPLEMENTATION NOTES

• Pure Pine v6: ta.highest, ta.lowest, ta.percentile_nearest_rank, ta.atr, ta.stdev — no external data, no repainting security calls.
• All governed signals are edge-driven and settle on bar close; alert() fires once per confirmed bar, so nothing repaints intrabar.
• Core stepping idea:
Pine Script®


█ LIMITATIONS

• Trend-following by design: expect whipsaws in tight ranges; raise Hysteresis or Cooldown to compensate.
• Signals confirm on bar close; intrabar triggers may vanish.
• TP/SL lines are reference levels for manual trading — this is an indicator, not an auto-executing strategy.
• Best suited to liquid, trending markets on 15-minute and higher timeframes.

█ NOTES

• Engine unchanged from the original open-source script; governance, risk levels and visuals added.

═════════════════════════════════════════════════════════════════════════
For questions or feedback, use the comments section.
Feel free to use and modify.
Special thanks to Donchian Trend Ranges (AlgoAlpha) for the concept and inspiration.

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.