OPEN-SOURCE SCRIPT

Fair Value Gaps - JC

62
FVG Indicator — How It Works

What It Does

Detects Fair Value Gaps (3-bar price imbalances) on any chart timeframe and draws them as semi-transparent boxes that track their full lifecycle from formation to resolution.

Detection

A FVG forms when a 3-candle pattern leaves a price gap:

- Bullish FVG: Bar 3's low > Bar 1's high — price gapped up, leaving an unfilled zone between bar 1's high (bottom) and bar 3's low (top)
- Bearish FVG: Bar 1's low > Bar 3's high — price gapped down, leaving an unfilled zone between bar 3's high (bottom) and bar 1's low (top)

Bar 2 (the middle candle) is where the box starts drawing from, but it's not used in detection — only bars 1 and 3 matter.

State Machine (7 States)

Each FVG tracks through a lifecycle:

Active states:
- Fresh (blue/orange) — Just formed, price hasn't returned to the zone yet
- Tapped (lighter shade) — Price has entered the zone but hasn't resolved it
- Respected (green/red) — Price tapped the zone then bounced away (closed back outside)

Terminal states:
- Consumed — Fill ratio reached 100% (zone fully filled by wicks)
- Invalidated — Price closed through the opposite side of the zone
- Displaced — Price closed through with a strong candle body (>= gap size × displacement multiplier)
- Timeout — Unresolved after 50 bars (configurable)

Visual Behavior

- Active FVGs extend rightward bar-by-bar until they reach a terminal state
- Terminal FVGs are deleted by default (toggle "Show terminated" to keep them visible in gray)
- Optional midpoint dashed line marks the CE (Consequent Encroachment) level — the 50% retracement of the gap
- Oldest FVGs are removed when the count exceeds the max (default 15)

Key Inputs
┌─────────────────────────┬─────────┬────────────────────────────────────────────┐
│ Setting │ Default │ Purpose │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Max FVGs │ 15 │ How many to show on chart │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Min gap ticks │ 0 │ Filter out small gaps (set to 4 for MNQ) │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Timeout bars │ 50 │ When unresolved FVGs expire │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Consumed threshold │ 1.0 │ Fill ratio to mark as consumed │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Displacement multiplier │ 1.0 │ Body size relative to gap for displacement │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Show midpoint │ ON │ CE level dashed line │
├─────────────────────────┼─────────┼────────────────────────────────────────────┤
│ Show terminated │ OFF │ Keep resolved FVGs visible │
└─────────────────────────┴─────────┴────────────────────────────────────────────┘

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.