UT Bot Alerts (T-30 Confirm)

KannonXBT · study · 86 行 · 点赞 726 · TradingView 原页

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

Pine Script

//@version=6
indicator("UT Bot Alerts (T-30 Confirm)", overlay=true)
 
// Inputs
a = input.int(1, title="Key Value. Sensitivity")
c = input.int(10, title="ATR Period")
h = input.bool(false, title="Signals from Heikin Ashi Candles")
 
xATR  = ta.atr(c)
nLoss = a * xATR
 
src = h ? request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) : close
 
var float xATRTrailingStop = na
 
xATRTrailingStop := src > nz(xATRTrailingStop[1]) and src[1] > nz(xATRTrailingStop[1]) ?
     math.max(nz(xATRTrailingStop[1]), src - nLoss) :
     src < nz(xATRTrailingStop[1]) and src[1] < nz(xATRTrailingStop[1]) ?
     math.min(nz(xATRTrailingStop[1]), src + nLoss) :
     src > nz(xATRTrailingStop[1]) ? src - nLoss : src + nLoss
 
var int pos = 0
pos := src[1] < nz(xATRTrailingStop[1]) and src > nz(xATRTrailingStop[1]) ? 1 :
       src[1] > nz(xATRTrailingStop[1]) and src < nz(xATRTrailingStop[1]) ? -1 :
       nz(pos[1])
 
emaVal = ta.ema(src, 1)
above  = ta.crossover(emaVal, xATRTrailingStop)
below  = ta.crossover(xATRTrailingStop, emaVal)
 
buy  = src > xATRTrailingStop and above
sell = src < xATRTrailingStop and below
 
barbuy  = src > xATRTrailingStop
barsell = src < xATRTrailingStop
 
plotshape(buy,  title="Buy",  text="Buy",  style=shape.labelup,   location=location.belowbar, color=color.green, textcolor=color.white, size=size.tiny)
plotshape(sell, title="Sell", text="Sell", style=shape.labeldown, location=location.abovebar, color=color.red,   textcolor=color.white, size=size.tiny)
 
barcolor(barbuy  ? color.green : na)
barcolor(barsell ? color.red   : na)
 
 
// ===== T-30 seconds confirmation (signal must still be valid) =====
ms_to_close = time_close - timenow
tminus30 = ms_to_close <= 30000 and ms_to_close > 0
newbar = ta.change(time) != 0
 
// Track whether a Buy/Sell label has appeared at any point during this candle
var bool buy_seen_this_bar  = false
var bool sell_seen_this_bar = false
 
// Ensure we only fire once per candle
var bool sentLong  = false
var bool sentShort = false
 
if newbar
    buy_seen_this_bar  := false
    sell_seen_this_bar := false
    sentLong  := false
    sentShort := false
 
// Record crossover event whenever it happens during the candle
if buy
    buy_seen_this_bar := true
if sell
    sell_seen_this_bar := true
 
// Confirm at T-30 that the signal is still "there" (i.e. state still matches)
buy_t30  = barstate.isrealtime and tminus30 and buy_seen_this_bar  and barbuy  and not sentLong
sell_t30 = barstate.isrealtime and tminus30 and sell_seen_this_bar and barsell and not sentShort
 
if buy_t30
    sentLong := true
 
if sell_t30
    sentShort := true
 
 
// Alerts (optional originals)
alertcondition(buy,  "UT Long",  "UT Long")
alertcondition(sell, "UT Short", "UT Short")
 
// Alerts you actually use
alertcondition(buy_t30,  "UT Long T-30",  "UT Long T-30")
alertcondition(sell_t30, "UT Short T-30", "UT Short T-30")

← 返回列表