Trend Pullback Sniper PRO [Thomas]

Thomas-Sterling · study · 204 行 · 点赞 753 · 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("Trend Pullback Sniper PRO [Thomas]", overlay=true, max_lines_count=20, max_labels_count=30)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 1. INPUT SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
groupTrend = "Trend Settings"
fastLen = input.int(21, "Fast EMA", minval=1, group=groupTrend)
midLen = input.int(50, "Middle EMA", minval=1, group=groupTrend)
trendLen = input.int(200, "Trend EMA", minval=1, group=groupTrend)
useTrendFilter = input.bool(true, "Use EMA Trend Filter", group=groupTrend)
 
groupConfirm = "Signal Confirmation"
rsiLen = input.int(14, "RSI Length", minval=1, group=groupConfirm)
bullRsiLevel = input.float(50, "Bullish RSI Minimum", group=groupConfirm)
bearRsiLevel = input.float(50, "Bearish RSI Maximum", group=groupConfirm)
cooldown = input.int(8, "Signal Cooldown Bars", minval=0, group=groupConfirm)
 
groupRisk = "Risk & Targets"
atrLen = input.int(14, "ATR Length", minval=1, group=groupRisk)
slBuffer = input.float(0.5, "SL ATR Buffer", minval=0.0, step=0.1, group=groupRisk)
tp1RR = input.float(1.0, "TP1 Risk/Reward", minval=0.1, step=0.1, group=groupRisk)
tp2RR = input.float(2.0, "TP2 Risk/Reward", minval=0.1, step=0.1, group=groupRisk)
tp3RR = input.float(3.0, "TP3 Risk/Reward", minval=0.1, step=0.1, group=groupRisk)
 
groupVisual = "Visual Settings"
showEMAs = input.bool(true, "Show EMAs", group=groupVisual)
showDashboard = input.bool(true, "Show Dashboard", group=groupVisual)
showLevels = input.bool(true, "Show Entry / SL / Targets", group=groupVisual)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 2. INDICATOR CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
emaFast = ta.ema(close, fastLen)
emaMid = ta.ema(close, midLen)
emaTrend = ta.ema(close, trendLen)
 
rsiValue = ta.rsi(close, rsiLen)
atrValue = ta.atr(atrLen)
 
bullTrend = close > emaTrend and emaFast > emaMid
bearTrend = close < emaTrend and emaFast < emaMid
 
bullTrendAllowed = not useTrendFilter or bullTrend
bearTrendAllowed = not useTrendFilter or bearTrend
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 3. PULLBACK CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bullPullback = low <= emaFast and close > emaFast and close > open
bearPullback = high >= emaFast and close < emaFast and close < open
 
bullConfirmation = rsiValue > bullRsiLevel
bearConfirmation = rsiValue < bearRsiLevel
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 4. SIGNAL COOLDOWN
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var int lastSignalBar = na
 
cooldownOK = na(lastSignalBar) or bar_index - lastSignalBar > cooldown
 
buySignal = bullTrendAllowed and bullPullback and bullConfirmation and cooldownOK and barstate.isconfirmed
sellSignal = bearTrendAllowed and bearPullback and bearConfirmation and cooldownOK and barstate.isconfirmed
 
if buySignal or sellSignal
    lastSignalBar := bar_index
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 5. TRADE LEVEL VARIABLES
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var float entryPrice = na
var float stopPrice = na
var float target1 = na
var float target2 = na
var float target3 = na
 
var string tradeDirection = "WAITING"
 
var line entryLine = na
var line stopLine = na
var line tp1Line = na
var line tp2Line = na
var line tp3Line = na
 
