Liquidity Hunter PRO SMC Edition [Thomas]

Thomas-Sterling · study · 296 行 · 点赞 1,461 · 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/
// © Thomas-Sterling
 
 
 //@version=6
indicator("Liquidity Hunter PRO SMC Edition [Thomas]", overlay=true, max_labels_count=200, max_lines_count=100, max_boxes_count=30)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
swingLen     = input.int(5, "Swing Length", minval=2)
confirmBars  = input.int(10, "Max Bars After Sweep", minval=1)
atrLen       = input.int(14, "ATR Length", minval=1)
minBodyATR   = input.float(0.15, "Min Reversal Body (ATR)", minval=0, step=0.05)
 
rr1 = input.float(1.0, "TP1 Risk:Reward", minval=0.5, step=0.5)
rr2 = input.float(2.0, "TP2 Risk:Reward", minval=1.0, step=0.5)
rr3 = input.float(3.0, "TP3 Risk:Reward", minval=1.5, step=0.5)
 
showLevels = input.bool(true, "Show Entry / SL / TP")
showSweeps = input.bool(true, "Show Liquidity Sweeps")
showBOS    = input.bool(true, "Show BOS")
showOB     = input.bool(true, "Show Order Blocks")
showFVG    = input.bool(true, "Show Fair Value Gaps")
showDash   = input.bool(true, "Show Dashboard")
 
obLookback = input.int(15, "Order Block Search Bars", minval=2, maxval=50)
extendBars = input.int(30, "Zone Extension Bars", minval=5, maxval=200)
rightBars  = input.int(15, "Target Label Distance", minval=2, maxval=100)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SWING STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ph = ta.pivothigh(high, swingLen, swingLen)
pl = ta.pivotlow(low, swingLen, swingLen)
 
var float swingHigh = na
var float swingLow  = na
 
if not na(ph)
    swingHigh := ph
if not na(pl)
    swingLow := pl
 
atr  = ta.atr(atrLen)
body = math.abs(close - open)
 
bullCandle = close > open and body >= atr * minBodyATR
bearCandle = close < open and body >= atr * minBodyATR
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY SWEEPS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
sweepLow  = barstate.isconfirmed and not na(swingLow) and low < swingLow and close > swingLow
sweepHigh = barstate.isconfirmed and not na(swingHigh) and high > swingHigh and close < swingHigh
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BREAK OF STRUCTURE (BOS)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullBOS = barstate.isconfirmed and not na(swingHigh) and ta.crossover(close, swingHigh)
bearBOS = barstate.isconfirmed and not na(swingLow) and ta.crossunder(close, swingLow)
 
plotshape(showBOS and bullBOS, title="Bullish BOS", text="BOS ↑", style=shape.labelup, location=location.belowbar, color=color.teal, textcolor=color.white, size=size.tiny)
plotshape(showBOS and bearBOS, title="Bearish BOS", text="BOS ↓", style=shape.labeldown, location=location.abovebar, color=color.maroon, textcolor=color.white, size=size.tiny)
 
