本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hardy2004
//@version=5
indicator("UT Bot Alerts + 200 EMA Filter", overlay=true)
// --- Inputs ---
// UT Bot Settings
key_value = input.float(2.0, title="UT Key Value (Sensitivity)")
atr_period = input.int(10, title="UT ATR Period")
// Filter Settings
use_ema_filter = input.bool(true, title="Filter with 200 EMA?")
ema_period = input.int(200, title="EMA Period")
// --- UT Bot Logic ---
xATR = ta.atr(atr_period)
nLoss = key_value * xATR
var float xATRTrailingStop = na
src = close
xATRTrailingStop := if src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0)
math.max(nz(xATRTrailingStop[1], 0), src - nLoss)
else if src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0)
math.min(nz(xATRTrailingStop[1], 0), src + nLoss)
else if src > nz(xATRTrailingStop[1], 0)
src - nLoss
else
src + nLoss
var int position = 0
if src > nz(xATRTrailingStop[1], 0) and src[1] <= nz(xATRTrailingStop[1], 0)
position := 1
else if src < nz(xATRTrailingStop[1], 0) and src[1] >= nz(xATRTrailingStop[1], 0)
position := -1
ut_buy = ta.crossunder(xATRTrailingStop, src)
ut_sell = ta.crossover(xATRTrailingStop, src)
// --- EMA Filter Logic ---
ema_filter = ta.ema(close, ema_period)
plot(ema_filter, color=color.blue, linewidth=2, title="200 EMA Filter")
// Apply conditions
filtered_buy = use_ema_filter ? (ut_buy and close > ema_filter) : ut_buy
filtered_sell = use_ema_filter ? (ut_sell and close < ema_filter) : ut_sell
// --- Plots & Shapes ---
plotshape(filtered_buy, title="Buy Signal", style=shape.labelup, location=location.belowbar, color=color.green, text="BUY", textcolor=color.white, size=size.small)
plotshape(filtered_sell, title="Sell Signal", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
// --- Alerts ---
alertcondition(filtered_buy, title="UT Bot Filtered Buy", message="UT Bot BUY Signal (Trend Aligned)")
alertcondition(filtered_sell, title="UT Bot Filtered Sell", message="UT Bot SELL Signal (Trend Aligned)")