var label entryLabel = na
var label stopLabel = na
var label tp1Label = na
var label tp2Label = na
var label tp3Label = na
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 6. NEW BUY / SELL SETUP
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if buySignal or sellSignal
 
    // Remove previous trade drawings
    if not na(entryLine)
        line.delete(entryLine)
    if not na(stopLine)
        line.delete(stopLine)
    if not na(tp1Line)
        line.delete(tp1Line)
    if not na(tp2Line)
        line.delete(tp2Line)
    if not na(tp3Line)
        line.delete(tp3Line)
 
    if not na(entryLabel)
        label.delete(entryLabel)
    if not na(stopLabel)
        label.delete(stopLabel)
    if not na(tp1Label)
        label.delete(tp1Label)
    if not na(tp2Label)
        label.delete(tp2Label)
    if not na(tp3Label)
        label.delete(tp3Label)
 
    entryPrice := close
 
    if buySignal
        stopPrice := low - atrValue * slBuffer
        riskDistance = entryPrice - stopPrice
        target1 := entryPrice + riskDistance * tp1RR
        target2 := entryPrice + riskDistance * tp2RR
        target3 := entryPrice + riskDistance * tp3RR
        tradeDirection := "BUY"
 
    else
        stopPrice := high + atrValue * slBuffer
        riskDistance = stopPrice - entryPrice
        target1 := entryPrice - riskDistance * tp1RR
        target2 := entryPrice - riskDistance * tp2RR
        target3 := entryPrice - riskDistance * tp3RR
        tradeDirection := "SELL"
 
    // Draw latest trade levels
    if showLevels
        entryLine := line.new(bar_index, entryPrice, bar_index + 15, entryPrice, color=color.yellow, width=2)
        stopLine := line.new(bar_index, stopPrice, bar_index + 15, stopPrice, color=color.red, width=2)
        tp1Line := line.new(bar_index, target1, bar_index + 15, target1, color=color.lime, width=1)
        tp2Line := line.new(bar_index, target2, bar_index + 15, target2, color=color.lime, width=1)
        tp3Line := line.new(bar_index, target3, bar_index + 15, target3, color=color.lime, width=2)
 
        entryLabel := label.new(bar_index + 15, entryPrice, "ENTRY " + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=color.yellow, textcolor=color.black)
        stopLabel := label.new(bar_index + 15, stopPrice, "SL " + str.tostring(stopPrice, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white)
        tp1Label := label.new(bar_index + 15, target1, "TP1 " + str.tostring(target1, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
        tp2Label := label.new(bar_index + 15, target2, "TP2 " + str.tostring(target2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
        tp3Label := label.new(bar_index + 15, target3, "TP3 " + str.tostring(target3, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 7. EMA DISPLAY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(showEMAs ? emaFast : na, "Fast EMA", color=color.aqua, linewidth=1)
plot(showEMAs ? emaMid : na, "Middle EMA", color=color.orange, linewidth=1)
plot(showEMAs ? emaTrend : na, "Trend EMA", color=color.blue, linewidth=2)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 8. BUY / SELL SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(buySignal, title="BUY Signal", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.black, size=size.small)
plotshape(sellSignal, title="SELL Signal", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 9. DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table dashboard = table.new(position.top_right, 2, 5, border_width=1)
 
if barstate.islast and showDashboard
    trendText = bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "NEUTRAL"
    trendColor = bullTrend ? color.green : bearTrend ? color.red : color.gray
 
    emaText = close > emaTrend ? "ABOVE EMA 200" : "BELOW EMA 200"
    rsiText = str.tostring(rsiValue, "#.0")
    directionColor = tradeDirection == "BUY" ? color.green : tradeDirection == "SELL" ? color.red : color.gray
 
    table.cell(dashboard, 0, 0, "THOMAS SNIPER", bgcolor=color.rgb(25, 35, 55), text_color=color.white)
    table.cell(dashboard, 1, 0, "PRO", bgcolor=color.rgb(25, 35, 55), text_color=color.aqua)
 
    table.cell(dashboard, 0, 1, "TREND", bgcolor=color.new(color.gray, 75), text_color=color.white)
    table.cell(dashboard, 1, 1, trendText, bgcolor=trendColor, text_color=color.white)
 
    table.cell(dashboard, 0, 2, "EMA STATUS", bgcolor=color.new(color.gray, 75), text_color=color.white)
    table.cell(dashboard, 1, 2, emaText, bgcolor=color.new(color.blue, 65), text_color=color.white)
 
    table.cell(dashboard, 0, 3, "RSI", bgcolor=color.new(color.gray, 75), text_color=color.white)
    table.cell(dashboard, 1, 3, rsiText, bgcolor=color.new(color.gray, 55), text_color=color.white)
 
    table.cell(dashboard, 0, 4, "LAST SETUP", bgcolor=color.new(color.gray, 75), text_color=color.white)
    table.cell(dashboard, 1, 4, tradeDirection, bgcolor=directionColor, text_color=color.white)
 
if barstate.islast and not showDashboard
    table.clear(dashboard, 0, 0, 1, 4)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10. ALERT CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, title="Thomas Sniper BUY", message="Thomas Trend Pullback Sniper PRO: BUY setup confirmed.")
alertcondition(sellSignal, title="Thomas Sniper SELL", message="Thomas Trend Pullback Sniper PRO: SELL setup confirmed.")

← 返回列表