plotshape(showSweeps and sweepLow, title="Low Liquidity Sweep", style=shape.circle, location=location.belowbar, color=color.aqua, size=size.tiny)
plotshape(showSweeps and sweepHigh, title="High Liquidity Sweep", style=shape.circle, location=location.abovebar, color=color.orange, size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ORDER BLOCKS
// Latest bullish and bearish OB are displayed
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullOB = na
var box bearOB = na
 
if showOB and bullBOS
    int bullOffset = na
    float bullTop = na
    float bullBottom = na
 
    for i = 1 to obLookback
        if na(bullOffset) and close[i] < open[i]
            bullOffset := i
            bullTop := high[i]
            bullBottom := low[i]
 
    if not na(bullOffset)
        if not na(bullOB)
            box.delete(bullOB)
        bullOB := box.new(left=bar_index - bullOffset, top=bullTop, right=bar_index + extendBars, bottom=bullBottom, xloc=xloc.bar_index, bgcolor=color.new(color.green, 85), border_color=color.lime, text="Bullish OB", text_color=color.lime, text_size=size.tiny)
 
if showOB and bearBOS
    int bearOffset = na
    float bearTop = na
    float bearBottom = na
 
    for i = 1 to obLookback
        if na(bearOffset) and close[i] > open[i]
            bearOffset := i
            bearTop := high[i]
            bearBottom := low[i]
 
    if not na(bearOffset)
        if not na(bearOB)
            box.delete(bearOB)
        bearOB := box.new(left=bar_index - bearOffset, top=bearTop, right=bar_index + extendBars, bottom=bearBottom, xloc=xloc.bar_index, bgcolor=color.new(color.red, 85), border_color=color.red, text="Bearish OB", text_color=color.red, text_size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// FAIR VALUE GAPS (FVG)
// Three-candle imbalance
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var box bullFVG = na
var box bearFVG = na
 
bullGap = barstate.isconfirmed and bar_index >= 2 and low > high[2]
bearGap = barstate.isconfirmed and bar_index >= 2 and high < low[2]
 
if showFVG and bullGap
    if not na(bullFVG)
        box.delete(bullFVG)
    bullFVG := box.new(left=bar_index - 2, top=low, right=bar_index + extendBars, bottom=high[2], xloc=xloc.bar_index, bgcolor=color.new(color.aqua, 86), border_color=color.aqua, text="Bullish FVG", text_color=color.aqua, text_size=size.tiny)
 
if showFVG and bearGap
    if not na(bearFVG)
        box.delete(bearFVG)
    bearFVG := box.new(left=bar_index - 2, top=low[2], right=bar_index + extendBars, bottom=high, xloc=xloc.bar_index, bgcolor=color.new(color.orange, 86), border_color=color.orange, text="Bearish FVG", text_color=color.orange, text_size=size.tiny)
 
// Keep latest zones extended to the right
if barstate.islast
    if not na(bullOB)
        box.set_right(bullOB, bar_index + extendBars)
    if not na(bearOB)
        box.set_right(bearOB, bar_index + extendBars)
    if not na(bullFVG)
        box.set_right(bullFVG, bar_index + extendBars)
    if not na(bearFVG)
        box.set_right(bearFVG, bar_index + extendBars)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SWEEP + MSS CONFIRMATION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var bool waitBull = false
var bool waitBear = false
var float bullSL = na
var float bearSL = na
var float bullMSS = na
var float bearMSS = na
var int bullBar = na
var int bearBar = na
 
if sweepLow and not na(swingHigh)
    waitBull := true
    waitBear := false
    bullSL := low
    bullMSS := swingHigh
    bullBar := bar_index
 
if sweepHigh and not na(swingLow)
    waitBear := true
    waitBull := false
    bearSL := high
    bearMSS := swingLow
    bearBar := bar_index
 
if waitBull and not na(bullBar) and bar_index - bullBar > confirmBars
    waitBull := false
 
if waitBear and not na(bearBar) and bar_index - bearBar > confirmBars
    waitBear := false
 
buySignal = barstate.isconfirmed and waitBull and not na(bullMSS) and close > bullMSS and bullCandle and close > bullSL
sellSignal = barstate.isconfirmed and waitBear and not na(bearMSS) and close < bearMSS and bearCandle and close < bearSL
 
validBuy = buySignal and close - bullSL > syminfo.mintick
validSell = sellSignal and bearSL - close > syminfo.mintick
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ENTRY / STOP LOSS / THREE TARGETS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float entry = na
var float sl = na
var float tp1 = na
var float tp2 = na
var float tp3 = na
var string lastSignal = "WAITING"
 
if validBuy
    entry := close
    sl := bullSL
    float riskBuy = entry - sl
    tp1 := entry + riskBuy * rr1
    tp2 := entry + riskBuy * rr2
    tp3 := entry + riskBuy * rr3
    lastSignal := "BUY"
    waitBull := false
 
if validSell
    entry := close
    sl := bearSL
    float riskSell = sl - entry
    tp1 := entry - riskSell * rr1
    tp2 := entry - riskSell * rr2
    tp3 := entry - riskSell * rr3
    lastSignal := "SELL"
    waitBear := false
 
plotshape(validBuy, title="BUY Signal", text="BUY", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.small)
plotshape(validSell, title="SELL Signal", text="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CLEAN HORIZONTAL LEVELS + RIGHT LABELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var line entryLine = na
var line slLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
 
var label entryLabel = na
var label slLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
 
if validBuy or validSell
    line.delete(entryLine)
    line.delete(slLine)
    line.delete(tp1Line)
    line.delete(tp2Line)
    line.delete(tp3Line)
 
    label.delete(entryLabel)
    label.delete(slLabel)
    label.delete(tp1Label)
    label.delete(tp2Label)
    label.delete(tp3Label)
 
    if showLevels
        entryLine := line.new(bar_index, entry, bar_index + rightBars, entry, color=color.blue, width=2)
        slLine := line.new(bar_index, sl, bar_index + rightBars, sl, color=color.red, width=2)
        tp1Line := line.new(bar_index, tp1, bar_index + rightBars, tp1, color=color.lime, width=2)
        tp2Line := line.new(bar_index, tp2, bar_index + rightBars, tp2, color=color.green, width=2)
        tp3Line := line.new(bar_index, tp3, bar_index + rightBars, tp3, color=color.teal, width=2)
 
        entryLabel := label.new(bar_index + rightBars, entry, "ENTRY " + str.tostring(entry, format.mintick), style=label.style_label_left, color=color.blue, textcolor=color.white, size=size.small)
        slLabel := label.new(bar_index + rightBars, sl, "SL " + str.tostring(sl, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white, size=size.small)
        tp1Label := label.new(bar_index + rightBars, tp1, "TP1 " + str.tostring(tp1, format.mintick), style=label.style_label_left, color=color.lime, textcolor=color.black, size=size.small)
        tp2Label := label.new(bar_index + rightBars, tp2, "TP2 " + str.tostring(tp2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white, size=size.small)
        tp3Label := label.new(bar_index + rightBars, tp3, "TP3 " + str.tostring(tp3, format.mintick), style=label.style_label_left, color=color.teal, textcolor=color.white, size=size.small)
 
if barstate.islast and showLevels and not na(entryLine)
    line.set_x2(entryLine, bar_index + rightBars)
    line.set_x2(slLine, bar_index + rightBars)
    line.set_x2(tp1Line, bar_index + rightBars)
    line.set_x2(tp2Line, bar_index + rightBars)
    line.set_x2(tp3Line, bar_index + rightBars)
 
    label.set_x(entryLabel, bar_index + rightBars)
    label.set_x(slLabel, bar_index + rightBars)
    label.set_x(tp1Label, bar_index + rightBars)
    label.set_x(tp2Label, bar_index + rightBars)
    label.set_x(tp3Label, bar_index + rightBars)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table dash = table.new(position.top_right, 2, 5, border_width=1)
 
if barstate.islast and showDash
    table.cell(dash, 0, 0, "LIQUIDITY HUNTER", bgcolor=color.rgb(25, 35, 55), text_color=color.white)
    table.cell(dash, 1, 0, "SMC PRO", bgcolor=color.rgb(25, 35, 55), text_color=color.aqua)
 
    table.cell(dash, 0, 1, "Last Signal", text_color=chart.fg_color)
    table.cell(dash, 1, 1, lastSignal, text_color=lastSignal == "BUY" ? color.lime : lastSignal == "SELL" ? color.red : chart.fg_color)
 
    table.cell(dash, 0, 2, "Timeframe", text_color=chart.fg_color)
    table.cell(dash, 1, 2, timeframe.period, text_color=chart.fg_color)
 
    table.cell(dash, 0, 3, "Structure", text_color=chart.fg_color)
    table.cell(dash, 1, 3, bullBOS ? "BULLISH BOS" : bearBOS ? "BEARISH BOS" : "WAITING", text_color=bullBOS ? color.lime : bearBOS ? color.red : chart.fg_color)
 
    table.cell(dash, 0, 4, "SMC Tools", text_color=chart.fg_color)
    table.cell(dash, 1, 4, "OB + FVG + BOS", text_color=color.aqua)
 
if barstate.islast and not showDash
    table.clear(dash, 0, 0, 1, 4)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(validBuy, title="BUY - Liquidity Hunter PRO", message="BUY | {{ticker}} | {{interval}} | Close: {{close}} | Sweep + MSS")
alertcondition(validSell, title="SELL - Liquidity Hunter PRO", message="SELL | {{ticker}} | {{interval}} | Close: {{close}} | Sweep + MSS")
alertcondition(bullBOS, title="Bullish BOS", message="Bullish BOS | {{ticker}} | {{interval}} | Close: {{close}}")
alertcondition(bearBOS, title="Bearish BOS", message="Bearish BOS | {{ticker}} | {{interval}} | Close: {{close}}")
alertcondition(bullGap, title="Bullish FVG", message="Bullish FVG formed | {{ticker}} | {{interval}}")
alertcondition(bearGap, title="Bearish FVG", message="Bearish FVG formed | {{ticker}} | {{interval}}")

← 返回列表