// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © LiquidityEdgeFutures (https://liquidityedgefutures.com) // ========================================================================================================= // LIQUIDITY EDGE | INVERSION FVG (IFVG) & IMBALANCE RADAR [FREE COMMUNITY EDITION] // Institutional Order Flow & Smart Money Concepts Engine for CME NQ1!, MNQ1!, ES1! // // Features: // - Automatic 3-candle Fair Value Gap detection (BISI & SIBI) // - Dynamic Inversion Engine: Automatically flips broken FVGs into high-probability IFVG support/resistance // - Consequent Encroachment (50% CE) midline computation // - Visual retest tracking & institutional color grading // - Ready-to-fire TradingView alerts for IFVG creation and retest entries // ========================================================================================================= //@version=5 indicator("Liquidity Edge - Inversion FVG (IFVG) Radar", shorttitle="LE - IFVG Radar", overlay=true, max_boxes_count=500, max_labels_count=500, max_lines_count=500) // --------------------------------------------------------------------------------------------------------- // INPUT SETTINGS // --------------------------------------------------------------------------------------------------------- var string G_GEN = "1. General Configuration" var string G_FVG = "2. Standard FVG Styling" var string G_IFVG = "3. Inversion FVG (IFVG) Styling" var string G_ALERTS = "4. Audio / Webhook Alerts" // General Inputs int i_minTicks = input.int(8, "Min FVG Size (Ticks)", minval=0, tooltip="Filters out microscopic noise gaps. For NQ (0.25 tick), 8 ticks = 2 full points.", group=G_GEN) int i_maxActive = input.int(15, "Max Active Zones Stored", minval=5, maxval=40, tooltip="Number of active unmitigated zones tracked on chart.", group=G_GEN) bool i_showMidline = input.bool(true, "Show 50% Consequent Encroachment (CE)", group=G_GEN) bool i_extendZones = input.bool(true, "Extend Active Zones to Current Bar", group=G_GEN) bool i_showLabels = input.bool(true, "Show Institutional Labels", group=G_GEN) // Standard FVG Styling color i_bisi_fill = input.color(color.new(#10B981, 85), "BISI (Bullish FVG) Fill", group=G_FVG) color i_bisi_border = input.color(color.new(#10B981, 40), "BISI Border", group=G_FVG) color i_sibi_fill = input.color(color.new(#EF4444, 85), "SIBI (Bearish FVG) Fill", group=G_FVG) color i_sibi_border = input.color(color.new(#EF4444, 40), "SIBI Border", group=G_FVG) // Inversion FVG Styling (Broken Support/Resistance) color i_ifvg_bull_fill = input.color(color.new(#38BDF8, 75), "Bullish IFVG Fill (Broken Bearish)", group=G_IFVG) color i_ifvg_bull_border = input.color(color.new(#0284C7, 10), "Bullish IFVG Border", group=G_IFVG) color i_ifvg_bear_fill = input.color(color.new(#F59E0B, 75), "Bearish IFVG Fill (Broken Bullish)", group=G_IFVG) color i_ifvg_bear_border = input.color(color.new(#D97706, 10), "Bearish IFVG Border", group=G_IFVG) color i_ce_color = input.color(color.new(#94A3B8, 40), "50% CE Midline Color", group=G_IFVG) // Alerts bool i_alertInversion = input.bool(true, "Alert: Inversion FVG Created", group=G_ALERTS) bool i_alertRetest = input.bool(true, "Alert: IFVG Retest Entry", group=G_ALERTS) // --------------------------------------------------------------------------------------------------------- // CUSTOM DATA TYPES & ARRAYS // --------------------------------------------------------------------------------------------------------- type FVGZone box bx line ln_ce label lbl float top float bottom float ce int leftBar bool isBullish bool isInverted bool isMitigated var FVGZone[] activeZones = array.new() // Clean up function to remove old zones f_purgeZone(FVGZone z) => box.delete(z.bx) line.delete(z.ln_ce) label.delete(z.lbl) // --------------------------------------------------------------------------------------------------------- // FVG IDENTIFICATION LOGIC (3-Candle Sequences) // --------------------------------------------------------------------------------------------------------- // Candle 1 = [2], Candle 2 = [1], Candle 3 = [0] float tickSize = syminfo.mintick float minRange = i_minTicks * tickSize bool isBISI = (low > high[2]) and ((low - high[2]) >= minRange) bool isSIBI = (high < low[2]) and ((low[2] - high) >= minRange) // Alert triggers for current bar bool event_bullishInversion = false bool event_bearishInversion = false bool event_bullishRetest = false bool event_bearishRetest = false // 1. Register New Standard FVG if barstate.isconfirmed if isBISI float topPrice = low float bottomPrice = high[2] float midPrice = (topPrice + bottomPrice) / 2.0 int startBar = bar_index[1] box b = box.new(left=startBar, top=topPrice, right=bar_index, bottom=bottomPrice, border_color=i_bisi_border, border_width=1, bgcolor=i_bisi_fill) line l = i_showMidline ? line.new(x1=startBar, y1=midPrice, x2=bar_index, y2=midPrice, color=i_ce_color, style=line.style_dashed, width=1) : na label lb = i_showLabels ? label.new(x=startBar, y=topPrice, text="BISI FVG", color=color.new(color.black, 100), textcolor=color.new(#10B981, 20), style=label.style_none, size=size.tiny) : na FVGZone nz = FVGZone.new(b, l, lb, topPrice, bottomPrice, midPrice, startBar, true, false, false) array.push(activeZones, nz) if isSIBI float topPrice = low[2] float bottomPrice = high float midPrice = (topPrice + bottomPrice) / 2.0 int startBar = bar_index[1] box b = box.new(left=startBar, top=topPrice, right=bar_index, bottom=bottomPrice, border_color=i_sibi_border, border_width=1, bgcolor=i_sibi_fill) line l = i_showMidline ? line.new(x1=startBar, y1=midPrice, x2=bar_index, y2=midPrice, color=i_ce_color, style=line.style_dashed, width=1) : na label lb = i_showLabels ? label.new(x=startBar, y=bottomPrice, text="SIBI FVG", color=color.new(color.black, 100), textcolor=color.new(#EF4444, 20), style=label.style_none, size=size.tiny) : na FVGZone nz = FVGZone.new(b, l, lb, topPrice, bottomPrice, midPrice, startBar, false, false, false) array.push(activeZones, nz) // --------------------------------------------------------------------------------------------------------- // 2. INVERSION & MITIGATION ENGINE // --------------------------------------------------------------------------------------------------------- if barstate.isconfirmed and array.size(activeZones) > 0 for i = array.size(activeZones) - 1 to 0 FVGZone z = array.get(activeZones, i) if not z.isInverted // Check for Inversion Breakdown / Breakout if z.isBullish // Bullish FVG broken downward with body close -> turns into Bearish IFVG (Resistance) if close < z.bottom z.isInverted := true box.set_bgcolor(z.bx, i_ifvg_bear_fill) box.set_border_color(z.bx, i_ifvg_bear_border) box.set_border_width(z.bx, 2) if not na(z.lbl) and i_showLabels label.set_text(z.lbl, "BEARISH IFVG") label.set_textcolor(z.lbl, #F59E0B) event_bearishInversion := true else // Bearish FVG broken upward with body close -> turns into Bullish IFVG (Support) if close > z.top z.isInverted := true box.set_bgcolor(z.bx, i_ifvg_bull_fill) box.set_border_color(z.bx, i_ifvg_bull_border) box.set_border_width(z.bx, 2) if not na(z.lbl) and i_showLabels label.set_text(z.lbl, "BULLISH IFVG") label.set_textcolor(z.lbl, #38BDF8) event_bullishInversion := true else // Zone is already an Inversion FVG -> Check for Retest Entry or Total Mitigation if not z.isBullish // Meaning it was Bearish SIBI, now Bullish IFVG (Support) // Retest condition: price dips into the IFVG zone from above without closing below it if (low <= z.top and low >= z.bottom and close >= z.bottom) event_bullishRetest := true // Full invalidation / mitigation: price decisively closes below bottom if close < z.bottom z.isMitigated := true else // Meaning it was Bullish BISI, now Bearish IFVG (Resistance) // Retest condition: price rallies into the IFVG zone from below without closing above it if (high >= z.bottom and high <= z.top and close <= z.top) event_bearishRetest := true // Full invalidation / mitigation: price decisively closes above top if close > z.top z.isMitigated := true // Extend active unmitigated zones to current bar if i_extendZones and not z.isMitigated box.set_right(z.bx, bar_index) if not na(z.ln_ce) line.set_x2(z.ln_ce, bar_index) // Remove mitigated zones from memory if z.isMitigated f_purgeZone(z) array.remove(activeZones, i) // Cap array size to prevent memory leaks and chart lag while array.size(activeZones) > i_maxActive FVGZone oldest = array.shift(activeZones) f_purgeZone(oldest) // --------------------------------------------------------------------------------------------------------- // ON-CHART WATERMARK & DESK STATUS // --------------------------------------------------------------------------------------------------------- var table deskHud = table.new(position=position.top_right, columns=1, rows=2, bgcolor=color.new(#030712, 30), border_color=color.new(#1E2D48, 50), border_width=1) if barstate.islast table.cell(deskHud, 0, 0, "LIQUIDITY EDGE | IFVG RADAR", text_color=#38BDF8, text_size=size.tiny, text_font_family=font.family_monospace) string subText = "Active Zones: " + str.tostring(array.size(activeZones)) + " | NQ/MNQ" table.cell(deskHud, 0, 1, subText, text_color=#94A3B8, text_size=size.tiny, text_font_family=font.family_monospace) // --------------------------------------------------------------------------------------------------------- // ALERTS // --------------------------------------------------------------------------------------------------------- if event_bullishInversion and i_alertInversion alert("Liquidity Edge: 🚀 Bullish Inversion FVG (IFVG) Created on " + syminfo.ticker, alert.freq_once_per_bar_close) if event_bearishInversion and i_alertInversion alert("Liquidity Edge: 🩸 Bearish Inversion FVG (IFVG) Created on " + syminfo.ticker, alert.freq_once_per_bar_close) if event_bullishRetest and i_alertRetest alert("Liquidity Edge: 🟢 Bullish IFVG Retest Entry Signal on " + syminfo.ticker, alert.freq_once_per_bar) if event_bearishRetest and i_alertRetest alert("Liquidity Edge: 🔴 Bearish IFVG Retest Entry Signal on " + syminfo.ticker, alert.freq_once_per_bar) // Dedicated alertconditions for TradingView Alert Creation Dialog alertcondition(event_bullishInversion, title="Bullish IFVG Created", message="[Liquidity Edge] Bullish IFVG formed on {{ticker}} at {{close}}") alertcondition(event_bearishInversion, title="Bearish IFVG Created", message="[Liquidity Edge] Bearish IFVG formed on {{ticker}} at {{close}}") alertcondition(event_bullishRetest, title="Bullish IFVG Retest Entry", message="[Liquidity Edge] Long Retest Entry in Bullish IFVG on {{ticker}}") alertcondition(event_bearishRetest, title="Bearish IFVG Retest Entry", message="[Liquidity Edge] Short Retest Entry in Bearish IFVG on {{ticker}}")