OPEN-SOURCE SCRIPT

CRT - Candle Range Theory by agm

4 306
# CRT — Candle Range Theory (Trader DNA 5-Step Framework)

**An automated, multi-timeframe Candle Range Theory detector with full trade execution levels — Entry, Stop Loss, TP1, and TP2 — built on the Trader DNA 5-Step CRT framework and ICT Power of 3 (AMD) concepts.**

---

## What is Candle Range Theory?

Candle Range Theory (CRT) is a price action methodology rooted in ICT (Inner Circle Trader) concepts. It describes how institutional smart money moves price through three sequential candles:

- **C1 — Accumulation:** A "range candle" that defines the playing field. Its high sets the **CR (Candle Range High / Buy-side Liquidity)** and its low sets the **CRL (Candle Range Low / Sell-side Liquidity)**.
- **C2 — Manipulation:** Price breaks out of C1's range to sweep liquidity — then **closes back inside** the C1 range. This is the trap. It runs stops above (bearish) or below (bullish) before reversing.
- **C3 — Distribution:** Price delivers in the opposite direction of the C2 sweep. This is where the trade runs.

This three-candle sequence mirrors the **ICT Power of 3 (AMD)** — Accumulation, Manipulation, Distribution — and can be observed on any timeframe.

---

## What This Indicator Does

This indicator automatically scans a **Higher Timeframe (HTF)** of your choice for completed CRT patterns. When a valid pattern is detected, it draws every element you need to execute the trade directly on your chart:

- Shaded **Range Box** over the C1 candle (the accumulation range)
- **Premium Zone** (upper half — bearish bias)
- **Discount Zone** (lower half — bullish bias)
- **Equilibrium line** (50% of C1 range)
- **CR** and **CRL** dashed lines extended to the right
- **Entry line** — at C2 close price
- **Stop Loss line** — beyond the C2 manipulation wick (with adjustable buffer)
- **TP1** — Equilibrium (50% of range)
- **TP2** — Opposite extreme of the range (full CRT target)
- **R:R ratio** labels on TP1 and TP2
- **ACC / MAN** labels marking the Accumulation and Manipulation candles
- **LTF entry hint** reminding you to drop to your Lower Timeframe for confirmation
- **Triangle signal markers** on the chart bar where the pattern confirms
- **Alerts** for bearish, bullish, and any CRT pattern

All drawings use **real bar timestamps** (`xloc.bar_time`) so every box, line, and label stays perfectly anchored at any zoom level.

---

## The 5-Step Trade Framework

This indicator is built around the Trader DNA 5-Step CRT execution process:

**Step 1 — Define the Range**
C1's body and wicks define the CR (top wick = Buy-side liquidity) and CRL (bottom wick = Sell-side liquidity). The midpoint is the Equilibrium (EQ).

**Step 2 — Confirm AMD Pattern**
C2 must sweep beyond C1 (above CR for bearish, below CRL for bullish) and close back inside the C1 range. This confirms the manipulation and sets up C3 distribution.

**Step 3 — Timeframe Alignment**
The HTF (e.g. 1H, 4H, Daily) defines the pattern. The LTF (e.g. 5m, 15m) is where you enter. Drop to the LTF after a signal fires and wait for a **CHoCH (Change of Character)** or **FVG (Fair Value Gap)** to confirm the reversal before entering.

**Step 4 — Premium / Discount Zone Filter**
- **Bearish CRT** is only valid if C2 closes in the **Premium Zone** (above the 50% EQ) — you are shorting from a premium price.
- **Bullish CRT** is only valid if C2 closes in the **Discount Zone** (below the 50% EQ) — you are buying at a discount.
This filter is optional and can be toggled off in settings.

**Step 5 — External Context**
Always confirm that the pattern aligns with the broader market structure on a higher timeframe than your HTF. This indicator handles Steps 1–4 automatically. **Step 5 is your responsibility** — do not take CRT setups against a strong trend or major resistance/support on the HTF.

---

## Bearish CRT — Pattern Rules

