OPEN-SOURCE SCRIPT
Gaspard98 - Donchian Channel - Trend Colored - Highs / Lows

> **Donchian Channel — Trend-Colored - Highs / Lows**
>
> This indicator plots a classic **Donchian Channel** (highest high / lowest low over *N* bars) and dynamically colors it based on the **current market structure** — bullish or bearish — making trend direction instantly readable at a glance.
>
> ---
>
> **How it works**
>
> The channel is drawn using:
> - **Upper band** — highest `high` over the chosen period
> - **Lower band** — lowest `low` over the chosen period
> - **Median line** — midpoint of the two bands
>
> Trend state is updated on every bar:
> - A **new swing high** (upper band expanding) flips the state to **bullish** → channel turns green
> - A **new swing low** (lower band expanding) flips the state to **bearish** → channel turns red
> - Bearish signals take **priority** over bullish signals on the same bar
>
> ---
>
> **Settings**
>
> | Parameter | Default | Description |
> |---|---|---|
> | Period | 20 | Lookback length for the channel |
> | Show bands | ✅ | Toggle upper/lower band visibility |
> | Show median | ✅ | Toggle midline visibility |
> | Show background | ✅ | Toggle shaded fill between bands |
> | Bullish color | Green | Color when structure is bullish |
> | Bearish color | Red | Color when structure is bearish |
>
> ---
>
> **Use cases**
> - Quickly identify whether price is making new highs or new lows within any timeframe
> - Use the median as a dynamic support/resistance or trend filter
> - Combine with momentum indicators (RSI, MACD) for confirmation entries
> - Works on any asset and any timeframe
>
> ---
>
> *Based on the original Donchian Channel concept by Richard Donchian. No repainting — all calculations are based on confirmed bar data.*
>
> This indicator plots a classic **Donchian Channel** (highest high / lowest low over *N* bars) and dynamically colors it based on the **current market structure** — bullish or bearish — making trend direction instantly readable at a glance.
>
> ---
>
> **How it works**
>
> The channel is drawn using:
> - **Upper band** — highest `high` over the chosen period
> - **Lower band** — lowest `low` over the chosen period
> - **Median line** — midpoint of the two bands
>
> Trend state is updated on every bar:
> - A **new swing high** (upper band expanding) flips the state to **bullish** → channel turns green
> - A **new swing low** (lower band expanding) flips the state to **bearish** → channel turns red
> - Bearish signals take **priority** over bullish signals on the same bar
>
> ---
>
> **Settings**
>
> | Parameter | Default | Description |
> |---|---|---|
> | Period | 20 | Lookback length for the channel |
> | Show bands | ✅ | Toggle upper/lower band visibility |
> | Show median | ✅ | Toggle midline visibility |
> | Show background | ✅ | Toggle shaded fill between bands |
> | Bullish color | Green | Color when structure is bullish |
> | Bearish color | Red | Color when structure is bearish |
>
> ---
>
> **Use cases**
> - Quickly identify whether price is making new highs or new lows within any timeframe
> - Use the median as a dynamic support/resistance or trend filter
> - Combine with momentum indicators (RSI, MACD) for confirmation entries
> - Works on any asset and any timeframe
>
> ---
>
> *Based on the original Donchian Channel concept by Richard Donchian. No repainting — all calculations are based on confirmed bar data.*
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน