Liquidity Edge - Inversion FVG (IFVG) Radar PRO

liquidityedgefutures · study · 380 行 · 点赞 43 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LiquidityEdgeFutures ()
// =========================================================================================================
//  LIQUIDITY EDGE | INVERSION FVG (IFVG) & IMBALANCE RADAR [PRO MASTER EDITION]
//  Institutional Order Flow & Smart Money Concepts Engine for CME NQ1!, MNQ1!, ES1!
//
//  Premium Visual Upgrades:
//  - Lighter, ultra-clean glassmorphism transparency (90-92% default) so candles breathe
//  - Right-margin labels: Anchors tags to the right price axis edge (zero chart wick obstruction)
//  - Anti-clutter zone limiter: Intelligently caps active zones & purges mitigated levels
//  - Display filter modes: "Inversion FVGs + Recent Standard", "Inversion FVGs Only", or "All FVGs"
//  - High-visibility Desk HUD with customizable sizing (Normal / Large / Compact)
//  - 100% Pine Script v6 compliant with anti-wrapping multi-line constructor formatting
// =========================================================================================================
 
//@version=6
indicator(
     title="Liquidity Edge - Inversion FVG (IFVG) Radar PRO",
     shorttitle="LE - IFVG Radar PRO",
     overlay=true,
     max_boxes_count=500,
     max_labels_count=500,
     max_lines_count=500
 )
 
// ---------------------------------------------------------------------------------------------------------
// INPUT SETTINGS
// ---------------------------------------------------------------------------------------------------------
var string G_GEN    = "1. General & Display Settings"
var string G_STYLE  = "2. Glassmorphism Visuals & Transparency"
var string G_HUD    = "3. High-Visibility Desk HUD"
var string G_ALERTS = "4. Audio / Webhook Alerts"
 