| Condition | Description |
|-----------|-------------|
| C1 is bullish | Accumulation candle closes up |
| C2 is bearish | Manipulation candle closes down |
| C2 high > C1 high | Liquidity sweep above CR |
| C2 close < C1 high | Close back inside the range |
| C2 close ≥ C1 low | Did not close below the range |
| Zone filter (optional) | C2 close above 50% EQ (Premium) |

**Trade:** Short at C2 close → SL above C2 high → TP1 at EQ → TP2 at CRL

---

## Bullish CRT — Pattern Rules

| Condition | Description |
|-----------|-------------|
| C1 is bearish | Accumulation candle closes down |
| C2 is bullish | Manipulation candle closes up |
| C2 low < C1 low | Liquidity sweep below CRL |
| C2 close > C1 low | Close back inside the range |
| C2 close ≤ C1 high | Did not close above the range |
| Zone filter (optional) | C2 close below 50% EQ (Discount) |

**Trade:** Long at C2 close → SL below C2 low → TP1 at EQ → TP2 at CR

---

## Settings Guide

### ⏱ Timeframes

| Setting | Default | Description |
|---------|---------|-------------|
| HTF | 1H | The timeframe on which the CRT pattern is detected. Patterns are drawn based on completed HTF bars. |
| LTF | 5m | Your entry timeframe. Shown in the entry hint label as a reminder to switch down for confirmation. |

**Recommended HTF / LTF Pairings:**

| HTF | LTF | Style |
|-----|-----|-------|
| Daily | 1H or 4H | Swing trading |
| 4H | 15m or 1H | Intraday swing |
| 1H | 5m or 15m | Day trading |
| 15m | 1m or 3m | Scalping |

> **Important:** Always view the indicator on a chart timeframe **equal to or lower than your HTF**. For example, if HTF = 1H, use a 1m–1H chart. Using a 4H chart with HTF = 1H means 4H bars will not contain enough resolution to display the drawings accurately.

---

### 🟢 Signals

| Setting | Default | Description |
|---------|---------|-------------|
| Show Bullish CRT | On | Toggle bullish pattern detection and drawings |
| Show Bearish CRT | On | Toggle bearish pattern detection and drawings |
| Step 4: Require Premium/Discount Zone | On | When enabled, bearish signals only fire if C2 closes above EQ (Premium), and bullish signals only fire if C2 closes below EQ (Discount). Disable to see all patterns regardless of C2 close position. |

---

### 📐 Trade Levels

| Setting | Default | Description |
|---------|---------|-------------|
| Show Entry Line | On | Blue solid line at C2 close price — your entry level |
| Show Stop Loss | On | Orange dashed line beyond the manipulation wick |
| Show TP1 (EQ 50%) | On | First target at the range midpoint |
| Show TP2 (Range Extreme) | On | Full target at CRL (bearish) or CR (bullish) |
| SL Buffer (%) | 0.10% | Adds a small buffer beyond the wick for the SL to avoid getting stopped by spread or noise. Increase for volatile assets. |
| Show R:R Label | On | Displays the reward-to-risk ratio next to each TP label, e.g. `[2.1R]` |

---

### 🎨 Visuals

| Setting | Default | Description |
|---------|---------|-------------|
| Show Range Box | On | Shaded box covering the C1 candle from its high to low |
| Show Premium / Discount Zones | On | Upper half (Premium, red tint) and lower half (Discount, green tint) of the range |
| Show AMD Labels | On | Labels "ACC" on C1 and "MAN" on C2 |
| Show LTF Entry Hint | On | Adds the LTF timeframe name to the entry label as a reminder |
| Show Equilibrium Line | On | Dotted gold line at the 50% midpoint of C1 |
| Show CR / CRL Lines | On | Dashed lines at C1 high and C1 low extending right |
| Show Price Labels | On | Labels showing exact price of CR, EQ, and CRL |
| Show Triangle Signals | On | Red triangle above bar (bearish) or green triangle below bar (bullish) |
| Extend Lines (bars right) | 30 | How many current-chart bars the lines/labels extend to the right. Increase for more projection space. |

---

### 🎨 Colors

