OPEN-SOURCE SCRIPT
Fair Value Gaps - JC

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 │
└─────────────────────────┴─────────┴────────────────────────────────────────────┘
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 │
└─────────────────────────┴─────────┴────────────────────────────────────────────┘
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.