本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("UT Bot PRO v4 (Correct VWAP Filter)", overlay=true)
// === INPUTS ===
haBodyMultiplier = input.float(1.2, "Strong Candle Multiplier")
pullbackBars = input.int(3, "Pullback Lookback")
// === VWAP (MATCH CHART) ===
vwapValue = ta.vwap(hlc3) // IMPORTANT FIX
// === HEIKIN ASHI ===
haClose = (open + high + low + close) / 4
var float haOpen = na
haOpen := na(haOpen[1]) ? (open + close)/2 : (haOpen[1] + haClose[1]) / 2
haBody = math.abs(haClose - haOpen)
haAvgBody = ta.sma(haBody, 10)
// === STRONG CANDLES ===
isStrongBull = haClose > haOpen and haBody > haAvgBody * haBodyMultiplier
isStrongBear = haClose < haOpen and haBody > haAvgBody * haBodyMultiplier
// === PULLBACK ===
isPullbackBull = haClose < haOpen or haBody < haAvgBody
isPullbackBear = haClose > haOpen or haBody < haAvgBody
pullbackHappenedBull = ta.barssince(isPullbackBull) < pullbackBars
pullbackHappenedBear = ta.barssince(isPullbackBear) < pullbackBars
// === STATE ===
var bool sellReady = true
var bool buyReady = true
if pullbackHappenedBear
sellReady := true
if pullbackHappenedBull
buyReady := true
// === STRICT VWAP CONDITIONS ===
// 🚫 STRICT: candle must CLOSE above VWAP
aboveVWAP = close > vwapValue and low > vwapValue
// 🚫 STRICT: candle must CLOSE below VWAP
belowVWAP = close < vwapValue and high < vwapValue
// === SIGNALS ===
sellSignal = belowVWAP and isStrongBear and sellReady
buySignal = aboveVWAP and isStrongBull and buyReady
if sellSignal
sellReady := false
if buySignal
buyReady := false
// === PLOTS ===
plot(vwapValue, color=color.yellow, linewidth=2)
plotshape(buySignal, title="BUY", location=location.belowbar,
color=color.green, style=shape.labelup, text="B")
plotshape(sellSignal, title="SELL", location=location.abovebar,
color=color.red, style=shape.labeldown, text="S")
// === ALERTS ===
alertcondition(buySignal, title="BUY ALERT", message="BUY Signal")
alertcondition(sellSignal, title="SELL ALERT", message="SELL Signal")