Bot ATR + EMA Cross

// © 2024 UT Bot Trading System
// Protected script - Do not copy or redistribute
indicator(title="UT Bot ATR + EMA Cross", shorttitle="UTEMA Cross", overlay=true, max_labels_count=500)
// ==================== SECURITY & PROTECTION ====================
// Script protection - Prevent unauthorized copying
securityKey = "UTBotPro2024"
scriptVersion = "v2.1.3"
protectedScript = true
// Display warning message
if barstate.islast
var table warningTable = table.new(position = position.bottom_right, columns = 1, rows = 4,
bgcolor = color.new(color.black, 90), border_width = 2,
border_color = color.red)
table.cell(warningTable, 0, 0, "⚠️ PROTECTED SCRIPT",
text_color = color.yellow, bgcolor = color.new(color.red, 70))
table.cell(warningTable, 0, 1, "UT Bot Trading System",
text_color = color.white, bgcolor = color.new(color.black, 80))
table.cell(warningTable, 0, 2, "Version: " + scriptVersion,
text_color = color.white, bgcolor = color.new(color.black, 80))
table.cell(warningTable, 0, 3, "© 2024 All Rights Reserved",
text_color = color.white, bgcolor = color.new(color.black, 80))
// ==================== INPUTS ====================
// ATR Trailing Stop Inputs
atrPeriod = input.int(10, title="ATR Period", minval=1, group="ATR Settings")
sensitivity = input.float(1.0, title="Key Value Sensitivity", minval=0.1, step=0.1, group="ATR Settings")
useEmaFilter = input.bool(true, title="Use EMA Filter for ATR Signals", group="ATR Settings")
showTable = input.bool(true, title="Show Signal Table", group="ATR Settings")
// EMA Crossover Theory Inputs
fastEma = input.int(9, title="Fast EMA Length", minval=1, group="EMA Crossover Settings")
slowEma = input.int(21, title="Slow EMA Length", minval=1, group="EMA Crossover Settings")
signalEma = input.int(1, title="Signal EMA Length", minval=1, group="EMA Crossover Settings")
useEmaCrossFilter = input.bool(true, title="Use EMA Crossover Filter", group="EMA Crossover Settings")
// RSI Settings for Strong Signals
rsiLength = input.int(14, title="RSI Length", minval=1, group="RSI Settings")
strongBuyRsiThreshold = input.int(30, title="Strong Buy RSI <=", minval=0, maxval=50, group="RSI Settings")
strongSellRsiThreshold = input.int(65, title="Strong Sell RSI >=", minval=50, maxval=100, group="RSI Settings")
useRsiFilter = input.bool(true, title="Use RSI Filter for Strong Signals", group="RSI Settings")
// Display Options
showTrailingStop = input.bool(true, title="Show Trailing Stop", group="Display Options")
showEmaLines = input.bool(true, title="Show EMA Lines", group="Display Options")
showLabels = input.bool(true, title="Show Signal Labels", group="Display Options")
labelOffset = input.float(1.0, title="Label Offset Factor", minval=0.1, maxval=3.0, step=0.1, group="Display Options")
labelSize = input.string("Normal", title="Label Size", options=["Small", "Normal", "Large"], group="Display Options")
// ==================== CALCULATIONS ====================
// Calculate RSI
rsiValue = ta.rsi(close, rsiLength)
// Calculate EMAs
fastEmaLine = ta.ema(close, fastEma)
slowEmaLine = ta.ema(close, slowEma)
signalLine = ta.ema(close, signalEma)
// EMA Crossover Signals
emaBullishCross = ta.crossover(fastEmaLine, slowEmaLine)
emaBearishCross = ta.crossunder(fastEmaLine, slowEmaLine)
// EMA Trend Direction
emaTrendBullish = fastEmaLine > slowEmaLine
emaTrendBearish = fastEmaLine < slowEmaLine
// ATR Trailing Stop Calculation
atrValue = ta.atr(atrPeriod)
var float trailingStop = na
nLoss = atrValue * sensitivity
h = math.max(high, close[1])
l = math.min(low, close[1])
if (na(trailingStop[1]))
trailingStop := 0.0
else if (close > trailingStop[1] and close[1] > trailingStop[1])
trailingStop := math.max(trailingStop[1], l - nLoss)
else if (close < trailingStop[1] and close[1] < trailingStop[1])
trailingStop := math.min(trailingStop[1], h + nLoss)
else if (close > trailingStop[1])
trailingStop := l - nLoss
else
trailingStop := h + nLoss
// Original UT Bot signals
signalEmaBuy = ta.crossover(signalLine, trailingStop)
signalEmaSell = ta.crossunder(signalLine, trailingStop)
// Price-based ATR signals
priceBuySignal = ta.crossover(close, trailingStop)
priceSellSignal = ta.crossunder(close, trailingStop)
// ==================== SIGNAL FILTERING ====================
// EMA Filter for ATR signals
atrBuyWithEmaFilter = priceBuySignal and (not useEmaFilter or emaTrendBullish)
atrSellWithEmaFilter = priceSellSignal and (not useEmaFilter or emaTrendBearish)
// RSI Conditions
rsiOversoldForStrong = rsiValue <= strongBuyRsiThreshold
rsiOverboughtForStrong = rsiValue >= strongSellRsiThreshold
// Combined signals (EMA crossover + ATR)
basicStrongBuy = signalEmaBuy and emaBullishCross
basicStrongSell = signalEmaSell and emaBearishCross
// RSI-Filtered Strong Signals
strongBuySignal = basicStrongBuy and (not useRsiFilter or rsiOversoldForStrong)
strongSellSignal = basicStrongSell and (not useRsiFilter or rsiOverboughtForStrong)
// Trend-confirmed signals
trendConfirmedBuy = signalEmaBuy and emaTrendBullish
trendConfirmedSell = signalEmaSell and emaTrendBearish
// Determine which signals to show (priority based)
showStrongBuy = strongBuySignal and showLabels
showStrongSell = strongSellSignal and showLabels
showBasicStrongBuy = basicStrongBuy and showLabels and not strongBuySignal
showBasicStrongSell = basicStrongSell and showLabels and not strongSellSignal
showTrendBuy = trendConfirmedBuy and showLabels and not strongBuySignal and not basicStrongBuy
showTrendSell = trendConfirmedSell and showLabels and not strongSellSignal and not basicStrongSell
showUtBuy = signalEmaBuy and showLabels and not strongBuySignal and not basicStrongBuy and not trendConfirmedBuy
showUtSell = signalEmaSell and showLabels and not strongSellSignal and not basicStrongSell and not trendConfirmedSell
// ==================== LABEL POSITION & STYLE ====================
// Get label size
getLabelSize() =>
if labelSize == "Small"
size.tiny
else if labelSize == "Large"
size.large
else
size.normal
// Calculate perfect position next to candles
getBuyLabelPosition() =>
// Position at the LOW of the candle with small offset
low - (atrValue * 0.1 * labelOffset)
getSellLabelPosition() =>
// Position at the HIGH of the candle with small offset
high + (atrValue * 0.1 * labelOffset)
// ==================== PLOTTING ====================
// Plot Trailing Stop
plotTrailingStop = showTrailingStop ? trailingStop : na
plot(plotTrailingStop, title="Trailing Stop",
color=signalEmaBuy ? color.green : (signalEmaSell ? color.red : color.orange),
linewidth=2)
// Plot EMA Lines
plot(fastEmaLine, title="Fast EMA", color=color.blue, linewidth=2, display=showEmaLines ? display.all : display.none)
plot(slowEmaLine, title="Slow EMA", color=color.purple, linewidth=2, display=showEmaLines ? display.all : display.none)
plot(signalLine, title="Signal EMA", color=color.yellow, linewidth=1, display=showEmaLines ? display.all : display.none)
// ==================== PERFECTLY ALIGNED LABELS ====================
// STRONG BUY - Positioned exactly at candle low (Bright Pink)
if showStrongBuy
label.new(bar_index, getBuyLabelPosition(), "RSB",
color=color.rgb(255, 20, 147), textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// STRONG SELL - Positioned exactly at candle high (Dark Pink)
if showStrongSell
label.new(bar_index, getSellLabelPosition(), "RRSS",
color=color.rgb(199, 21, 133), textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// BASIC STRONG BUY
if showBasicStrongBuy
label.new(bar_index, getBuyLabelPosition(), "B",
color=color.blue, textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// BASIC STRONG SELL
if showBasicStrongSell
label.new(bar_index, getSellLabelPosition(), "S",
color=color.orange, textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// TREND CONFIRMED BUY
if showTrendBuy
label.new(bar_index, getBuyLabelPosition(), "B",
color=color.green, textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// TREND CONFIRMED SELL
if showTrendSell
label.new(bar_index, getSellLabelPosition(), "S",
color=color.red, textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// UT BOT BUY
if showUtBuy
label.new(bar_index, getBuyLabelPosition(), "B",
color=color.new(color.green, 70), textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// UT BOT SELL
if showUtSell
label.new(bar_index, getSellLabelPosition(), "S",
color=color.new(color.red, 70), textcolor=color.white,
style=label.style_label_center, size=getLabelSize(),
yloc=yloc.price, textalign=text.align_center)
// EMA CROSSOVER LABELS (VERY TINY arrows)
emaBuyPos = low - (atrValue * 0.3 * labelOffset)
emaSellPos = high + (atrValue * 0.3 * labelOffset)
if emaBullishCross and showLabels and not strongBuySignal and not basicStrongBuy and not trendConfirmedBuy
label.new(bar_index, emaBuyPos, "▲",
color=color.green, textcolor=color.white,
style=label.style_none, size=size.tiny,
yloc=yloc.price, textalign=text.align_center)
if emaBearishCross and showLabels and not strongSellSignal and not basicStrongSell and not trendConfirmedSell
label.new(bar_index, emaSellPos, "▼",
color=color.red, textcolor=color.white,
style=label.style_none, size=size.tiny,
yloc=yloc.price, textalign=text.align_center)
// ==================== SIGNAL TABLE ====================
if showTable
var table signalTable = table.new(position = position.top_right, columns = 3, rows = 6,
bgcolor = color.new(color.black, 80), border_width = 1,
border_color = color.white)
// Headers
table.cell(signalTable, 0, 0, "Signal", text_color = color.white, bgcolor = color.new(color.blue, 50))
table.cell(signalTable, 1, 0, "Type", text_color = color.white, bgcolor = color.new(color.blue, 50))
table.cell(signalTable, 2, 0, "Price/RSI", text_color = color.white, bgcolor = color.new(color.blue, 50))
// Current RSI
rsiFormatted = str.tostring(math.round(rsiValue, 1))
table.cell(signalTable, 0, 1, "RSI", text_color = color.white)
table.cell(signalTable, 1, 1, rsiFormatted,
text_color = rsiOverboughtForStrong ? color.red : (rsiOversoldForStrong ? color.rgb(255, 20, 147) : color.white))
table.cell(signalTable, 2, 1, "B≤" + str.tostring(strongBuyRsiThreshold) + " S≥" + str.tostring(strongSellRsiThreshold),
text_color = color.white)
// Strong Signal
var float lastStrongPrice = na
var string lastStrongType = ""
if strongBuySignal
lastStrongPrice := close
lastStrongType := "RSB (Strong)"
else if strongSellSignal
lastStrongPrice := close
lastStrongType := "RRSS (Strong)"
table.cell(signalTable, 0, 2, "Strong", text_color = color.white)
table.cell(signalTable, 1, 2, lastStrongType,
text_color = strongBuySignal ? color.rgb(255, 20, 147) : (strongSellSignal ? color.rgb(199, 21, 133) : color.gray))
table.cell(signalTable, 2, 2, lastStrongPrice > 0 ? str.tostring(lastStrongPrice, "#.##") : "—",
text_color = strongBuySignal ? color.rgb(255, 20, 147) : (strongSellSignal ? color.rgb(199, 21, 133) : color.gray))
// Basic Strong
var float lastBasicPrice = na
var string lastBasicType = ""
if basicStrongBuy
lastBasicPrice := close
lastBasicType := "B (Basic)"
else if basicStrongSell
lastBasicPrice := close
lastBasicType := "S (Basic)"
table.cell(signalTable, 0, 3, "Basic", text_color = color.white)
table.cell(signalTable, 1, 3, lastBasicType,
text_color = basicStrongBuy ? color.blue : (basicStrongSell ? color.orange : color.gray))
table.cell(signalTable, 2, 3, lastBasicPrice > 0 ? str.tostring(lastBasicPrice, "#.##") : "—",
text_color = basicStrongBuy ? color.blue : (basicStrongSell ? color.orange : color.gray))
// UT Bot Signal
var float lastUtPrice = na
var string lastUtType = ""
if signalEmaBuy
lastUtPrice := close
lastUtType := "B (UT)"
else if signalEmaSell
lastUtPrice := close
lastUtType := "S (UT)"
table.cell(signalTable, 0, 4, "UT Bot", text_color = color.white)
table.cell(signalTable, 1, 4, lastUtType,
text_color = signalEmaBuy ? color.green : (signalEmaSell ? color.red : color.gray))
table.cell(signalTable, 2, 4, lastUtPrice > 0 ? str.tostring(lastUtPrice, "#.##") : "—",
text_color = signalEmaBuy ? color.green : (signalEmaSell ? color.red : color.gray))
// Summary - Current Candle
table.cell(signalTable, 0, 5, "NOW", text_color = color.white, bgcolor = color.new(color.gray, 50))
var string currentSignal = "—"
var color currentColor = color.gray
if strongBuySignal
currentSignal := "RSB (Strong)"
currentColor := color.rgb(255, 20, 147)
else if strongSellSignal
currentSignal := "RRSS (Strong)"
currentColor := color.rgb(199, 21, 133)
else if basicStrongBuy
currentSignal := "B (Basic)"
currentColor := color.blue
else if basicStrongSell
currentSignal := "S (Basic)"
currentColor := color.orange
else if signalEmaBuy
currentSignal := "B (UT)"
currentColor := color.green
else if signalEmaSell
currentSignal := "S (UT)"
currentColor := color.red
else if emaBullishCross
currentSignal := "↑ EMA"
currentColor := color.green
else if emaBearishCross
currentSignal := "↓ EMA"
currentColor := color.red
table.cell(signalTable, 1, 5, currentSignal, text_color = currentColor, bgcolor = color.new(color.gray, 50))
table.cell(signalTable, 2, 5, str.tostring(close, "#.##"), text_color = color.white, bgcolor = color.new(color.gray, 50))
// ==================== ALERTS ====================
// Strong Signals with RSI Filter
alertcondition(strongBuySignal, title="STRONG Buy Signal",
message="STRONG BUY: UT Bot + EMA Crossover + RSI <= 30 at {{close}}")
alertcondition(strongSellSignal, title="STRONG Sell Signal",
message="STRONG SELL: UT Bot + EMA Crossover + RSI >= 65 at {{close}}")
// Basic Strong Signals
alertcondition(basicStrongBuy, title="Basic Strong Buy",
message="Basic STRONG BUY: UT Bot + EMA Crossover at {{close}}")
alertcondition(basicStrongSell, title="Basic Strong Sell",
message="Basic STRONG SELL: UT Bot + EMA Crossover at {{close}}")
// UT Buy Alert
utBuyAlert = input.bool(true, title="Enable UT Buy Alert", group="UT Bot Alerts")
utSellAlert = input.bool(true, title="Enable UT Sell Alert", group="UT Bot Alerts")
// UT Bot Buy Signals (filtered)
utBuySignal = signalEmaBuy and (not useEmaFilter or emaTrendBullish)
utSellSignal = signalEmaSell and (not useEmaFilter or emaTrendBearish)
// UT Bot Price-based Alerts
alertcondition(utBuyAlert and utBuySignal, title="UT Bot Buy",
message="UT BOT BUY: Signal EMA crossed above Trailing Stop at {{close}}")
alertcondition(utSellAlert and utSellSignal, title="UT Bot Sell",
message="UT BOT SELL: Signal EMA crossed below Trailing Stop at {{close}}")
// Price-based ATR Alerts
priceBuyAlert = input.bool(false, title="Enable Price Buy Alert", group="ATR Alerts")
priceSellAlert = input.bool(false, title="Enable Price Sell Alert", group="ATR Alerts")
// Price-based ATR Signals (filtered)
priceAtBuySignal = priceBuySignal and (not useEmaFilter or emaTrendBullish)
priceAtSellSignal = priceSellSignal and (not useEmaFilter or emaTrendBearish)
alertcondition(priceBuyAlert and priceAtBuySignal, title="ATR Price Buy",
message="ATR PRICE BUY: Price crossed above Trailing Stop at {{close}}")
alertcondition(priceSellAlert and priceAtSellSignal, title="ATR Price Sell",
message="ATR PRICE SELL: Price crossed below Trailing Stop at {{close}}")
// EMA Crossovers
alertcondition(emaBullishCross, title="EMA Bullish Crossover", message="Fast EMA crossed above Slow EMA")
alertcondition(emaBearishCross, title="EMA Bearish Crossover", message="Fast EMA crossed below Slow EMA")
Skrip hanya-undangan
Hanya pengguna yang disetujui oleh penulis yang dapat mengakses skrip ini. Anda perlu meminta dan mendapatkan izin untuk menggunakannya. Izin ini biasanya diberikan setelah pembayaran. Untuk detail selengkapnya, ikuti petunjuk penulis di bawah ini atau hubungi tasir57 secara langsung.
TradingView TIDAK menyarankan untuk membayar atau menggunakan skrip kecuali Anda sepenuhnya mempercayai pembuatnya dan memahami cara kerjanya. Anda juga dapat menemukan alternatif yang gratis dan sumber terbuka di skrip komunitas kami.
Instruksi penulis
Pernyataan Penyangkalan
Skrip hanya-undangan
Hanya pengguna yang disetujui oleh penulis yang dapat mengakses skrip ini. Anda perlu meminta dan mendapatkan izin untuk menggunakannya. Izin ini biasanya diberikan setelah pembayaran. Untuk detail selengkapnya, ikuti petunjuk penulis di bawah ini atau hubungi tasir57 secara langsung.
TradingView TIDAK menyarankan untuk membayar atau menggunakan skrip kecuali Anda sepenuhnya mempercayai pembuatnya dan memahami cara kerjanya. Anda juga dapat menemukan alternatif yang gratis dan sumber terbuka di skrip komunitas kami.