OPEN-SOURCE SCRIPT
Inversion FVG (iFVG) by EonMetrics

Inversion FVG (iFVG) by EonMetrics
🔶WHAT IT DOES
A "fair value gap" (FVG) is a three-candle pattern where price moved so fast that the wicks of the first and third candle never overlapped — leaving a void on the chart that the market skipped over. While an FVG is fresh, traders typically expect a bullish gap to act as support and a bearish gap as resistance.

This indicator focuses on the moment that expectation FAILS — and on how it fails. An inversion FVG (iFVG) happens when price displaces through an existing gap with enough force to print a NEW fair value gap in the opposite direction, overlapping the old one. The inversion zone drawn by this script is the COMMON GROUND of those two opposing gaps — the price area where both imbalances intersect. That is where one side got trapped: broken demand turns into supply, broken supply turns into demand, and the market tends to defend that exact area when price returns to it.

It is a structure-annotation tool: it shows you where these events happen and how significant they were. It deliberately does not give buy/sell signals, entries, targets, stops, or win-rate statistics.
🔶HOW THIS SCRIPT IS DIFFERENT
Most inversion-FVG tools use a simple rule: when a candle closes through a gap, the whole gap is recolored and called inverted. This script uses a stricter, structural definition, and adds level-management logic around it:
1. Two gaps required, intersection drawn. A slow drift through an FVG does not create an inversion here. The traversal must be violent enough to leave a fresh FVG in the opposite direction, and the zone drawn is only the overlap of the two gaps — the exact prices where the old imbalance and the new one coincide — not the whole original gap.
2. Spent levels never invert. The first candle close through the far side of a gap opens a short pairing window. If no opposing gap confirms within it, the level is considered spent and permanently dropped. Levels that price has already chopped through several times can never produce a late, meaningless inversion zone.
3. Levels are remembered independently of what you see. A gap's box may be mitigated and removed from the chart, yet its price range keeps working invisibly as a candidate level for a configurable number of bars. The displacement that flips a level often arrives well after the gap was first touched — display and detection are deliberately separated.
4. Partial consumption. When an opposing gap overlaps only part of a remembered level, only that part is consumed; the remainder stays available. A small opposing gap therefore cannot "steal" a large level from a later, proper displacement. One inverting gap can flip several remembered levels at once, and the resulting zones never overlap each other.
5. Two-condition strength grading. An inversion is tagged STRONG only when the inverting gap is both large relative to volatility AND backed by elevated volume on its displacement candle — size or volume alone is not enough.
🔶HOW IT DETECTS EACH EVENT (THE EXACT METHOD)
1. Regular FVG: on every closed bar the script checks the classic three-candle condition — for a bullish gap, the current bar's low must be above the high from two bars ago (mirrored for bearish). Gaps smaller than a chosen multiple of ATR (a standard volatility unit, measured at the moment the gap forms) are ignored. By default these regular gaps stay INVISIBLE — they are tracked in the background purely as raw material for inversions, so the chart shows only what the tool is about: the inversion zones. One switch reveals them as a quiet context layer if you want to see what may flip next.
2. Regular FVG expiry (display): each displayed gap lives until price mitigates it, by your rules — at its 50% midpoint or only on a full fill, touched by any wick or requiring a candle close. Mitigated gaps disappear, or stay frozen as reference if you prefer. This controls only what you SEE.
3. Level memory (detection): independently of the display, every detected gap's price range is remembered for a set number of bars from its creation (Inversion Memory). A remembered level dies early if price closes through its far side and no opposing gap confirms within the pairing window (Pairing Window After Break) — that level is spent.
4. Inversion (iFVG): when a fresh gap forms in the OPPOSITE direction of a remembered level and their price ranges overlap, the inversion fires:
- The drawn zone is the intersection of the two full gaps: its top is the lower of the two gap tops, its bottom is the higher of the two gap bottoms.
- An overlap thinner than the Min FVG Size threshold neither draws a zone nor consumes the level.
- The zone is colored by its new role: support (a bearish gap was displaced upward through) or resistance (a bullish gap was displaced downward through).
- The zone is drawn starting from the ORIGINAL gap's origin, so you see the full history of the level — from the moment the imbalance first appeared, through the displacement that flipped it.
- The zone's age counter, retest and expiry logic are anchored at the inversion moment, not at the original gap.
5. Strong grading: the NEW (inverting) gap is measured. If its height is at least a chosen multiple of ATR AND the volume of its displacement candle exceeds the 20-bar volume average by a chosen multiplier, the inversion is tagged STRONG — the old gap was taken out with conviction on real participation, not by low-volume drift.

