OPEN-SOURCE SCRIPT

UT Bot Pro Final

//version=6
indicator("UT Bot Pro Final", overlay=true, max_lines_count=500)

// === INPUT PARAMETERS ===
// Core Settings
atr_multiplier = input.float(1.0, "ATR Multiplier", minval=0.5, maxval=5, step=0.1, group="Core Settings")
atr_period = input.int(6, "ATR Period", minval=1, maxval=20, group="Core Settings")

// Trend Filter
use_trend_filter = input.bool(true, "Enable Trend Filter", group="Trend Filter")
trend_length = input.int(50, "Trend SMA Period", minval=10, group="Trend Filter")

// Volume Filter
use_volume_filter = input.bool(true, "Enable Volume Filter", group="Volume Filter")
volume_ma_length = input.int(20, "Volume MA Period", minval=5, group="Volume Filter")
volume_threshold = input.float(1.25, "Volume Threshold %", step=0.1, group="Volume Filter")

// === CORE LOGIC ===
xATR = ta.atr(atr_period)
nLoss = atr_multiplier * xATR
price = close

// Trend Filter
trend_sma = ta.sma(price, trend_length)
valid_uptrend = not use_trend_filter or (price > trend_sma)
valid_downtrend = not use_trend_filter or (price < trend_sma)

// Volume Filter
volume_ma = ta.sma(volume, volume_ma_length)
volume_ok = volume > (volume_ma * volume_threshold)

// Trailing Stop
var float xATRTrailingStop = na
xATRTrailingStop := switch
na(xATRTrailingStop[1]) => price - nLoss
price > xATRTrailingStop[1] and valid_uptrend => math.max(xATRTrailingStop[1], price - nLoss)
price < xATRTrailingStop[1] and valid_downtrend => math.min(xATRTrailingStop[1], price + nLoss)
=> xATRTrailingStop[1]

// Signal Generation
buy_signal = ta.crossover(price, xATRTrailingStop) and valid_uptrend and (use_volume_filter ? volume_ok : true)
sell_signal = ta.crossunder(price, xATRTrailingStop) and valid_downtrend and (use_volume_filter ? volume_ok : true)

// === VISUALS ===
plot(xATRTrailingStop, "Trailing Stop", color=color.new(color.purple, 0), linewidth=2)

plotshape(
buy_signal, "Buy", shape.triangleup,
location.belowbar, color=color.green,
text="BUY", textcolor=color.white, size=size.small)

plotshape(
sell_signal, "Sell", shape.triangledown,
location.abovebar, color=color.red,
text="SELL", textcolor=color.white, size=size.small)

// === ALERTS ===
alertcondition(buy_signal, "Long Entry", "Bullish breakout detected")
alertcondition(sell_signal, "Short Entry", "Bearish breakdown detected")

免責聲明