Liquidity Edge - Institutional Volume Displacement & Delta PRO

liquidityedgefutures · study · 418 行 · 点赞 52 · 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 | INSTITUTIONAL VOLUME DISPLACEMENT & ORDER FLOW DELTA [ELITE PRO EDITION]
//  Precision Momentum Validator, RVOL Spikes, 50% CE Zones & Retest Engine for CME NQ1!, MNQ1!, ES1!
// =========================================================================================================
 
//@version=6
indicator(
     title="Liquidity Edge - Institutional Volume Displacement & Delta PRO",
     shorttitle="LE - Volume Displacement PRO",
     overlay=true,
     max_boxes_count=500,
     max_lines_count=500,
     max_labels_count=500
 )
 
// ---------------------------------------------------------------------------------------------------------
// INPUT CONFIGURATION
// ---------------------------------------------------------------------------------------------------------
var string G_FILTER = "1. Institutional Displacement Thresholds"
var string G_SIGNAL = "2. Signal Aesthetic & De-Duplication"
var string G_ZONES  = "3. On-Chart Displacement Range & 50% CE"
var string G_HUD    = "4. Telemetry Dashboard HUD"
var string G_ALERTS = "5. Audio & Webhook Alerts"
 
// Thresholds
float  i_rvolThreshold  = input.float(1.5, "Min Relative Volume (RVOL) Multiplier", minval=1.1, maxval=4.0, step=0.1, tooltip="Volume must be at least 1.5x the 20-period moving average.", group=G_FILTER)
float  i_bodyThreshold  = input.float(0.65, "Min Candle Body-to-Range Ratio", minval=0.50, maxval=0.90, step=0.05, tooltip="65% body-to-range filters out wicks, confirming pure institutional displacement.", group=G_FILTER)
int    i_volSmaPeriod   = input.int(20, "Volume Moving Average Period", minval=5, maxval=100, group=G_FILTER)
 
