UT Bot One Alert (Buy + Sell + Exit)

anilnandure · strategy · 47 行 · 点赞 242 · TradingView 原页

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

Pine Script

//@version=6
strategy("UT Bot One Alert (Buy + Sell + Exit)", overlay=true, pyramiding=0)
 
// ===== INPUTS =====
atrPeriod = input.int(10, "ATR Period")
keyValue  = input.float(1.0, "Sensitivity")
 
// ===== ATR =====
atr = ta.atr(atrPeriod)
src = close
 
// ===== UT BOT LOGIC =====
longStop  = src - keyValue * atr
shortStop = src + keyValue * atr
 
longStopPrev  = nz(longStop[1], longStop)
shortStopPrev = nz(shortStop[1], shortStop)
 
longStop  := src > longStopPrev  ? math.max(longStop, longStopPrev)   : longStop
shortStop := src < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
 
trend = 0
trend := src > shortStopPrev ? 1 : src < longStopPrev ? -1 : nz(trend[1], 0)
 
// ===== SIGNALS =====
buySignal  = trend == 1 and trend[1] == -1
sellSignal = trend == -1 and trend[1] == 1
 
// ===== ORDERS =====
if buySignal
    strategy.close("SELL")
    strategy.entry("BUY", strategy.long)
 
if sellSignal
    strategy.close("BUY")
    strategy.entry("SELL", strategy.short)
 
// ===== PLOTS =====
plotshape(buySignal, style=shape.labelup, text="BUY", color=color.green)
plotshape(sellSignal, style=shape.labeldown, text="SELL", color=color.red)
 
// ===== ONE SINGLE ALERT =====
alertcondition(
     buySignal or sellSignal,
     title="One Alert Buy Sell Exit",
     message="{{strategy.order.action}}"
)

← 返回列表