All colors are fully customizable. Defaults:
- **Bullish** — Bright green (`#00E676`)
- **Bearish** — Bright red (`#FF1744`)
- **Equilibrium** — Gold (`#FFD700`)
- **Entry** — Sky blue (`#29B6F6`)
- **Stop Loss** — Orange (`#FF6D00`)
- **TP1** — Light green (`#69F0AE`)
- **TP2** — Pale green (`#B9F6CA`)
- **Premium Zone** — Soft red
- **Discount Zone** — Soft green

**Box Fill Transparency** (default 88%) and **Zone Fill Transparency** (default 93%) let you control how opaque the filled boxes appear.

---

## How to Use — Step-by-Step

**1. Add the indicator to your chart.**
Select your HTF and LTF in the settings (⏱ Timeframes group).

**2. Watch for a signal triangle.**
A red triangle above a bar means a Bearish CRT has confirmed on the HTF. A green triangle below means Bullish CRT.

**3. Read the box.**
The shaded box is the C1 accumulation range. The upper red-tinted zone is Premium (sell from here). The lower green-tinted zone is Discount (buy from here).

**4. Note the entry line (blue).**
This is C2's close price — the theoretical market entry. In practice, drop to your LTF to confirm the reversal before entering.

**5. Drop to your LTF.**
On the LTF, wait for confirmation: a **Change of Character (CHoCH)** — where price breaks a recent swing high/low in the direction of the trade — or a **Fair Value Gap (FVG)** acting as support/resistance.

**6. Manage the trade.**
- Set your SL at the orange dashed line (beyond the C2 manipulation wick).
- Target TP1 at the gold EQ line (partial close recommended).
- Target TP2 at the CRL (bearish) or CR (bullish) for full CRT delivery.
- Check the R:R label — aim for setups showing at least **1.5R to TP1** and **2.5R+ to TP2**.

**7. Apply Step 5 yourself.**
Before taking any trade, confirm that the HTF market structure supports the direction. Do not short into a strong bullish HTF structure. Do not long into a strong bearish HTF structure.

---

## Alerts

Three alert conditions are available. Set them up via **TradingView Alerts → Condition → [this indicator]**:

| Alert | Fires When |
|-------|------------|
| Bearish CRT (Premium Zone) | A valid bearish pattern confirms on the HTF |
| Bullish CRT (Discount Zone) | A valid bullish pattern confirms on the HTF |
| CRT Pattern (Any) | Either direction confirms |

Alert messages include the ticker, HTF interval, and entry price, along with a reminder to confirm on the LTF.

---

## Visual Reference — What You See on the Chart

```
← C1 Box (Range Box) → ← Extensions →
┌─────────────────────────────────────────────────────────── CR line (C1 High)
│█████████████████ PREMIUM ZONE (red tint) ███████████████──

├─────────────────────────────────────────────────────────── EQ line (50%)

│████████████████ DISCOUNT ZONE (green tint) ████████████──
└─────────────────────────────────────────────────────────── CRL line (C1 Low)

ACC label (on C1) MAN label (on C2)

───────────────────────────────────────────────────────────── ENTRY (blue, solid)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - SL (orange, dashed)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TP1 EQ [xR] (green)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TP2 CRL [xR] (pale green)
```

---

## Technical Notes

- **No repainting:** All HTF data is fetched with `lookahead=barmerge.lookahead_off` and drawings are gated by `barstate.isconfirmed`. Patterns are only drawn when the HTF bar is fully closed.
- **Zoom-stable drawings:** All boxes, lines, and labels use `xloc.bar_time` (real timestamps), not bar index, so they remain perfectly aligned at every zoom level.
- **Signal triangles** use Pine Script's `plotshape()` which internally positions by bar index. This is a platform limitation; triangles may appear slightly offset when chart zoom changes, but all other drawings remain locked.
- Requires Pine Script v5. Works on all instruments and timeframes.

---

## Credits

- Base CRT pattern logic: **ninefnarsa** (TradingView script `oOzkiAxu`)
- Entry/exit framework: **Trader DNA** 5-Step CRT methodology
- ICT concepts: **Michael J. Huddleston** (Inner Circle Trader)

---

*This indicator is for educational purposes only. It does not constitute financial advice. Always use proper risk management and never risk more than you can afford to lose.*

Exención de responsabilidad

La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.