UT Bot + EMA + RSI Indicator

anikethpm · study · 69 行 · 点赞 49 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("UT Bot + EMA + RSI Indicator", overlay=true, max_labels_count=500, max_lines_count=500)
 
// --- INPUTS ---
var float kv    = input.float(1.0, "UT Key Value")
var int   atrp  = input.int(10, "UT ATR Period")
var int   f_ema = input.int(9, "Fast EMA")
var int   s_ema = input.int(20, "Slow EMA")
var float rr    = input.float(2.0, "Risk:Reward Ratio")
var int   line_len = input.int(15, "Target Line Length (Bars)")
 
// Aggressive Filters
var int   rsi_buy = input.int(55, "RSI Buy Threshold")
var int   rsi_sell = input.int(45, "RSI Sell Threshold")
var int   fresh_window = input.int(15, "EMA Cross Window")
 
// --- CALCULATIONS ---
// UT Bot
float xATR = ta.atr(atrp)
float nLoss = kv * xATR
var float xTS = 0.0
xTS := close > nz(xTS[1]) and close[1] > nz(xTS[1]) ? math.max(nz(xTS[1]), close - nLoss) : 
       close < nz(xTS[1]) and close[1] < nz(xTS[1]) ? math.min(nz(xTS[1]), close + nLoss) : 
       close > nz(xTS[1]) ? close - nLoss : close + nLoss
 
// Indicators
float ema9  = ta.ema(close, f_ema)
float ema20 = ta.ema(close, s_ema)
float rsi   = ta.rsi(close, 14)
 
// Freshness
bool recent_bull = ta.barssince(ta.crossover(ema9, ema20)) <= fresh_window
bool recent_bear = ta.barssince(ta.crossunder(ema9, ema20)) <= fresh_window
 
// TRIGGERS (Require exact crossover moment of UT Bot alongside other conditions)
bool buy_trigger  = ta.crossover(close, xTS) and (ema9 > ema20) and recent_bull and (rsi > rsi_buy)
bool sell_trigger = ta.crossunder(close, xTS) and (ema9 < ema20) and recent_bear and (rsi < rsi_sell)
 
// --- VISUALS ---
p1 = plot(ema9, "9 EMA", color.orange, 1)
p2 = plot(ema20, "20 EMA", color.blue, 2)
fill(p1, p2, ema9 > ema20 ? color.new(color.green, 90) : color.new(color.red, 90))
plot(xTS, "UT Trailing Stop", color=color.new(#d500f9, 30), style=plot.style_linebr, linewidth=2)
 
// Draw Risk/Reward Lines Function
draw_rr(entry, sl, tp) =>
    int end_bar = bar_index + line_len
    line.new(bar_index, entry, end_bar, entry, color=color.new(color.yellow, 50), width=1, style=line.style_dashed)
    line.new(bar_index, sl, end_bar, sl, color=color.new(color.red, 30), width=2)
    line.new(bar_index, tp, end_bar, tp, color=color.new(color.green, 30), width=2)
 
// --- SIGNAL EXECUTION ---
if buy_trigger
    label.new(bar_index, low, "B", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.small)
    float sl_p = low[1]
    float risk = close - sl_p
    if risk > 0
        draw_rr(close, sl_p, close + (risk * rr))
 
if sell_trigger
    label.new(bar_index, high, "S", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.small)
    float sl_p = high[1]
    float risk = sl_p - close
    if risk > 0
        draw_rr(close, sl_p, close - (risk * rr))
 
// --- ALERTS ---
alertcondition(buy_trigger, "Long Entry", "UT Bot Buy Signal")
alertcondition(sell_trigger, "Short Entry", "UT Bot Sell Signal")

← 返回列表