本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("UT Bot Decimal + HA Signals + HA VWAP (Bold White Labels)", overlay=true)
//──────────────────────────────────────────────────────────────────────────────
// Inputs
sens = input.float(1.0, "Sensitivity (Decimal)", step=0.01, minval=0.01)
atrLen = input.int(10, "ATR Length", minval=1)
showVWAP = input.bool(true, "Show HA VWAP")
showStops = input.bool(true, "Show UT Trailing Stop")
showSignals = input.bool(true, "Show Buy / Sell Labels")
//──────────────────────────────────────────────────────────────────────────────
// Heikin Ashi data
haTicker = ticker.heikinashi(syminfo.tickerid)
haOpen = request.security(haTicker, timeframe.period, open)
haHigh = request.security(haTicker, timeframe.period, high)
haLow = request.security(haTicker, timeframe.period, low)
haClose = request.security(haTicker, timeframe.period, close)
haHlc3 = (haHigh + haLow + haClose) / 3.0
//──────────────────────────────────────────────────────────────────────────────
// UT Bot logic (Heikin Ashi ONLY)
atr = ta.atr(atrLen)
nLoss = sens * atr
src = haClose
var float trailStop = na
if na(trailStop[1])
trailStop := src - nLoss
else
if src > trailStop[1] and src[1] > trailStop[1]
trailStop := math.max(trailStop[1], src - nLoss)
else if src < trailStop[1] and src[1] < trailStop[1]
trailStop := math.min(trailStop[1], src + nLoss)
else
trailStop := src > trailStop[1] ? (src - nLoss) : (src + nLoss)
// Direction
var int dir = 1
dir := src > trailStop ? 1 : src < trailStop ? -1 : dir[1]
// Signals (HA only)
buySignal = ta.crossover(src, trailStop) and dir == 1
sellSignal = ta.crossunder(src, trailStop) and dir == -1
//──────────────────────────────────────────────────────────────────────────────
// VWAP (Heikin Ashi)
vwapHA = ta.vwap(haHlc3)
//──────────────────────────────────────────────────────────────────────────────
// Plots
plot(showStops ? trailStop : na, title="UT Trailing Stop", linewidth=2)
plot(showVWAP ? vwapHA : na, title="VWAP (HA)", linewidth=2)
// BUY label — BOLD WHITE
plotshape(showSignals and buySignal, title="BUY", style=shape.labelup, location=location.belowbar, text="𝗕𝗨𝗬", size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)
// SELL label — BOLD WHITE
plotshape(showSignals and sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, text="𝗦𝗘𝗟𝗟", size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)
//──────────────────────────────────────────────────────────────────────────────
// Alerts
alertcondition(buySignal, title="UT HA BUY", message="UT HA BUY | {{ticker}} {{interval}}")
alertcondition(sellSignal, title="UT HA SELL", message="UT HA SELL | {{ticker}} {{interval}}")