6. Inversion zone life: each iFVG shows its 50% equilibrium line (the consequent encroachment level), an age counter in bars, fires an alert on the first retest from outside, and expires by the same mitigation rules as regular gaps (50% or full, wick or close) once price trades through it against its new role.
Everything is evaluated on closed bars only, so zones, colors and labels do not repaint.
🔶HOW TO ACTUALLY USE IT (STEP BY STEP)
1. Out of the box you see only inversion zones — that is the point of the tool. If you also want the raw material (regular gaps that may flip later), enable "Show Regular FVGs" and they appear as quiet green/red context boxes.
2. When a colored inversion zone appears, read its meaning: orange resistance = former demand that got displaced through downward; cyan support = former supply that got displaced through upward.
3. Give more weight to zones tagged STRONG — the inverting gap was large and backed by elevated volume, which traders treat as a more meaningful role-flip than a quiet leak.
4. The first return of price into the zone is the moment most iFVG traders wait for (there is a dedicated retest alert). Watch how price reacts there — rejection confirms the new role, a pass-through negates it.
5. The gray line inside each zone is its 50% midpoint (EQ) — many traders use it as the precise reaction level rather than the zone edges.
6. The age counter (e.g. "34b") tells you how long a zone has existed since its inversion — fresh zones are generally considered more reliable than stale ones, and you can enable fading to de-emphasize old zones automatically.
7. Combine with your own analysis of trend and higher-timeframe levels. The indicator describes structure; it does not predict.
If you want the full life cycle of REGULAR fair value gaps (creation, strength grading and retest alerts while they still act in their original direction), that is what our free Smart FVG indicator does — this tool picks up where it ends, at the moment a gap fails and flips. Both use the same visual language, so they pair naturally.
🔶EVERY SETTING EXPLAINED
🔵Visualization group
- Bullish FVG / Bearish FVG — colors of the quiet regular-gap context layer.
- iFVG Support / iFVG Resistance — colors of the inversion zones.
- Show Regular FVGs — off by default: only inversion zones are displayed. Turn on to also see the not-yet-inverted gaps as context (hidden gaps are still tracked, so inversions keep firing either way).
- Show 50% Line (EQ) / EQ Line Color — the midpoint line inside each zone.
- Width Mode — how zones extend to the right: Dynamic (to the current bar), Fixed (a set number of bars), or Extended (infinitely).
- Fixed Width (bars) — zone width when Fixed mode is selected.
- Min FVG Size (x ATR) — the smallest height that registers, applied twice: to every new gap AND to the common ground of the two gaps (an overlap thinner than this neither draws a zone nor consumes the level); 0 disables both checks.
BEFORE ATR

AFTER ATR

