本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Smart Liquidity Levels", overlay=true)
// --- Inputs ---
pivotLen = input.int(6, "Liquidity Swing Strength (Pivot Bars)", minval=3, maxval=25)
maxActiveLines = input.int(4, "Max Active Liquidity Levels (Each Side)", minval=1, maxval=10)
sweepDelete = input.bool(true, "Auto-Delete Liquidity Line After Sweep/Break")
sellLiqColor = input.color(color.red, "Buy-Side Liquidity Color (Sell Zone $$$)")
demandLiqColor = input.color(color.green, "Sell-Side Liquidity Color (Demand Zone $$$)")
// --- Helper Function for Clean Timeframe Label ---
getTFStr() =>
if timeframe.isintraday
int mins = timeframe.in_seconds() / 60
mins >= 60 ? str.tostring(mins / 60) + "H" : str.tostring(mins) + "m"
else
timeframe.period
string tfName = getTFStr()
// --- Detect Strong Swing Highs & Lows (Current Chart Timeframe Only) ---
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
var line[] sellLiqLines = array.new_line()
var label[] sellLiqLabels = array.new_label()
var line[] demandLiqLines = array.new_line()
var label[] demandLiqLabels = array.new_label()
// --- 1. Mark Buy-Side Liquidity (Above Swing Highs -> Potential Sell Area) ---
if not na(ph)
int pivotBar = bar_index - pivotLen
string txt = tfName + " Sell Liquidity ($$$)"
line l = line.new(x1=pivotBar, y1=ph, x2=bar_index, y2=ph, color=sellLiqColor, style=line.style_dashed, width=2, extend=extend.right)
label lbl = label.new(x=bar_index + 3, y=ph, text=txt, style=label.style_none, textcolor=sellLiqColor, size=size.small, textalign=text.align_left)
array.push(sellLiqLines, l)
array.push(sellLiqLabels, lbl)
// Keep chart clean by limiting max lines
if array.size(sellLiqLines) > maxActiveLines
line.delete(array.shift(sellLiqLines))
label.delete(array.shift(sellLiqLabels))
// --- 2. Mark Sell-Side Liquidity (Below Swing Lows -> Potential Demand Area) ---
if not na(pl)
int pivotBar = bar_index - pivotLen
string txt = tfName + " Demand Liquidity ($$$)"
line l = line.new(x1=pivotBar, y1=pl, x2=bar_index, y2=pl, color=demandLiqColor, style=line.style_dashed, width=2, extend=extend.right)
label lbl = label.new(x=bar_index + 3, y=pl, text=txt, style=label.style_none, textcolor=demandLiqColor, size=size.small, textalign=text.align_left)
array.push(demandLiqLines, l)
array.push(demandLiqLabels, lbl)
if array.size(demandLiqLines) > maxActiveLines
line.delete(array.shift(demandLiqLines))
label.delete(array.shift(demandLiqLabels))
// --- Update Labels & Auto-Delete Swept/Taken Liquidity ---
bool sellSweepAlert = false
bool demandSweepAlert = false
if array.size(sellLiqLines) > 0
for i = array.size(sellLiqLines) - 1 to 0
line l = array.get(sellLiqLines, i)
label lbl = array.get(sellLiqLabels, i)
float liqPrice = line.get_y1(l)
label.set_x(lbl, bar_index + 3)
// Check if current candle swept above the liquidity level
if barstate.isconfirmed and high > liqPrice
sellSweepAlert := true
alert(tfName + " Sell Liquidity Swept at " + str.tostring(liqPrice) + " on " + syminfo.ticker, alert.freq_once_per_bar_close)
if sweepDelete
line.delete(l)
label.delete(lbl)
array.remove(sellLiqLines, i)
array.remove(sellLiqLabels, i)
if array.size(demandLiqLines) > 0
for i = array.size(demandLiqLines) - 1 to 0
line l = array.get(demandLiqLines, i)
label lbl = array.get(demandLiqLabels, i)
float liqPrice = line.get_y1(l)
label.set_x(lbl, bar_index + 3)
// Check if current candle swept below the liquidity level
if barstate.isconfirmed and low < liqPrice
demandSweepAlert := true
alert(tfName + " Demand Liquidity Swept at " + str.tostring(liqPrice) + " on " + syminfo.ticker, alert.freq_once_per_bar_close)
if sweepDelete
line.delete(l)
label.delete(lbl)
array.remove(demandLiqLines, i)
array.remove(demandLiqLabels, i)
// --- Plot Liquidity Sweep Signals ---
plotshape(sellSweepAlert, title="Sell Liquidity Swept", style=shape.triangledown, location=location.abovebar, color=color.red, text="LIQ SWEPT", textcolor=color.red, size=size.tiny)
plotshape(demandSweepAlert, title="Demand Liquidity Swept", style=shape.triangleup, location=location.belowbar, color=color.green, text="LIQ SWEPT", textcolor=color.green, size=size.tiny)
// --- Alert Conditions ---
alertcondition(sellSweepAlert, title="Sell Liquidity Swept (Look for Sell)", message="Buy-Side Liquidity Swept on {{ticker}} ({{interval}})")
alertcondition(demandSweepAlert, title="Demand Liquidity Swept (Look for Buy)", message="Sell-Side Liquidity Swept on {{ticker}} ({{interval}})")