OPEN-SOURCE SCRIPT

ICT FVG_IFVG Engine 3m Optimised

686
This indicator detects and tracks **Fair Value Gaps (FVGs)** and **Inversion Fair Value Gaps (IFVGs)** based on the Inner Circle Trader (ICT) methodology. It is built specifically around the **AM session (9:30–12:00 NY)** and **Silver Bullet windows (10:00–11:00 and 14:00–15:00 NY)**, firing real-time alerts when price returns to key entry levels.

The core signal is the **Consequent Encroachment (CE) tap** — price reaching the 50% midpoint (mean threshold) of a Fair Value Gap — which ICT teaches as the precision entry point within the gap. When this level is touched, the indicator fires a full alert with entry price, stop loss, take profit, R:R ratio, session tag, and quality tier.

---

## ICT Concepts Applied

**Fair Value Gap (FVG)**
A 3-candle price imbalance where the current bar's low is above the 2-bars-prior high (bullish) or the current bar's high is below the 2-bars-prior low (bearish). An optional ATR displacement filter ensures only gaps formed by real displacement candles are tracked.

**Consequent Encroachment (CE)**
The 50% midpoint of the FVG — also called the mean threshold. ICT teaches this as the primary entry reference within the gap, offering better risk-to-reward than entering at the gap edge.

**Inversion Fair Value Gap (IFVG)**
When price closes through the far edge of an FVG (a **body close**, not just a wick), the gap inverts its role — a bullish FVG becomes resistance, a bearish FVG becomes support. The next retest of the inverted zone is a trade in the new direction.

**First-Presented FVG (FPFVG)**
The first qualifying FVG of each session. ICT methodology emphasises this as the highest-quality setup of the session.

**Silver Bullet**
A specific ICT time window (10:00–11:00 AM and 2:00–3:00 PM New York time) within which the first FVG and its CE are considered premium setups.

**Liquidity Sweep (optional)**
A prerequisite where price raids a prior swing high or low (taking out resting orders) and then closes back inside the range before the displacement that creates the FVG. This forms the full ICT sequence: sweep → displacement → FVG → CE entry.

---

## Features

### Detection
- 3-candle FVG detection with configurable ATR displacement filter
- Optional liquidity sweep prerequisite (raid + rejection of prior swing)
- Tracks gaps until mitigated (full entry) or inverted (IFVG)
- Inversion confirmed by **candle body close** through the far edge — not a wick

### Session & Scope
- Configurable AM (default 9:30–12:00) and PM (1:30–4:00) session windows
- Silver Bullet windows: AM (10:00–11:00) and PM (2:00–3:00)
- Optional London Silver Bullet (3:00–4:00 AM NY)
- Three scope modes: All gaps | Session gaps only | First-presented + Silver Bullet

### Time-of-Day Quality Filter
Gaps are colour-coded by formation time based on historical win-rate data:

| Tier | Window | Visual |
|------|--------|--------|
| HIGH | 9:30–10:00 AM | Bright boxes |
| MED | 10:00–11:00 AM | Normal boxes (Silver Bullet) |
| LOW | 11:00 AM–12:00 PM | Dimmed boxes |

LOW-quality alerts and R:R zones are suppressed by default to reduce noise.

### Two-Tier Alert System
Every CE tap fires a rich alert message containing:
- Priority tier (`*** PRIORITY` for first-presented/SB, `SETUP` for others)
- Quality tier (`HIGH`, `MED`, or `LOW`)
- Ticker and timeframe
- Trade direction (`LONG` or `SHORT`)
- Exact CE entry level
- Stop loss level
- Take profit level
- R:R ratio
- Session tag (e.g. `1st AM`, `SB-AM`, `AM`)
- Current price

**Example alert message:**
```
*** PRIORITY [HIGH] | NQ 3 | LONG | CE 21245.00 | SL 21235.00 | TP 21275.00 | 1:3.0 | [1st AM] | px 21246.25
```

### R:R Zones
When a CE tap occurs, the indicator automatically draws:
- **Yellow dashed line** — Entry at CE
- **Red solid line** — Stop loss level with label
- **Green solid line** — Take profit level with label
- **Green fill zone** — CE to TP visual
- **Red fill zone** — CE to SL visual

Default levels are set to the backtest-optimised values for the 3-minute NQ chart (10-point stop / 30-point target). These are fully configurable.