// General Inputs
string i_displayMode  = input.string("Inversion FVGs + Recent Standard", "Display Mode", options=["Inversion FVGs + Recent Standard", "Inversion FVGs Only (Ultra Clean)", "All FVGs"], group=G_GEN)
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(6, "Max Active Zones Stored", minval=2, maxval=25, tooltip="Default 6 prevents chart clutter. When zones mitigate, they are cleanly purged.", group=G_GEN)
string i_labelPos     = input.string("Right Margin", "Label Position", options=["Right Margin", "Left Origin", "None"], tooltip="Right Margin places tags neatly by the price scale, keeping candles 100% clean.", group=G_GEN)
bool   i_showMidline  = input.bool(true, "Show 50% Consequent Encroachment (CE)", group=G_GEN)
color  i_ce_color     = input.color(color.new(#94A3B8, 40), "50% CE Midline Color", group=G_GEN)
 
// Glassmorphism Visuals & Transparency
int    i_transp       = input.int(90, "Zone Fill Transparency % (Higher = Lighter / Subtle)", minval=50, maxval=98, step=2, tooltip="90-92% gives an institutional glass look that lets candles shine through.", group=G_STYLE)
color  i_c_bull_ifvg  = input.color(#00F2FE, "Bullish IFVG Color (Electric Cyan)", group=G_STYLE)
color  i_c_bear_ifvg  = input.color(#F59E0B, "Bearish IFVG Color (Institutional Amber)", group=G_STYLE)
color  i_c_bisi       = input.color(#10B981, "Standard BISI FVG Color (Emerald)", group=G_STYLE)
color  i_c_sibi       = input.color(#EF4444, "Standard SIBI FVG Color (Crimson)", group=G_STYLE)
 
// Desk HUD
bool   i_showHud      = input.bool(true, "Display Desk Telemetry HUD", group=G_HUD)
string i_hudPosition  = input.string("Top Right", "HUD Position", options=["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group=G_HUD)
string i_hudSize      = input.string("Normal (Readable)", "HUD Text Size", options=["Normal (Readable)", "Large (High-Res Monitors)", "Compact (Small)"], group=G_HUD)
 
// 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<FVGZone>()
 
// Clean up function to remove old zones
f_purgeZone(FVGZone z) =>
    if not na(z.bx)
        box.delete(z.bx)
    if not na(z.ln_ce)
        line.delete(z.ln_ce)
    if not na(z.lbl)
        label.delete(z.lbl)
 
// ---------------------------------------------------------------------------------------------------------
// FVG IDENTIFICATION LOGIC (3-Candle Sequences)
// ---------------------------------------------------------------------------------------------------------
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
    int projRight = bar_index + 4
 
    if isBISI
        float topPrice    = low
        float bottomPrice = high[2]
        float midPrice    = (topPrice + bottomPrice) / 2.0
        int   startBar    = bar_index[1]
 
        bool showInitial = i_displayMode != "Inversion FVGs Only (Ultra Clean)"
        color fillColor  = showInitial ? color.new(i_c_bisi, i_transp + 2) : color.new(color.black, 100)
        color bordColor  = showInitial ? color.new(i_c_bisi, 40) : color.new(color.black, 100)
 
        box b = box.new(
             left=startBar,
             top=topPrice,
             right=projRight,
             bottom=bottomPrice,
             border_color=bordColor,
             border_width=1,
             bgcolor=fillColor
         )
 
        line l = (i_showMidline and showInitial) ? line.new(
             x1=startBar,
             y1=midPrice,
             x2=projRight,
             y2=midPrice,
             color=i_ce_color,
             style=line.style_dashed,
             width=1
         ) : na
 
        label lb = na
        if i_labelPos != "None" and showInitial
            int lblX = i_labelPos == "Right Margin" ? projRight + 1 : startBar
            label_style = i_labelPos == "Right Margin" ? label.style_label_left : label.style_none
            string lblTxt = "BISI FVG (" + str.tostring(midPrice, "#.##") + ")"
            lb := label.new(
                 x=lblX,
                 y=midPrice,
                 text=lblTxt,
                 color=color.new(color.black, 100),
                 textcolor=color.new(i_c_bisi, 20),
                 style=label_style,
                 size=size.tiny
             )
 
        FVGZone nz = FVGZone.new(
             bx=b,
             ln_ce=l,
             lbl=lb,
             top=topPrice,
             bottom=bottomPrice,
             ce=midPrice,
             leftBar=startBar,
             isBullish=true,
             isInverted=false,
             isMitigated=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]
 
        bool showInitial = i_displayMode != "Inversion FVGs Only (Ultra Clean)"
        color fillColor  = showInitial ? color.new(i_c_sibi, i_transp + 2) : color.new(color.black, 100)
        color bordColor  = showInitial ? color.new(i_c_sibi, 40) : color.new(color.black, 100)
 
        box b = box.new(
             left=startBar,
             top=topPrice,
             right=projRight,
             bottom=bottomPrice,
             border_color=bordColor,
             border_width=1,
             bgcolor=fillColor
         )
 
        line l = (i_showMidline and showInitial) ? line.new(
             x1=startBar,
             y1=midPrice,
             x2=projRight,
             y2=midPrice,
             color=i_ce_color,
             style=line.style_dashed,
             width=1
         ) : na
 
        label lb = na
        if i_labelPos != "None" and showInitial
            int lblX = i_labelPos == "Right Margin" ? projRight + 1 : startBar
            label_style = i_labelPos == "Right Margin" ? label.style_label_left : label.style_none
            string lblTxt = "SIBI FVG (" + str.tostring(midPrice, "#.##") + ")"
            lb := label.new(
                 x=lblX,
                 y=midPrice,
                 text=lblTxt,
                 color=color.new(color.black, 100),
                 textcolor=color.new(i_c_sibi, 20),
                 style=label_style,
                 size=size.tiny
             )
 
        FVGZone nz = FVGZone.new(
             bx=b,
             ln_ce=l,
             lbl=lb,
             top=topPrice,
             bottom=bottomPrice,
             ce=midPrice,
             leftBar=startBar,
             isBullish=false,
             isInverted=false,
             isMitigated=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, color.new(i_c_bear_ifvg, i_transp))
                    box.set_border_color(z.bx, color.new(i_c_bear_ifvg, 30))
                    box.set_border_width(z.bx, 1)
 
                    if not na(z.ln_ce) and i_showMidline
                        line.set_color(z.ln_ce, color.new(i_c_bear_ifvg, 50))
 
                    if not na(z.lbl) and i_labelPos != "None"
                        label.set_text(z.lbl, "BEARISH IFVG (" + str.tostring(z.ce, "#.##") + ")")
                        label.set_textcolor(z.lbl, i_c_bear_ifvg)
                    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, color.new(i_c_bull_ifvg, i_transp))
                    box.set_border_color(z.bx, color.new(i_c_bull_ifvg, 30))
                    box.set_border_width(z.bx, 1)
 
                    if not na(z.ln_ce) and i_showMidline
                        line.set_color(z.ln_ce, color.new(i_c_bull_ifvg, 50))
 
                    if not na(z.lbl) and i_labelPos != "None"
                        label.set_text(z.lbl, "BULLISH IFVG (" + str.tostring(z.ce, "#.##") + ")")
                        label.set_textcolor(z.lbl, i_c_bull_ifvg)
                    event_bullishInversion := true
        else
            // Zone is already an Inversion FVG -> Check for Retest Entry or Total Mitigation
            if not z.isBullish
                // Bullish IFVG (Support): Retest condition
                if (low <= z.top and low >= z.bottom and close >= z.bottom)
                    event_bullishRetest := true
                // Invalidation / mitigation: close below bottom
                if close < z.bottom
                    z.isMitigated := true
            else
                // Bearish IFVG (Resistance): Retest condition
                if (high >= z.bottom and high <= z.top and close <= z.top)
                    event_bearishRetest := true
                // Invalidation / mitigation: close above top
                if close > z.top
                    z.isMitigated := true
 
        // Extend active unmitigated zones to right price margin
        if not z.isMitigated
            int rightEdge = bar_index + 4
            box.set_right(z.bx, rightEdge)
            if not na(z.ln_ce)
                line.set_x2(z.ln_ce, rightEdge)
            if not na(z.lbl)
                if i_labelPos == "Right Margin"
                    label.set_x(z.lbl, rightEdge + 1)
                else if i_labelPos == "Left Origin"
                    label.set_x(z.lbl, z.leftBar)
        else
            // Purge mitigated zone from memory & chart
            f_purgeZone(z)
            array.remove(activeZones, i)
 
// Cap array size to prevent memory leaks and chart clutter
while array.size(activeZones) > i_maxActive
    FVGZone oldest = array.shift(activeZones)
    f_purgeZone(oldest)
 
// ---------------------------------------------------------------------------------------------------------
// ON-CHART HIGH-VISIBILITY DESK TELEMETRY HUD
// ---------------------------------------------------------------------------------------------------------
hud_pos = i_hudPosition == "Top Right" ? position.top_right : (i_hudPosition == "Bottom Right" ? position.bottom_right : (i_hudPosition == "Top Left" ? position.top_left : position.bottom_left))
 
hud_hdrSize  = i_hudSize == "Large (High-Res Monitors)" ? size.normal : (i_hudSize == "Compact (Small)" ? size.small : size.normal)
hud_bodySize = i_hudSize == "Large (High-Res Monitors)" ? size.normal : (i_hudSize == "Compact (Small)" ? size.tiny : size.small)
 
var table deskHud = table.new(
     position=hud_pos,
     columns=2,
     rows=4,
     bgcolor=color.new(#030712, 10),
     border_color=color.new(#1E2D48, 30),
     border_width=1
 )
 
if i_showHud and barstate.islast
    // Count active IFVGs vs Standard
    int activeIFVG = 0
    int activeBISI = 0
    int activeSIBI = 0
    float nearestCE = na
    float minCeDist = 99999.0
 
    if array.size(activeZones) > 0
        for k = 0 to array.size(activeZones) - 1
            FVGZone zone = array.get(activeZones, k)
            if zone.isInverted
                activeIFVG += 1
            else if zone.isBullish
                activeBISI += 1
            else
                activeSIBI += 1
 
            float dist = math.abs(close - zone.ce)
            if dist < minCeDist
                minCeDist := dist
                nearestCE := zone.ce
 
    // Header
    color hdrBg = activeIFVG > 0 ? #0E3B43 : #0A0F1D
    table.cell(deskHud, 0, 0, "⚡ LIQUIDITY EDGE", text_color=#38BDF8, text_size=hud_hdrSize, text_font_family=font.family_monospace, bgcolor=hdrBg)
    table.cell(deskHud, 1, 0, "IFVG RADAR PRO", text_color=#F8FAFC, text_size=hud_hdrSize, text_font_family=font.family_monospace, bgcolor=hdrBg)
 
    // Row 1: Active Inversion Zones
    string ifvgTxt = str.tostring(activeIFVG) + " Active (" + str.tostring(array.size(activeZones)) + " Total Tracked)"
    color  ifvgCol = activeIFVG > 0 ? #00F2FE : #94A3B8
    table.cell(deskHud, 0, 1, "Inversion Zones", text_color=#94A3B8, text_size=hud_bodySize, text_font_family=font.family_monospace)
    table.cell(deskHud, 1, 1, ifvgTxt, text_color=ifvgCol, text_size=hud_bodySize, text_font_family=font.family_monospace)
 
    // Row 2: Nearest 50% CE Midline
    string ceTxt = not na(nearestCE) ? str.tostring(nearestCE, "#.##") + " (" + (nearestCE > close ? "+" : "") + str.tostring(nearestCE - close, "#.#") + " pts)" : "No Active Midline"
    color  ceCol = not na(nearestCE) ? (nearestCE > close ? #EF4444 : #10B981) : #64748B
    table.cell(deskHud, 0, 2, "Nearest 50% CE", text_color=#94A3B8, text_size=hud_bodySize, text_font_family=font.family_monospace)
    table.cell(deskHud, 1, 2, ceTxt, text_color=ceCol, text_size=hud_bodySize, text_font_family=font.family_monospace)
 
    // Row 3: Order Flow Status
    string statusTxt = event_bullishRetest ? "🟢 BULLISH IFVG RETEST ENTRY" : (event_bearishRetest ? "🔴 BEARISH IFVG RETEST ENTRY" : (activeIFVG > 0 ? "⚡ INVERSION STRUCTURE ACTIVE" : "STANDARD IMBALANCES"))
    color  statusCol = event_bullishRetest ? #10B981 : (event_bearishRetest ? #EF4444 : (activeIFVG > 0 ? #00F2FE : #64748B))
    table.cell(deskHud, 0, 3, "Radar Status", text_color=#94A3B8, text_size=hud_bodySize, text_font_family=font.family_monospace)
    table.cell(deskHud, 1, 3, statusTxt, text_color=statusCol, text_size=hud_bodySize, 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}}")

← 返回列表