// Signal Styling
string i_signalStyle    = input.string("Sleek Minimalist Shapes", "Signal Display Mode", options=["Sleek Minimalist Shapes", "RVOL Data Badges (e.g. ▲ 2.1x)", "Subtle Candle Barcolor Only"], group=G_SIGNAL)
bool   i_filterConsec   = input.bool(true, "De-Duplicate Consecutive Signals", tooltip="Only signals the initiating displacement bar of a momentum leg, eliminating overlapping clutter.", group=G_SIGNAL)
bool   i_colorCandles   = input.bool(true, "Tint Displacement Candles On Chart", group=G_SIGNAL)
color  i_c_bull_disp    = input.color(#00F2FE, "Bullish Displacement Color (Electric Cyan)", group=G_SIGNAL)
color  i_c_bear_disp    = input.color(#FF2A5F, "Bearish Displacement Color (Vivid Crimson)", group=G_SIGNAL)
 
// Displacement Range & CE Engine
bool   i_showDispZones  = input.bool(true, "Project Recent Displacement Range & 50% CE", group=G_ZONES)
int    i_maxZones       = input.int(4, "Max Active Displacement Zones", minval=1, maxval=10, group=G_ZONES)
bool   i_showCeMidline  = input.bool(true, "Show 50% Consequent Encroachment (CE)", group=G_ZONES)
color  i_ce_color       = input.color(#38BDF8, "50% CE Midline Color", group=G_ZONES)
bool   i_trackRetest    = input.bool(true, "Highlight 50% CE Retest Entries", tooltip="Detects when price pulls back into the 50% midpoint of the displacement candle for an entry.", group=G_ZONES)
color  i_c_bull_retest  = input.color(#10B981, "Bullish Retest Color (Emerald Green)", group=G_ZONES)
color  i_c_bear_retest  = input.color(#F59E0B, "Bearish Retest Color (Amber Gold)", group=G_ZONES)
 
// HUD Table
bool   i_showHud        = input.bool(true, "Show Volume Delta Telemetry HUD", group=G_HUD)
string i_hudPos         = input.string("Bottom Right", "HUD Position", options=["Bottom Right", "Bottom Left", "Top Right", "Top Left"], group=G_HUD)
string i_hudSize        = input.string("Normal", "HUD Text Size", options=["Normal", "Large", "Compact"], group=G_HUD)
 
// Alerts
bool   i_alt_bull       = input.bool(true, "Alert: Bullish Institutional Displacement", group=G_ALERTS)
bool   i_alt_bear       = input.bool(true, "Alert: Bearish Institutional Displacement", group=G_ALERTS)
bool   i_alt_retest     = input.bool(true, "Alert: Displacement 50% CE Retest", group=G_ALERTS)
 
// ---------------------------------------------------------------------------------------------------------
// RELATIVE VOLUME & DISPLACEMENT CALCULATIONS
// ---------------------------------------------------------------------------------------------------------
float volSMA   = ta.sma(volume, i_volSmaPeriod)
float rvol     = volSMA > 0 ? (volume / volSMA) : 1.0
bool  hasRVOL  = volume >= (volSMA * i_rvolThreshold)
 
float candleRange = high - low
float candleBody  = math.abs(close - open)
float bodyRatio   = candleRange > 0 ? (candleBody / candleRange) : 0.0
bool  hasBody     = bodyRatio >= i_bodyThreshold
 
bool isBullBar = close > open
bool isBearBar = close < open
 
// Raw Displacement Signals
bool rawBullDisp = hasRVOL and hasBody and isBullBar
bool rawBearDisp = hasRVOL and hasBody and isBearBar
 
// De-duplication: Only trigger on initiating bar if filter enabled
var bool inBullRun = false
var bool inBearRun = false
 
bool trigBullDisp = false
bool trigBearDisp = false
 
if rawBullDisp
    if not i_filterConsec or not inBullRun
        trigBullDisp := true
    inBullRun := true
    inBearRun := false
else
    inBullRun := false
 
if rawBearDisp
    if not i_filterConsec or not inBearRun
        trigBearDisp := true
    inBearRun := true
    inBullRun := false
else
    inBearRun := false
 
// Estimated Volume Delta Footprint
float upVolRatio   = candleRange > 0 ? ((close - low) / candleRange) : 0.5
float estBuyVol    = volume * upVolRatio
float estSellVol   = volume * (1.0 - upVolRatio)
float deltaVol     = estBuyVol - estSellVol
float deltaPct     = volume > 0 ? ((deltaVol / volume) * 100.0) : 0.0
 
// Visual RVOL Progress Bar Generator
f_rvolGauge(float r) =>
    int filled = math.min(10, math.max(0, math.round(r * 2.5)))
    string bar = ""
    for k = 0 to 9
        bar := bar + (k < filled ? "█" : "░")
    bar
 
// ---------------------------------------------------------------------------------------------------------
// ON-CHART VISUAL ENGINE (Clean, Minimalist & Anti-Clutter)
// ---------------------------------------------------------------------------------------------------------
// 1. Sleek Candle Color Tinting
barcolor(i_colorCandles ? (rawBullDisp ? i_c_bull_disp : (rawBearDisp ? i_c_bear_disp : na)) : na)
 
// 2. Signals on Chart
bool useShapes = i_signalStyle == "Sleek Minimalist Shapes"
bool useBadges = i_signalStyle == "RVOL Data Badges (e.g. ▲ 2.1x)"
 
// Sleek Clean Arrows (Zero text overlap)
plotshape(
     useShapes and trigBullDisp,
     title="Bullish Displacement Chevron",
     style=shape.triangleup,
     location=location.belowbar,
     color=i_c_bull_disp,
     size=size.small
 )
 
plotshape(
     useShapes and trigBearDisp,
     title="Bearish Displacement Chevron",
     style=shape.triangledown,
     location=location.abovebar,
     color=i_c_bear_disp,
     size=size.small
 )
 
// Micro Data Badges (Showing exact RVOL multiplier)
if useBadges and trigBullDisp
    string txt = "▲ " + str.tostring(rvol, "#.#") + "x"
    label.new(
         x=bar_index,
         y=low,
         text=txt,
         yloc=yloc.belowbar,
         color=color.new(#030712, 10),
         textcolor=i_c_bull_disp,
         style=label.style_label_up,
         size=size.tiny
     )
 
if useBadges and trigBearDisp
    string txt = "▼ " + str.tostring(rvol, "#.#") + "x"
    label.new(
         x=bar_index,
         y=high,
         text=txt,
         yloc=yloc.abovebar,
         color=color.new(#030712, 10),
         textcolor=i_c_bear_disp,
         style=label.style_label_down,
         size=size.tiny
     )
 
// ---------------------------------------------------------------------------------------------------------
// DISPLACEMENT RANGE & 50% CE PROJECTION ENGINE
// ---------------------------------------------------------------------------------------------------------
type DispZone
    box   bx
    line  ln_ce
    label lbl
    float top
    float bottom
    float ce
    int   leftBar
    bool  isBull
    bool  isMitigated
 
var DispZone[] activeZones = array.new<DispZone>()
 
// Purge helper
f_purgeDispZone(DispZone 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)
 
// Trigger Retest Signal Flag
bool event_bullRetest = false
bool event_bearRetest = false
 
// Register new zone on initiating displacement bar close
if barstate.isconfirmed
    if trigBullDisp and i_showDispZones
        float zTop = close
        float zBot = open
        float zCe  = (zTop + zBot) / 2.0
        int   zBar = bar_index
        int   zRight = bar_index + 12
 
        box b = box.new(
             left=zBar,
             top=zTop,
             right=zRight,
             bottom=zBot,
             border_color=color.new(i_c_bull_disp, 40),
             border_width=1,
             bgcolor=color.new(i_c_bull_disp, 88)
         )
 
        line l = i_showCeMidline ? line.new(
             x1=zBar,
             y1=zCe,
             x2=zRight,
             y2=zCe,
             color=i_ce_color,
             style=line.style_dashed,
             width=1
         ) : na
 
        string lblTxt = "50% CE: " + str.tostring(zCe, "#.##")
        label lb = label.new(
             x=zRight,
             y=zCe,
             text=lblTxt,
             color=color.new(color.black, 100),
             textcolor=i_c_bull_disp,
             style=label.style_none,
             size=size.tiny
         )
 
        DispZone nz = DispZone.new(
             bx=b,
             ln_ce=l,
             lbl=lb,
             top=zTop,
             bottom=zBot,
             ce=zCe,
             leftBar=zBar,
             isBull=true,
             isMitigated=false
         )
        array.push(activeZones, nz)
 
    if trigBearDisp and i_showDispZones
        float zTop = open
        float zBot = close
        float zCe  = (zTop + zBot) / 2.0
        int   zBar = bar_index
        int   zRight = bar_index + 12
 
        box b = box.new(
             left=zBar,
             top=zTop,
             right=zRight,
             bottom=zBot,
             border_color=color.new(i_c_bear_disp, 40),
             border_width=1,
             bgcolor=color.new(i_c_bear_disp, 88)
         )
 
        line l = i_showCeMidline ? line.new(
             x1=zBar,
             y1=zCe,
             x2=zRight,
             y2=zCe,
             color=i_ce_color,
             style=line.style_dashed,
             width=1
         ) : na
 
        string lblTxt = "50% CE: " + str.tostring(zCe, "#.##")
        label lb = label.new(
             x=zRight,
             y=zCe,
             text=lblTxt,
             color=color.new(color.black, 100),
             textcolor=i_c_bear_disp,
             style=label.style_none,
             size=size.tiny
         )
 
        DispZone nz = DispZone.new(
             bx=b,
             ln_ce=l,
             lbl=lb,
             top=zTop,
             bottom=zBot,
             ce=zCe,
             leftBar=zBar,
             isBull=false,
             isMitigated=false
         )
        array.push(activeZones, nz)
 
// Track zone extension & Retest Entries
if barstate.isconfirmed and array.size(activeZones) > 0
    for i = array.size(activeZones) - 1 to 0
        DispZone z = array.get(activeZones, i)
 
        if not z.isMitigated
            // Check for 50% CE Retest
            if z.isBull
                // Price dips into 50% CE from above
                if (low <= z.ce and close >= z.bottom and low[1] > z.ce)
                    event_bullRetest := true
                // Invalidation: candle closes below bottom of displacement body
                if close < z.bottom
                    z.isMitigated := true
            else
                // Price rallies into 50% CE from below
                if (high >= z.ce and close <= z.top and high[1] < z.ce)
                    event_bearRetest := true
                // Invalidation: candle closes above top of displacement body
                if close > z.top
                    z.isMitigated := true
 
        // Extend zone right edge until invalidated
        if not z.isMitigated
            int extendRight = bar_index + 6
            box.set_right(z.bx, extendRight)
            if not na(z.ln_ce)
                line.set_x2(z.ln_ce, extendRight)
            if not na(z.lbl)
                label.set_x(z.lbl, extendRight)
        else
            f_purgeDispZone(z)
            array.remove(activeZones, i)
 
// Cap zone memory
while array.size(activeZones) > i_maxZones
    DispZone old = array.shift(activeZones)
    f_purgeDispZone(old)
 
// Plot Retest Entry Shapes
plotshape(
     i_trackRetest and event_bullRetest,
     title="50% CE Bullish Retest Entry",
     style=shape.diamond,
     location=location.belowbar,
     color=i_c_bull_retest,
     size=size.tiny
 )
 
plotshape(
     i_trackRetest and event_bearRetest,
     title="50% CE Bearish Retest Entry",
     style=shape.diamond,
     location=location.abovebar,
     color=i_c_bear_retest,
     size=size.tiny
 )
 
// ---------------------------------------------------------------------------------------------------------
// HUD TELEMETRY DASHBOARD
// ---------------------------------------------------------------------------------------------------------
hud_position = i_hudPos == "Top Right" ? position.top_right : (i_hudPos == "Bottom Right" ? position.bottom_right : (i_hudPos == "Top Left" ? position.top_left : position.bottom_left))
hud_fontSize = i_hudSize == "Large" ? size.small : (i_hudSize == "Compact" ? size.tiny : size.tiny)
 
var table hud = table.new(
     position=hud_position,
     columns=2,
     rows=6,
     bgcolor=color.new(#030712, 10),
     border_color=color.new(#1E2D48, 30),
     border_width=1
 )
 
if i_showHud and barstate.islast
    // Header
    color hdrBg = rawBullDisp ? #0E3B43 : (rawBearDisp ? #451A03 : #0A0F1D)
    string hdrText = rawBullDisp ? "⚡ BULLISH EXPANSION" : (rawBearDisp ? "🩸 BEARISH EXPANSION" : "⚡ ORDER FLOW: BALANCED")
    table.cell(hud, 0, 0, "LIQUIDITY EDGE", text_color=#38BDF8, text_size=hud_fontSize, text_font_family=font.family_monospace, bgcolor=hdrBg)
    table.cell(hud, 1, 0, hdrText, text_color=#FFFFFF, text_size=hud_fontSize, text_font_family=font.family_monospace, bgcolor=hdrBg)
 
    // RVOL Multiplier with Gauge
    color rvolCol = rvol >= 2.0 ? #00F2FE : (rvol >= i_rvolThreshold ? #10B981 : #94A3B8)
    string rvolTxt = f_rvolGauge(rvol) + " " + str.tostring(rvol, "#.##") + "x (" + str.tostring(volume, "#,###") + " vs " + str.tostring(volSMA, "#,###") + ")"
    table.cell(hud, 0, 1, "Relative Vol (RVOL)", text_color=#94A3B8, text_size=hud_fontSize, text_font_family=font.family_monospace)
    table.cell(hud, 1, 1, rvolTxt, text_color=rvolCol, text_size=hud_fontSize, text_font_family=font.family_monospace)
 
    // Body Commitment
    color bodyCol = bodyRatio >= 0.75 ? #10B981 : (bodyRatio >= i_bodyThreshold ? #38BDF8 : #94A3B8)
    string bodyTxt = str.tostring(bodyRatio * 100.0, "#.#") + "% Body (Min: " + str.tostring(i_bodyThreshold * 100.0, "#") + "%)"
    table.cell(hud, 0, 2, "Body Ratio", text_color=#94A3B8, text_size=hud_fontSize, text_font_family=font.family_monospace)
    table.cell(hud, 1, 2, bodyTxt, text_color=bodyCol, text_size=hud_fontSize, text_font_family=font.family_monospace)
 
    // Volume Delta Footprint
    color deltaCol = deltaVol > 0 ? #10B981 : (deltaVol < 0 ? #EF4444 : #94A3B8)
    string deltaTxt = (deltaVol > 0 ? "+$" : "-$") + str.tostring(math.abs(deltaPct), "#.#") + "% (" + (deltaVol > 0 ? "Buyers In Control" : "Sellers In Control") + ")"
    table.cell(hud, 0, 3, "Volume Delta", text_color=#94A3B8, text_size=hud_fontSize, text_font_family=font.family_monospace)
    table.cell(hud, 1, 3, deltaTxt, text_color=deltaCol, text_size=hud_fontSize, text_font_family=font.family_monospace)
 
    // Active Zones
    table.cell(hud, 0, 4, "Active 50% CE Zones", text_color=#94A3B8, text_size=hud_fontSize, text_font_family=font.family_monospace)
    table.cell(hud, 1, 4, str.tostring(array.size(activeZones)) + " tracked on chart", text_color=#F8FAFC, text_size=hud_fontSize, text_font_family=font.family_monospace)
 
    // Setup Grade
    string gradeTxt = (rawBullDisp or rawBearDisp) ? "⭐ A+ INSTITUTIONAL EXPANSION" : (event_bullRetest or event_bearRetest ? "⚡ A+ 50% CE RETEST ENTRY" : "PULSE: STANDARD FLOW")
    color  gradeCol = (rawBullDisp or rawBearDisp) ? #00F2FE : (event_bullRetest or event_bearRetest ? #10B981 : #64748B)
    table.cell(hud, 0, 5, "Trade Setup Grade", text_color=#94A3B8, text_size=hud_fontSize, text_font_family=font.family_monospace)
    table.cell(hud, 1, 5, gradeTxt, text_color=gradeCol, text_size=hud_fontSize, text_font_family=font.family_monospace)
 
// ---------------------------------------------------------------------------------------------------------
// ALERTS
// ---------------------------------------------------------------------------------------------------------
alertcondition(trigBullDisp, title="Bullish Institutional Displacement", message="[Liquidity Edge] 🚀 High-Volume Bullish Displacement on {{ticker}}! RVOL: {{volume}}")
alertcondition(trigBearDisp, title="Bearish Institutional Displacement", message="[Liquidity Edge] 🩸 High-Volume Bearish Displacement on {{ticker}}! RVOL: {{volume}}")
alertcondition(event_bullRetest, title="Bullish 50% CE Retest Entry", message="[Liquidity Edge] 🟢 High-Probability 50% CE Bullish Retest Entry on {{ticker}} at {{close}}!")
alertcondition(event_bearRetest, title="Bearish 50% CE Retest Entry", message="[Liquidity Edge] 🔴 High-Probability 50% CE Bearish Retest Entry on {{ticker}} at {{close}}!")

← 返回列表