### Dashboard (top-right table)
- Live session status for AM, PM, Silver Bullet AM/PM/London
- Time-quality tier indicator with win-rate reference per bucket
- Daily CE signal counter vs cap
- Current R:R settings reminder

---

## How to Use

**Step 1 — Add to chart**
Paste into Pine Editor, Save, then click *Add to chart*. The indicator works as an overlay on any symbol and timeframe.

**Step 2 — Choose your scope**
In *Settings → Scope*, select:
- **"In configured sessions only"** to track all AM/PM FVGs (more signals)
- **"First-presented + Silver Bullet"** for highest-quality only (fewer signals)

**Step 3 — Set your R:R levels**
In *Settings → R:R Levels*, enter your stop loss and take profit in points. Defaults are 10pt stop / 30pt TP — calibrated for the 3-minute NQ futures chart.

**Step 4 — Create alerts**
1. Right-click the chart → *Add alert*
2. Condition = this indicator → select one of:
- **"*** PRIORITY CE tap"** — First-presented and Silver Bullet gaps only
- **"SETUP CE tap"** — All other session gaps
- **"Any CE tap"** — Catch-all for both tiers
- **"Any ICT signal"** — Includes inversions and IFVG retests
3. Set trigger to *Once Per Bar Close* to match closed-bar detection and avoid repaint

**Step 5 — Read the chart**
- **Bright boxes** = HIGH quality (9:30–10:00 AM) — best setups
- **Normal boxes** = MED quality (Silver Bullet window)
- **Dimmed boxes** = LOW quality (11:00 AM+) — alerts suppressed by default
- **Yellow border** = First-presented FVG of the session
- **Orange box** = FVG has inverted → now an IFVG — trade the opposite direction
- **Green/Red zones** = R:R levels drawn at moment of CE tap

---

## Settings Reference

| Group | Setting | Description |
|-------|---------|-------------|
| Detection | ATR filter | Minimum gap size relative to ATR14 — filters out small gaps |
| Detection | Closed bars only | Prevents repainting — recommended ON |
| Liquidity Sweep | Require sweep | Makes the full ICT sequence mandatory before a gap qualifies |
| Scope | Which gaps to track | Controls how many gaps are tracked and drawn |
| Sessions | AM / PM / SB times | All configurable in NY time. DST is handled automatically |
| Quality Filter | Enable quality tiers | Colour-codes gaps by time-of-day win rate |
| Quality Filter | Suppress LOW alerts | Prevents alerts after 11:00 AM when win rates drop |
| Alerts | PRIORITY / SETUP | Toggle each alert tier independently |
| Alerts | Max CE per day | Daily signal cap — default 4, matching recommended session limit |
| R:R Levels | Stop / TP points | Draws SL and TP lines and fill zones on every CE tap |

---

## Alert Setup for Mobile Notifications

To receive push notifications to the TradingView mobile app:
1. Create the alert as above
2. Under *Notifications*, enable **App notification**
3. Set trigger to *Once Per Bar Close*

For webhook/automation, the alert message is structured for easy parsing:
- Fields are `|`-separated
- Entry, SL, and TP are explicit price levels (not offsets)

---

## Notes & Disclaimers

- **Timeframe:** The indicator works on all timeframes. Default settings (10pt SL / 30pt TP) are calibrated for the **3-minute NQ futures chart** based on internal backtesting over 60 days of data. Adjust stop and target values to match your instrument's volatility and your preferred timeframe.

- **Repaint:** With *"Detect on closed bars only"* enabled (default), all signals are based on confirmed closed candles. Disabling this option allows earlier intrabar detection but will repaint before the bar closes.

- **Inversion logic:** Inversion is confirmed by a candle **body close** through the far edge of the gap, per ICT teaching. A wick alone does not qualify.

- **No financial advice:** This indicator is a technical analysis tool. All signals are for informational purposes only. Past performance of any pattern or level does not guarantee future results. Always use appropriate risk management and conduct your own analysis before entering any trade.

- **ICT methodology:** Fair Value Gaps, Silver Bullet, Consequent Encroachment, and related terminology are concepts taught by the Inner Circle Trader (ICT). This indicator is an independent technical implementation and is not affiliated with, endorsed by, or produced by ICT.

---

*Built with Pine Script v6.*

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.