OPEN-SOURCE SCRIPT
Cập nhật Fair Value Gaps + Inversion FVG [Quantum Algo]

Fair Value Gaps + Inversion FVG [Quantum Algo]
█ OVERVIEW
Most FVG indicators stop at drawing boxes. This one tracks the complete lifecycle of every gap — fresh → midline-tested → filled → INVERTED → retested — and automates the part of the model that traders actually trade: the Inversion Fair Value Gap (IFVG).
A Fair Value Gap is a 3-candle imbalance left behind when price moves too fast for two-sided trade to occur. Price frequently returns to these zones. But when price closes through a gap instead of respecting it, the zone does not die — it flips polarity. A violated bullish gap becomes resistance; a violated bearish gap becomes support. The first retest of that inverted zone is one of the cleanest entry models in the Smart Money Concepts framework, and this script detects, restyles, and signals it automatically.
█ FEATURES
Gap detection
— Bullish and bearish FVGs detected on confirmed bars only (non-repainting).
— ATR minimum-size filter removes insignificant micro-gaps.
— Optional displacement filter: the middle candle must be a genuine expansion bar (range greater than a configurable multiple of ATR), keeping only gaps created by aggressive participation.
Volume strength score
Every gap is stamped with a 0–100 score comparing the displacement candle's volume against its 20-bar average. A 90% gap and a 20% gap are not the same zone — now you can see the difference at a glance.
Consequent Encroachment (CE)
Each gap carries its 50% midline. The first touch of the CE is detected, the gap is visually dimmed to separate tested zones from fresh ones, and an alert is available.
Inversion engine (IFVG)
— A close through the gap converts it into an inverted zone with distinct styling.
— The first retest of an inverted zone prints an on-chart signal (long model for inverted bearish gaps, short model for inverted bullish gaps).
— A close back through the far side invalidates and removes the zone.
— Inversion can be disabled, in which case gaps simply fill and are removed or frozen (wick-fill or close-fill modes).
Multi-timeframe mode
Display gaps from one higher timeframe directly on your chart as dashed boxes. HTF gaps are built exclusively from closed higher-timeframe bars, so they do not repaint.
Dashboard
A compact panel shows active bullish gaps, bearish gaps, inverted zones, plus the nearest demand level below price and the nearest supply level above it.
Alerts
Eight alert conditions cover the full lifecycle: new bullish/bearish gap, CE touch, fill, bullish/bearish inversion, and long/short IFVG retest.
█ HOW DETECTION WORKS
A bullish FVG forms when the current bar's low sits entirely above the high from two bars earlier — the zone spans that void. A bearish FVG is the mirror image. Detection runs only on bar close, so a gap that appears never disappears or redraws. Lifecycle state changes (CE touches, fills, inversions, retests) are likewise evaluated on confirmed bars.
█ HOW TO USE IT
1. Classic continuation: in a trend, wait for price to retrace into a fresh high-strength gap aligned with the trend; the CE midline is the standard entry refinement.
2. Inversion reversal: when a gap is closed through, stop looking for the old reaction — wait for the retest of the inverted zone in the new direction. The on-chart IFVG markers identify exactly this moment.
3. Multi-timeframe confluence: enable HTF mode and prioritize chart-timeframe signals that occur inside a higher-timeframe gap.
4. Use the dashboard's nearest demand/supply readout for quick situational awareness of where the next reaction zones sit.
Works on all symbols and timeframes. Crypto and index futures tend to produce the cleanest gaps on 5m–1H; forex gaps are more frequent on 15m and above.
█ SETTINGS
Detection — minimum gap size (× ATR), displacement filter, maximum zones kept on chart.
Mitigation & Inversion — inversion on/off, fill source (close or wick), removal of filled gaps, retest signals.
Multi-Timeframe — HTF on/off and timeframe selection.
Visuals — colors for bullish / bearish / inverted zones, fill transparency, CE line, labels, dimming of tested gaps, dashboard.
█ NOTES
— All state changes occur on closed bars; the developing bar can always change until it closes.
— This is an analysis tool for mapping imbalance and inversion zones, intended as a confluence layer within a complete trading plan. It is not a standalone buy/sell system.
█ DISCLAIMER
This script is provided for educational and informational purposes only and does not constitute financial advice. Trading involves substantial risk of loss. Past behavior does not guarantee future results. Always do your own research and apply sound risk management.
█ OVERVIEW
Most FVG indicators stop at drawing boxes. This one tracks the complete lifecycle of every gap — fresh → midline-tested → filled → INVERTED → retested — and automates the part of the model that traders actually trade: the Inversion Fair Value Gap (IFVG).
A Fair Value Gap is a 3-candle imbalance left behind when price moves too fast for two-sided trade to occur. Price frequently returns to these zones. But when price closes through a gap instead of respecting it, the zone does not die — it flips polarity. A violated bullish gap becomes resistance; a violated bearish gap becomes support. The first retest of that inverted zone is one of the cleanest entry models in the Smart Money Concepts framework, and this script detects, restyles, and signals it automatically.
█ FEATURES
Gap detection
— Bullish and bearish FVGs detected on confirmed bars only (non-repainting).
— ATR minimum-size filter removes insignificant micro-gaps.
— Optional displacement filter: the middle candle must be a genuine expansion bar (range greater than a configurable multiple of ATR), keeping only gaps created by aggressive participation.
Volume strength score
Every gap is stamped with a 0–100 score comparing the displacement candle's volume against its 20-bar average. A 90% gap and a 20% gap are not the same zone — now you can see the difference at a glance.
Consequent Encroachment (CE)
Each gap carries its 50% midline. The first touch of the CE is detected, the gap is visually dimmed to separate tested zones from fresh ones, and an alert is available.
Inversion engine (IFVG)
— A close through the gap converts it into an inverted zone with distinct styling.
— The first retest of an inverted zone prints an on-chart signal (long model for inverted bearish gaps, short model for inverted bullish gaps).
— A close back through the far side invalidates and removes the zone.
— Inversion can be disabled, in which case gaps simply fill and are removed or frozen (wick-fill or close-fill modes).
Multi-timeframe mode
Display gaps from one higher timeframe directly on your chart as dashed boxes. HTF gaps are built exclusively from closed higher-timeframe bars, so they do not repaint.
Dashboard
A compact panel shows active bullish gaps, bearish gaps, inverted zones, plus the nearest demand level below price and the nearest supply level above it.
Alerts
Eight alert conditions cover the full lifecycle: new bullish/bearish gap, CE touch, fill, bullish/bearish inversion, and long/short IFVG retest.
█ HOW DETECTION WORKS
A bullish FVG forms when the current bar's low sits entirely above the high from two bars earlier — the zone spans that void. A bearish FVG is the mirror image. Detection runs only on bar close, so a gap that appears never disappears or redraws. Lifecycle state changes (CE touches, fills, inversions, retests) are likewise evaluated on confirmed bars.
█ HOW TO USE IT
1. Classic continuation: in a trend, wait for price to retrace into a fresh high-strength gap aligned with the trend; the CE midline is the standard entry refinement.
2. Inversion reversal: when a gap is closed through, stop looking for the old reaction — wait for the retest of the inverted zone in the new direction. The on-chart IFVG markers identify exactly this moment.
3. Multi-timeframe confluence: enable HTF mode and prioritize chart-timeframe signals that occur inside a higher-timeframe gap.
4. Use the dashboard's nearest demand/supply readout for quick situational awareness of where the next reaction zones sit.
Works on all symbols and timeframes. Crypto and index futures tend to produce the cleanest gaps on 5m–1H; forex gaps are more frequent on 15m and above.
█ SETTINGS
Detection — minimum gap size (× ATR), displacement filter, maximum zones kept on chart.
Mitigation & Inversion — inversion on/off, fill source (close or wick), removal of filled gaps, retest signals.
Multi-Timeframe — HTF on/off and timeframe selection.
Visuals — colors for bullish / bearish / inverted zones, fill transparency, CE line, labels, dimming of tested gaps, dashboard.
█ NOTES
— All state changes occur on closed bars; the developing bar can always change until it closes.
— This is an analysis tool for mapping imbalance and inversion zones, intended as a confluence layer within a complete trading plan. It is not a standalone buy/sell system.
█ DISCLAIMER
This script is provided for educational and informational purposes only and does not constitute financial advice. Trading involves substantial risk of loss. Past behavior does not guarantee future results. Always do your own research and apply sound risk management.
Phát hành các Ghi chú
On-chart symbol + timeframe tag (House Rules: chart clarity)Phát hành các Ghi chú
On-chart symbol + timeframe tag Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
The institutional Edge: Indicators, Strategies & a Free Academy. quantum-algo.com
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.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
The institutional Edge: Indicators, Strategies & a Free Academy. quantum-algo.com
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.