本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=5
indicator("UT Bot + Cooldown + Visual FVG", overlay=true)
// === Inputs ===
atrPeriod = input.int(10, title="ATR Period")
factor = input.float(1.0, title="ATR Multiplier")
fvgGap = input.float(0.01, title="Min FVG Gap %")
cooldownBars = input.int(30, title="Min Bars Between Signals")
// === UT Bot Core Logic ===
atr = ta.atr(atrPeriod)
upperBand = close - factor * atr
lowerBand = close + factor * atr
var int dir = na
dir := na(dir[1]) ? 0 : dir[1]
dir := close > lowerBand[1] ? 1 : close < upperBand[1] ? -1 : dir
utBuy = dir == 1 and dir[1] == -1
utSell = dir == -1 and dir[1] == 1
// === Cooldown Logic ===
var int lastBuyBar = na
var int lastSellBar = na
buySignal = utBuy and (na(lastBuyBar) or bar_index - lastBuyBar > cooldownBars)
sellSignal = utSell and (na(lastSellBar) or bar_index - lastSellBar > cooldownBars)
if buySignal
lastBuyBar := bar_index
if sellSignal
lastSellBar := bar_index
// === Plot Buy/Sell Signals
plotshape(buySignal, title="BUY", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(sellSignal, title="SELL", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// === Optional: Visual FVG Markers
fvgUp = low[1] > high[2] and ((low[1] - high[2]) / close) > fvgGap
fvgDown = high[1] < low[2] and ((high[1] - low[2]) / close) > fvgGap
plotshape(fvgUp, title="FVG Up", location=location.belowbar, color=color.blue, style=shape.circle, size=size.tiny)
plotshape(fvgDown, title="FVG Down", location=location.abovebar, color=color.blue, style=shape.circle, size=size.tiny)