TradingView Indicators

IFVG indicators for TradingView: inversion, retest and invalidation

An inverse fair value gap (IFVG) indicator tracks an existing FVG after price breaks through it, then watches that zone for a response in the opposite direction. Under the close-based rule used here, a bullish FVG becomes a bearish IFVG when a candle closes below its stored lower boundary; a bearish FVG becomes bullish after a close above its upper boundary. These are chart rules for potential support or resistance, not evidence of institutional orders or a reliable price forecast.

Draft custom IFVG rules

FVG versus inverse FVG

A basic FVG compares candle 1 and candle 3 in a three-candle sequence. A bullish gap exists when candle 3 low exceeds candle 1 high; a bearish gap exists when candle 3 high is below candle 1 low. Candle 2 may have traded through the interval, so the pattern does not establish an absence of trades or identify who traded. The inverse pattern reuses the original price interval after a later breach.

  • Equality at a boundary does not satisfy these strict inversion or invalidation conditions.
  • A wick crossing a boundary is not an inversion under this chosen close-based rule. Other scripts can use different definitions; a wick alone cannot prove a liquidity sweep.
  • The midpoint, sometimes called Consequent Encroachment, is (top + bottom) / 2. Using it as an entry threshold is a separate rule absent from this example.
RuleOriginally bullish gapOriginally bearish gap
Formationlow > high[2]high < low[2]
Store at formationbottom = high[2]; top = lowbottom = high; top = low[2]
Close-based inversionLater close < stored bottomLater close > stored top
Potential new roleBearish IFVG / resistanceBullish IFVG / support
IFVG invalidation used hereLater close > stored topLater close < stored bottom

Find the intended IFVG indicator on TradingView

One inspectable community option is Inversion Fair Value Gaps (IFVG) [LuxAlgo]. Its author documents close-based inversion, an ATR width filter, wick/close signal preferences and signal alerts. It is published as open source. This is a description of the publication, not a recommendation based on measured performance or a side-by-side chart test.

  • Search the exact title and author in TradingView Indicators, or open the linked author publication in Sources and use it on a chart. Review the settings before creating alerts.
  • The author states that mitigated IFVG zones and associated signals are deleted. A chart containing only surviving signals is therefore unsuitable for estimating historical signal performance.
  • ICT Implied Fair Value Gap (IFVG) [LuxAlgo] uses a different candle-body and shadow formation. It is not the inverse-FVG lifecycle described here, despite sharing the acronym.
  • When evaluating another script, record the inversion rule, retest rule, timeframe, deletion policy and whether old signals survive invalidation. Screenshots alone do not establish these behaviors.

An explicit lifecycle prevents ambiguous alerts

The following state machine is the specification for the example below. It uses confirmed chart bars, stores each gap separately and checks invalidation before retests. A touch merely overlaps the zone; a rejection also closes back outside its near edge. Ordinary FVG touches do not delete the gap in this implementation.

  • Bearish rejection requires high >= bottom, low <= top and close < bottom. Bullish rejection uses the same overlap test and close > top.
  • The inversion candle cannot also count as the retest. Subsequent rejections from the same zone do not produce another retest event.
  • Several zones can trigger on one bar. Each alert condition aggregates those events into one boolean, rather than sending one message per zone.
Current stateEventResult
Active FVGConfirmed close through the original far boundaryIFVG; recolor and use a dashed border
IFVG, not retestedOn a later bar, range overlaps the zone and close rejects itRecord the first rejection; keep tracking the zone
Either IFVG stateClose through the opposite side of the inverted zoneDelete the box; record invalidation
Any retained stateA new gap would exceed the selected capacityDelete the oldest retained box without an invalidation signal

Hypothetical cases to verify

These prices illustrate the specified rules; they are not market observations or executed test results. Start with a stored bullish FVG from 100 to 102. Record the original bounds and state after each candle.

  • Mirror the sequence for a bearish FVG that becomes a bullish IFVG.
  • Also inspect equal-boundary closes, overlapping zones, session gaps and capacity eviction. A bar range overlapping a zone does not prove a fill at a particular price.
  • For a trading strategy, separately define entries, exits, position sizing, commission and slippage. Indicator state transitions alone do not measure returns.
CaseLater candle informationExpected result
Wick through the floorLow 99.5; close 100.5Remains an ordinary FVG
InversionClose 99.5Becomes a bearish IFVG
Later touch without rejectionHigh 101; low 99.5; close 100.5Overlaps zone; no rejection event
Later rejectionHigh 101; low 99; close 99.8First bearish rejection; state becomes retested
InvalidationClose 102.5Delete the IFVG; no rejection on that bar
No retest before failureFrom inverted state, next close 103Invalidate directly; a retest is not required

Pine Script v6 example: stored zones and selectable alerts

This standalone indicator implements the stated lifecycle on the chart timeframe. Solid boxes are ordinary FVGs; dashed boxes are inverse FVGs. Circles mark inversions, triangles mark first rejections and crosses mark invalidations. The minimum width is a tick filter, not an optimized setting. Syntax validation does not establish runtime behavior or profitability; chart replay and live alert delivery have not been tested for this example.

  • The script keeps up to the selected number of boxes, with an input maximum of 100. Evicted zones stop being tracked, so the capacity setting can change subsequent events.
  • Event plot markers remain when their box is later deleted during the same calculation history. Changing inputs, chart data or the available history can still change recalculated results.
  • Closing-bar evaluation avoids decisions based on unfinished chart candles. It does not guarantee that all possible sources of repainting are eliminated.
  • This example has no higher-timeframe requests, webhook receiver or order execution.
