Liquidity Sniper Pro

VenusJ · study · 174 行 · 点赞 5,838 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("Liquidity Sniper Pro", overlay=true, max_boxes_count=20, max_labels_count=50)
 
// ===== INPUTS =====
emaFastLen = input.int(50, "Fast EMA")
emaSlowLen = input.int(200, "Slow EMA")
atrLen = input.int(14, "ATR Length")
atrMult = input.float(1.5, "ATR Multiplier")
 
useHTF = input.bool(true, "Use Higher Timeframe Trend")
htfTF = input.timeframe("15", "HTF Timeframe")
 
useVolumeFilter = input.bool(true, "Use Volume Filter")
volMultiplier = input.float(1.2, "Volume Strength Multiplier")
 
// ===== CORE =====
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
atrVal = ta.atr(atrLen)
 
// ===== HTF TREND =====
htfEmaFast = request.security(syminfo.tickerid, htfTF, ta.ema(close, emaFastLen))
htfEmaSlow = request.security(syminfo.tickerid, htfTF, ta.ema(close, emaSlowLen))
 
htfBull = htfEmaFast > htfEmaSlow
htfBear = htfEmaFast < htfEmaSlow
 
// ===== VOLUME =====
volMA = ta.sma(volume, 20)
strongVol = volume > volMA * volMultiplier
 
// ===== TREND =====
bullTrend = emaFast > emaSlow
bearTrend = emaFast < emaSlow
 
trendStrength = math.abs(emaFast - emaSlow)
 
// ===== SIGNALS =====
buySignal = bullTrend and ta.crossover(close, emaFast)
sellSignal = bearTrend and ta.crossunder(close, emaFast)
 
// APPLY FILTERS
buySignal := buySignal and (not useHTF or htfBull) and (not useVolumeFilter or strongVol)
sellSignal := sellSignal and (not useHTF or htfBear) and (not useVolumeFilter or strongVol)
 
// ===== SIGNAL QUALITY =====
quality = "C"
 
if strongVol and trendStrength > atrVal
    quality := "A"
else if strongVol
    quality := "B"
 
// ===== TRADE STATE =====
var bool tradeActive = false
var bool isBuy = false
var float entry = na
var float stop = na
var float tp1 = na
var float tp2 = na
var float tp3 = na
 
// ===== OBJECTS =====
var label entryLbl = na
var label slLbl = na
var label tp1Lbl = na
var label tp2Lbl = na
var label tp3Lbl = na
 
var box profitBox = na
var box lossBox = na
 
// ===== CLEAR FUNCTION =====
clearAll() =>
    label.delete(entryLbl)
    label.delete(slLbl)
    label.delete(tp1Lbl)
    label.delete(tp2Lbl)
    label.delete(tp3Lbl)
    box.delete(profitBox)
    box.delete(lossBox)
 
// ===== NEW TRADE =====
if not tradeActive and (buySignal or sellSignal)
 
    clearAll()
 
    tradeActive := true
    isBuy := buySignal
    entry := close
 
    if buySignal
        stop := entry - atrVal * atrMult
        risk = entry - stop
        tp1 := entry + risk
        tp2 := entry + risk * 2
        tp3 := entry + risk * 3
    else
        stop := entry + atrVal * atrMult
        risk = stop - entry
        tp1 := entry - risk
        tp2 := entry - risk * 2
        tp3 := entry - risk * 3
 
    // ===== KEEP YOUR ORIGINAL BOXES =====
    profitBox := box.new(bar_index, isBuy ? entry : tp3, bar_index + 30, isBuy ? tp3 : entry,
        bgcolor=color.new(#055509, 59), border_color=color.rgb(4, 199, 20, 70))
 
    lossBox := box.new(bar_index, isBuy ? stop : entry, bar_index + 30, isBuy ? entry : stop,
        bgcolor=color.new(color.red, 85), border_color=color.red)
 
    // ===== LABELS =====
    entryLbl := label.new(bar_index + 30, entry,
        "ENTRY (" + quality + ")\n" + str.tostring(entry, format.mintick),
        style=label.style_label_left, color=color.gray, textcolor=color.white)
 
    slLbl := label.new(bar_index + 30, stop,
        "SL\n" + str.tostring(stop, format.mintick),
        style=label.style_label_left, color=color.red, textcolor=color.white)
 
    tp1Lbl := label.new(bar_index + 30, tp1,
        "TP1", style=label.style_label_left, color=color.green, textcolor=color.white)
 
    tp2Lbl := label.new(bar_index + 30, tp2,
        "TP2", style=label.style_label_left, color=color.green, textcolor=color.white)
 
    tp3Lbl := label.new(bar_index + 30, tp3,
        "TP3", style=label.style_label_left, color=color.green, textcolor=color.white)
 
// ===== TRADE MANAGEMENT =====
if tradeActive
    tp1Hit = isBuy ? high >= tp1 : low <= tp1
    tp2Hit = isBuy ? high >= tp2 : low <= tp2
    tp3Hit = isBuy ? high >= tp3 : low <= tp3
    slHit = isBuy ? low <= stop : high >= stop
 
    if tp1Hit
        label.set_color(tp1Lbl, color.lime)
 
    if tp2Hit
        label.set_color(tp2Lbl, color.lime)
 
    if tp3Hit
        label.set_color(tp3Lbl, color.lime)
        tradeActive := false
 
    if slHit
        clearAll()
        tradeActive := false
 
// ===== DASHBOARD (SIDE PANEL) =====
var table dash = table.new(position.top_right, 2, 4)
 
trendText = bullTrend ? "BULLISH" : "BEARISH"
trendColor = bullTrend ? color.green : color.red
 
volText = strongVol ? "HIGH" : "LOW"
volColor = strongVol ? color.green : color.orange
 
table.cell(dash, 0, 0, "TREND", text_color=color.white)
table.cell(dash, 1, 0, trendText, text_color=trendColor)
 
table.cell(dash, 0, 1, "VOLUME", text_color=color.white)
table.cell(dash, 1, 1, volText, text_color=volColor)
 
table.cell(dash, 0, 2, "HTF", text_color=color.white)
table.cell(dash, 1, 2, htfBull ? "BULL" : "BEAR", text_color=trendColor)
 
table.cell(dash, 0, 3, "QUALITY", text_color=color.white)
table.cell(dash, 1, 3, quality, text_color=color.yellow)
 
// ===== EMAs =====
plot(emaFast, color=color.rgb(20, 83, 12))
plot(emaSlow, color=color.rgb(128, 8, 8))

← 返回列表