本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Liquidity Trap & Power Detector Pro", shorttitle="LTP Detector", overlay=true, max_labels_count=300, max_lines_count=100)
// ======================================
// INPUT SETTINGS
// ======================================
pivotLen = input.int(5, "Liquidity Swing Length", minval=2)
powerThreshold = input.float(60, "Minimum Buyer/Seller Power %", minval=50, maxval=95)
showLiquidity = input.bool(true, "Show Liquidity Levels")
showSignals = input.bool(true, "Show BUY/SELL Signals")
showDashboard = input.bool(true, "Show Power Dashboard")
showPowerLabels = input.bool(true, "Show Sweep Labels")
// ======================================
// LIQUIDITY DETECTION
// ======================================
pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
var float lastHigh = na
var float lastLow = na
var bool highSwept = false
var bool lowSwept = false
if not na(pivotHigh)
lastHigh := pivotHigh
highSwept := false
if not na(pivotLow)
lastLow := pivotLow
lowSwept := false
// LIQUIDITY SWEEP
bearishSweep = barstate.isconfirmed and not na(lastHigh) and high > lastHigh and close < lastHigh and not highSwept
bullishSweep = barstate.isconfirmed and not na(lastLow) and low < lastLow and close > lastLow and not lowSwept
if bearishSweep
highSwept := true
if bullishSweep
lowSwept := true
// ======================================
// BUYER VS SELLER POWER
// Candle-based pressure estimate
// ======================================
candleRange = math.max(high - low, syminfo.mintick)
buyPower = 100 * (close - low) / candleRange
sellPower = 100 - buyPower
buyerDominant = buyPower >= powerThreshold
sellerDominant = sellPower >= powerThreshold
// ======================================
// COMBINED CONFIRMATION
// ======================================
buySignal = bullishSweep and buyerDominant
sellSignal = bearishSweep and sellerDominant
// ======================================
// LIQUIDITY LEVEL PLOTS
// ======================================
plot(showLiquidity ? lastHigh : na, "Buy Side Liquidity", color=color.new(color.red, 30), linewidth=1, style=plot.style_stepline)
plot(showLiquidity ? lastLow : na, "Sell Side Liquidity", color=color.new(color.lime, 30), linewidth=1, style=plot.style_stepline)
// ======================================
// SIGNAL LABELS
// ======================================
plotshape(showSignals and buySignal, title="Liquidity BUY", style=shape.labelup, location=location.belowbar, color=color.green, text="BUY\nSWEEP", textcolor=color.white, size=size.small)
plotshape(showSignals and sellSignal, title="Liquidity SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL\nSWEEP", textcolor=color.white, size=size.small)
// SWEEP WITHOUT POWER CONFIRMATION
plotshape(showPowerLabels and bullishSweep and not buyerDominant, title="Bullish Sweep Wait", style=shape.circle, location=location.belowbar, color=color.orange, text="WAIT", textcolor=color.white, size=size.tiny)
plotshape(showPowerLabels and bearishSweep and not sellerDominant, title="Bearish Sweep Wait", style=shape.circle, location=location.abovebar, color=color.orange, text="WAIT", textcolor=color.white, size=size.tiny)
// ======================================
// MARKET STATUS
// ======================================
powerStatus = buyerDominant ? "BUYERS DOMINANT" : sellerDominant ? "SELLERS DOMINANT" : "BALANCED"
signalStatus = buySignal ? "BUY CONFIRMED" : sellSignal ? "SELL CONFIRMED" : bullishSweep ? "BULLISH SWEEP - WAIT" : bearishSweep ? "BEARISH SWEEP - WAIT" : "NO CONFIRMED SETUP"
signalColor = buySignal ? color.green : sellSignal ? color.red : color.orange
// ======================================
// DASHBOARD
// ======================================
var table dash = table.new(position.top_right, 2, 7, border_width=1)
if barstate.islast and showDashboard
table.cell(dash, 0, 0, "LIQUIDITY TRAP", bgcolor=color.rgb(25,35,55), text_color=color.white)
table.cell(dash, 1, 0, "POWER PRO", bgcolor=color.rgb(25,35,55), text_color=color.aqua)
table.cell(dash, 0, 1, "Buyer Power", text_color=color.white)
table.cell(dash, 1, 1, str.tostring(buyPower, "#.0") + "%", text_color=color.lime)
table.cell(dash, 0, 2, "Seller Power", text_color=color.white)
table.cell(dash, 1, 2, str.tostring(sellPower, "#.0") + "%", text_color=color.red)
table.cell(dash, 0, 3, "Dominance", text_color=color.white)
table.cell(dash, 1, 3, powerStatus, text_color=buyerDominant ? color.lime : sellerDominant ? color.red : color.orange)
table.cell(dash, 0, 4, "Liquidity", text_color=color.white)
table.cell(dash, 1, 4, bullishSweep ? "SELL-SIDE SWEPT" : bearishSweep ? "BUY-SIDE SWEPT" : "NO SWEEP", text_color=color.aqua)
table.cell(dash, 0, 5, "Decision", text_color=color.white)
table.cell(dash, 1, 5, signalStatus, text_color=color.white, bgcolor=signalColor)
table.cell(dash, 0, 6, "Confirmation", text_color=color.white)
table.cell(dash, 1, 6, buySignal or sellSignal ? "CONFIRMED" : "WAIT", text_color=buySignal or sellSignal ? color.lime : color.orange)
if barstate.islast and not showDashboard
table.clear(dash, 0, 0, 1, 6)
// ======================================
// ALERTS
// ======================================
alertcondition(buySignal, title="Bullish Liquidity Trap", message="Bullish liquidity sweep with buyer pressure confirmation on {{ticker}}")
alertcondition(sellSignal, title="Bearish Liquidity Trap", message="Bearish liquidity sweep with seller pressure confirmation on {{ticker}}")
alertcondition(bullishSweep, title="Bullish Sweep Detected", message="Sell-side liquidity sweep detected on {{ticker}}")
alertcondition(bearishSweep, title="Bearish Sweep Detected", message="Buy-side liquidity sweep detected on {{ticker}}")