Educational IFVG state machine, chart timeframe onlypinescript
//@version=6
indicator("IFVG lifecycle example", overlay = true, max_boxes_count = 100)

maxZones = input.int(30, "Maximum retained zones", minval = 1, maxval = 100)
minTicks = input.int(1, "Minimum gap size in ticks", minval = 1)

type Gap
    box drawing
    float top
    float bottom
    bool originalBull
    int state
    int inversionBar

// State 0: FVG. State 1: IFVG. State 2: first rejection recorded.
var array<Gap> gaps = array.new<Gap>()
bool flipped = false
bool bullRetest = false
bool bearRetest = false
bool failed = false

if barstate.isconfirmed
    int i = array.size(gaps) - 1
    while i >= 0
        Gap g = array.get(gaps, i)
        box.set_right(g.drawing, bar_index)
        bool remove = false
        if g.state == 0
            bool inversion = g.originalBull ? close < g.bottom : close > g.top
            if inversion
                g.state := 1
                g.inversionBar := bar_index
                color invertedColor = g.originalBull ? color.red : color.teal
                box.set_bgcolor(g.drawing, color.new(invertedColor, 85))
                box.set_border_color(g.drawing, invertedColor)
                box.set_border_style(g.drawing, line.style_dashed)
                flipped := true
        else
            // Invalidation takes priority over a retest on the same bar.
            remove := g.originalBull ? close > g.top : close < g.bottom
            if remove
                failed := true
            else if g.state == 1 and bar_index > g.inversionBar
                bool overlap = high >= g.bottom and low <= g.top
                bool rejection = g.originalBull ? close < g.bottom : close > g.top
                if overlap and rejection
                    g.state := 2
                    bearRetest := bearRetest or g.originalBull
                    bullRetest := bullRetest or not g.originalBull
        if remove
            box.delete(g.drawing)
            array.remove(gaps, i)
        i -= 1

    bool bullGap = low > high[2] and low - high[2] >= minTicks * syminfo.mintick
    bool bearGap = high < low[2] and low[2] - high >= minTicks * syminfo.mintick
    if bullGap or bearGap
        // Capacity eviction is housekeeping, not price invalidation.
        if array.size(gaps) >= maxZones
            Gap oldest = array.shift(gaps)
            box.delete(oldest.drawing)
        float top = bullGap ? low : low[2]
        float bottom = bullGap ? high[2] : high
        color initialColor = bullGap ? color.teal : color.red
        box drawing = box.new(bar_index - 2, top, bar_index, bottom,
             border_color = initialColor, bgcolor = color.new(initialColor, 92))
        array.push(gaps, Gap.new(drawing, top, bottom, bullGap, 0, na))

plotshape(flipped, title = "Inversion", style = shape.circle, location = location.abovebar, color = color.orange, size = size.tiny)
plotshape(bullRetest, title = "Bullish IFVG rejection", style = shape.triangleup, location = location.belowbar, color = color.teal, size = size.tiny)
plotshape(bearRetest, title = "Bearish IFVG rejection", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.tiny)
plotshape(failed, title = "IFVG invalidation", style = shape.xcross, location = location.abovebar, color = color.gray, size = size.tiny)
alertcondition(flipped, "IFVG formed", "A chart-timeframe FVG inverted on {{ticker}} at {{close}}.")
alertcondition(bullRetest, "Bullish IFVG rejection", "First bullish IFVG rejection on {{ticker}} at {{close}}.")
alertcondition(bearRetest, "Bearish IFVG rejection", "First bearish IFVG rejection on {{ticker}} at {{close}}.")
alertcondition(failed, "IFVG invalidated", "An IFVG failed on {{ticker}} at {{close}}.")

Create alerts and inspect their behavior

Paste the example into Pine Editor, save it and add it to the chart. In Create Alert, select the indicator and choose IFVG formed, Bullish IFVG rejection, Bearish IFVG rejection or IFVG invalidated. Set the alert frequency to Once Per Bar Close. Each condition reports whether at least one zone produced that event on the current bar.

  • Create separate alerts for the event types you want to receive. Adding a script to a chart does not create running alerts automatically.
  • TradingView alerts run on realtime bars. Historical markers do not generate a backlog of notifications.
  • Recreate an alert after changing the script, inputs or chart context: a running alert uses a saved snapshot.
  • A webhook requires a configured endpoint and separate order-handling logic. An indicator alert is not evidence that a broker order was placed.
Where Pineify fits

Pine Script AI Coding Agent

Use the lifecycle above as a specification for a custom IFVG indicator. Ask the agent to draft or revise the Pine code, review syntax diagnostics, then inspect the resulting state transitions and alerts in TradingView.

Draft custom IFVG rules

Frequently asked questions

Educational programming reference only, not investment advice. IFVG zones describe chosen chart rules and do not guarantee support, resistance or profitable trades. The example has not been backtested or tested with live alert delivery.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.