本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ReubenMiles
//@version=6
indicator("Liquidity Hunter Pro", overlay=true, max_labels_count=500, max_lines_count=100)
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
swingLen = input.int(5, "Swing Length", minval=2, maxval=50)
showLiquidity = input.bool(true, "Show Liquidity Levels")
showEqual = input.bool(true, "Show Equal Highs / Lows")
showSignals = input.bool(true, "Show BUY / SELL Signals")
showSweeps = input.bool(true, "Show Sweep Labels")
tolerance = input.float(0.10, "Equal High/Low Tolerance (ATR)", minval=0.01, step=0.01)
atrLen = input.int(14, "ATR Length")
bullColor = input.color(color.lime, "Bullish Color")
bearColor = input.color(color.red, "Bearish Color")
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY DETECTION
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLen)
pivotHigh = ta.pivothigh(high, swingLen, swingLen)
pivotLow = ta.pivotlow(low, swingLen, swingLen)
var float lastHigh = na
var float lastLow = na
var int highBar = na
var int lowBar = na
var bool highSwept = false
var bool lowSwept = false
var line highLine = na
var line lowLine = na
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BUY SIDE LIQUIDITY
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if not na(pivotHigh)
previousHigh = lastHigh
if showEqual and not na(previousHigh)
if math.abs(pivotHigh - previousHigh) <= atr[swingLen] * tolerance
label.new(bar_index - swingLen, pivotHigh, "EQH",
style=label.style_label_down,
color=color.new(bearColor, 15),
textcolor=color.white, size=size.tiny)
lastHigh := pivotHigh
highBar := bar_index - swingLen
highSwept := false
if not na(highLine)
line.delete(highLine)
if showLiquidity
highLine := line.new(highBar, lastHigh, bar_index, lastHigh,
color=bearColor, style=line.style_dashed, width=1)
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SELL SIDE LIQUIDITY
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if not na(pivotLow)
previousLow = lastLow
if showEqual and not na(previousLow)
if math.abs(pivotLow - previousLow) <= atr[swingLen] * tolerance
label.new(bar_index - swingLen, pivotLow, "EQL",
style=label.style_label_up,
color=color.new(bullColor, 15),
textcolor=color.black, size=size.tiny)
lastLow := pivotLow
lowBar := bar_index - swingLen
lowSwept := false
if not na(lowLine)
line.delete(lowLine)
if showLiquidity
lowLine := line.new(lowBar, lastLow, bar_index, lastLow,
color=bullColor, style=line.style_dashed, width=1)
// Extend latest liquidity levels
if showLiquidity and not na(highLine)
line.set_x2(highLine, bar_index)
if showLiquidity and not na(lowLine)
line.set_x2(lowLine, bar_index)
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY SWEEPS
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bearSweep = barstate.isconfirmed and not na(lastHigh) and not highSwept and high > lastHigh and close < lastHigh
bullSweep = barstate.isconfirmed and not na(lastLow) and not lowSwept and low < lastLow and close > lastLow
if bearSweep
highSwept := true
if bullSweep
lowSwept := true
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BUY / SELL SIGNALS
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
buySignal = showSignals and bullSweep
sellSignal = showSignals and bearSweep
plotshape(buySignal, title="BUY Signal",
style=shape.labelup, location=location.belowbar,
color=bullColor, text="BUY", textcolor=color.black,
size=size.small)
plotshape(sellSignal, title="SELL Signal",
style=shape.labeldown, location=location.abovebar,
color=bearColor, text="SELL", textcolor=color.white,
size=size.small)
// Sweep labels
if showSweeps and bullSweep
label.new(bar_index, low, "SSL SWEEP",
style=label.style_label_up,
color=bullColor, textcolor=color.black, size=size.tiny)
if showSweeps and bearSweep
label.new(bar_index, high, "BSL SWEEP",
style=label.style_label_down,
color=bearColor, textcolor=color.white, size=size.tiny)
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, title="Liquidity Hunter BUY",
message="Bullish SSL Liquidity Sweep on {{ticker}} | Price: {{close}}")
alertcondition(sellSignal, title="Liquidity Hunter SELL",
message="Bearish BSL Liquidity Sweep on {{ticker}} | Price: {{close}}")
alertcondition(bullSweep or bearSweep, title="Any Liquidity Sweep",
message="Liquidity Sweep detected on {{ticker}} | Price: {{close}}")