🔵Mitigation group
- Delete Mitigated Zones — remove finished zones, or freeze them on the chart as reference.
- Mitigation Level — a zone is finished when price reaches its 50% midpoint, or only on a full fill.
- Mitigation Confirmation — what must reach that level: any wick, or a candle close.
- Inversion Memory (bars) — how long each detected gap's range stays eligible to form inversions, counted from the gap's creation and independent of when its box disappears from the chart. Larger = more inversions detected, including from older levels.
- Pairing Window After Break (bars) — once price CLOSES through the far side of a remembered gap, the opposing gap must confirm within this many bars for the inversion to count. If it does not, the level is treated as spent and dropped.
🔵Imbalance Age group
- Show Age Label — the bar counter inside each zone.
- Fade Old Zones / Max Age for Full Fade — gradually de-emphasize stale zones.
🔵Strong Inversion group
- Mark Strong Inversions — enables the two-condition strength check.
- Min Inverting Gap Size (x ATR) — condition 1: how large the inverting gap must be relative to volatility. Note this grades the STRONG tag only; it does not filter which zones appear (that is Min FVG Size).
- Min Volume (x SMA 20) — condition 2: how elevated the displacement candle volume must be versus its 20-bar average.
- Show 'STRONG' Tag — the text tag on qualifying zones.
🔵Labels group
- Show Labels / Label Text Color — master switch and color for all in-zone text.
- Label Offset (bars left of price) — keeps each zone's label trailing near the current bar so it stays readable, instead of sitting far back at the zone's left edge; 0 pins it on the current bar.
🔶ALERTS
New iFVG Support / New iFVG Resistance / New STRONG iFVG / iFVG Retest / iFVG Mitigated — standard TradingView alert conditions. Select "Once Per Bar Close" when creating alerts for non-repainting behavior.
🔶WHAT THIS TOOL DELIBERATELY DOES NOT DO
No buy or sell signals, no take-profit or stop-loss levels, no win-rate dashboard. Detecting a structural pattern is not the same as having a tradable edge, and presenting pattern marks as trade signals would overstate what any indicator of this kind can honestly claim. Use it as a lens for reading market structure, together with your own judgment.
🔶WHAT IT DOES
A "fair value gap" (FVG) is a three-candle pattern where price moved so fast that the wicks of the first and third candle never overlapped — leaving a void on the chart that the market skipped over. While an FVG is fresh, traders typically expect a bullish gap to act as support and a bearish gap as resistance.
This indicator focuses on the moment that expectation FAILS — and on how it fails. An inversion FVG (iFVG) happens when price displaces through an existing gap with enough force to print a NEW fair value gap in the opposite direction, overlapping the old one. The inversion zone drawn by this script is the COMMON GROUND of those two opposing gaps — the price area where both imbalances intersect. That is where one side got trapped: broken demand turns into supply, broken supply turns into demand, and the market tends to defend that exact area when price returns to it.
It is a structure-annotation tool: it shows you where these events happen and how significant they were. It deliberately does not give buy/sell signals, entries, targets, stops, or win-rate statistics.
🔶HOW THIS SCRIPT IS DIFFERENT
Most inversion-FVG tools use a simple rule: when a candle closes through a gap, the whole gap is recolored and called inverted. This script uses a stricter, structural definition, and adds level-management logic around it:
1. Two gaps required, intersection drawn. A slow drift through an FVG does not create an inversion here. The traversal must be violent enough to leave a fresh FVG in the opposite direction, and the zone drawn is only the overlap of the two gaps — the exact prices where the old imbalance and the new one coincide — not the whole original gap.
2. Spent levels never invert. The first candle close through the far side of a gap opens a short pairing window. If no opposing gap confirms within it, the level is considered spent and permanently dropped. Levels that price has already chopped through several times can never produce a late, meaningless inversion zone.
3. Levels are remembered independently of what you see. A gap's box may be mitigated and removed from the chart, yet its price range keeps working invisibly as a candidate level for a configurable number of bars. The displacement that flips a level often arrives well after the gap was first touched — display and detection are deliberately separated.
4. Partial consumption. When an opposing gap overlaps only part of a remembered level, only that part is consumed; the remainder stays available. A small opposing gap therefore cannot "steal" a large level from a later, proper displacement. One inverting gap can flip several remembered levels at once, and the resulting zones never overlap each other.
5. Two-condition strength grading. An inversion is tagged STRONG only when the inverting gap is both large relative to volatility AND backed by elevated volume on its displacement candle — size or volume alone is not enough.
🔶HOW IT DETECTS EACH EVENT (THE EXACT METHOD)
1. Regular FVG: on every closed bar the script checks the classic three-candle condition — for a bullish gap, the current bar's low must be above the high from two bars ago (mirrored for bearish). Gaps smaller than a chosen multiple of ATR (a standard volatility unit, measured at the moment the gap forms) are ignored. By default these regular gaps stay INVISIBLE — they are tracked in the background purely as raw material for inversions, so the chart shows only what the tool is about: the inversion zones. One switch reveals them as a quiet context layer if you want to see what may flip next.
2. Regular FVG expiry (display): each displayed gap lives until price mitigates it, by your rules — at its 50% midpoint or only on a full fill, touched by any wick or requiring a candle close. Mitigated gaps disappear, or stay frozen as reference if you prefer. This controls only what you SEE.
3. Level memory (detection): independently of the display, every detected gap's price range is remembered for a set number of bars from its creation (Inversion Memory). A remembered level dies early if price closes through its far side and no opposing gap confirms within the pairing window (Pairing Window After Break) — that level is spent.
4. Inversion (iFVG): when a fresh gap forms in the OPPOSITE direction of a remembered level and their price ranges overlap, the inversion fires:
- The drawn zone is the intersection of the two full gaps: its top is the lower of the two gap tops, its bottom is the higher of the two gap bottoms.
- An overlap thinner than the Min FVG Size threshold neither draws a zone nor consumes the level.
- The zone is colored by its new role: support (a bearish gap was displaced upward through) or resistance (a bullish gap was displaced downward through).
- The zone is drawn starting from the ORIGINAL gap's origin, so you see the full history of the level — from the moment the imbalance first appeared, through the displacement that flipped it.
- The zone's age counter, retest and expiry logic are anchored at the inversion moment, not at the original gap.
5. Strong grading: the NEW (inverting) gap is measured. If its height is at least a chosen multiple of ATR AND the volume of its displacement candle exceeds the 20-bar volume average by a chosen multiplier, the inversion is tagged STRONG — the old gap was taken out with conviction on real participation, not by low-volume drift.
6. Inversion zone life: each iFVG shows its 50% equilibrium line (the consequent encroachment level), an age counter in bars, fires an alert on the first retest from outside, and expires by the same mitigation rules as regular gaps (50% or full, wick or close) once price trades through it against its new role.
Everything is evaluated on closed bars only, so zones, colors and labels do not repaint.
🔶HOW TO ACTUALLY USE IT (STEP BY STEP)
1. Out of the box you see only inversion zones — that is the point of the tool. If you also want the raw material (regular gaps that may flip later), enable "Show Regular FVGs" and they appear as quiet green/red context boxes.
2. When a colored inversion zone appears, read its meaning: orange resistance = former demand that got displaced through downward; cyan support = former supply that got displaced through upward.
3. Give more weight to zones tagged STRONG — the inverting gap was large and backed by elevated volume, which traders treat as a more meaningful role-flip than a quiet leak.
4. The first return of price into the zone is the moment most iFVG traders wait for (there is a dedicated retest alert). Watch how price reacts there — rejection confirms the new role, a pass-through negates it.
5. The gray line inside each zone is its 50% midpoint (EQ) — many traders use it as the precise reaction level rather than the zone edges.
6. The age counter (e.g. "34b") tells you how long a zone has existed since its inversion — fresh zones are generally considered more reliable than stale ones, and you can enable fading to de-emphasize old zones automatically.
7. Combine with your own analysis of trend and higher-timeframe levels. The indicator describes structure; it does not predict.
If you want the full life cycle of REGULAR fair value gaps (creation, strength grading and retest alerts while they still act in their original direction), that is what our free Smart FVG indicator does — this tool picks up where it ends, at the moment a gap fails and flips. Both use the same visual language, so they pair naturally.
🔶EVERY SETTING EXPLAINED
🔵Visualization group
- Bullish FVG / Bearish FVG — colors of the quiet regular-gap context layer.
- iFVG Support / iFVG Resistance — colors of the inversion zones.
- Show Regular FVGs — off by default: only inversion zones are displayed. Turn on to also see the not-yet-inverted gaps as context (hidden gaps are still tracked, so inversions keep firing either way).
- Show 50% Line (EQ) / EQ Line Color — the midpoint line inside each zone.
- Width Mode — how zones extend to the right: Dynamic (to the current bar), Fixed (a set number of bars), or Extended (infinitely).
- Fixed Width (bars) — zone width when Fixed mode is selected.
- Min FVG Size (x ATR) — the smallest height that registers, applied twice: to every new gap AND to the common ground of the two gaps (an overlap thinner than this neither draws a zone nor consumes the level); 0 disables both checks.
BEFORE ATR
AFTER ATR
🔵Mitigation group
- Delete Mitigated Zones — remove finished zones, or freeze them on the chart as reference.
- Mitigation Level — a zone is finished when price reaches its 50% midpoint, or only on a full fill.
- Mitigation Confirmation — what must reach that level: any wick, or a candle close.
- Inversion Memory (bars) — how long each detected gap's range stays eligible to form inversions, counted from the gap's creation and independent of when its box disappears from the chart. Larger = more inversions detected, including from older levels.
- Pairing Window After Break (bars) — once price CLOSES through the far side of a remembered gap, the opposing gap must confirm within this many bars for the inversion to count. If it does not, the level is treated as spent and dropped.
🔵Imbalance Age group
- Show Age Label — the bar counter inside each zone.
- Fade Old Zones / Max Age for Full Fade — gradually de-emphasize stale zones.
🔵Strong Inversion group
- Mark Strong Inversions — enables the two-condition strength check.
- Min Inverting Gap Size (x ATR) — condition 1: how large the inverting gap must be relative to volatility. Note this grades the STRONG tag only; it does not filter which zones appear (that is Min FVG Size).
- Min Volume (x SMA 20) — condition 2: how elevated the displacement candle volume must be versus its 20-bar average.
- Show 'STRONG' Tag — the text tag on qualifying zones.
🔵Labels group
- Show Labels / Label Text Color — master switch and color for all in-zone text.
- Label Offset (bars left of price) — keeps each zone's label trailing near the current bar so it stays readable, instead of sitting far back at the zone's left edge; 0 pins it on the current bar.
🔶ALERTS
New iFVG Support / New iFVG Resistance / New STRONG iFVG / iFVG Retest / iFVG Mitigated — standard TradingView alert conditions. Select "Once Per Bar Close" when creating alerts for non-repainting behavior.
🔶WHAT THIS TOOL DELIBERATELY DOES NOT DO
No buy or sell signals, no take-profit or stop-loss levels, no win-rate dashboard. Detecting a structural pattern is not the same as having a tradable edge, and presenting pattern marks as trade signals would overstate what any indicator of this kind can honestly claim. Use it as a lens for reading market structure, together with your own judgment.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน