OPEN-SOURCE SCRIPT

RSI EMA ENTRY

286
//version=6
indicator(title="RSI EMA ENTRY", overlay=false)

// RSI Inputs
rsiLengthInput = input.int(21, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")

// UT Bot Alerts Inputs
key_value = input.int(2, title="Key Value (Sensitivity)")
atr_period = input.int(5, title="ATR Period")
use_heikin_ashi = input.bool(false, title="Use Heikin Ashi Candles")

// ATR Calculation
atr_value = ta.atr(atr_period)
nLoss = key_value * atr_value

// Source Selection
ha_ticker = ticker.heikinashi(syminfo.ticker)
src = use_heikin_ashi ? request.security(ha_ticker, timeframe.period, close) : close

// ATR Trailing Stop Calculation
var float atr_trailing_stop = na
atr_trailing_stop := if src > nz(atr_trailing_stop[1]) and src[1] > nz(atr_trailing_stop[1])
math.max(nz(atr_trailing_stop[1]), src - nLoss)
else if src < nz(atr_trailing_stop[1]) and src[1] < nz(atr_trailing_stop[1])
math.min(nz(atr_trailing_stop[1]), src + nLoss)
else if src > nz(atr_trailing_stop[1])
src - nLoss
else
src + nLoss

// Position Logic
var int pos = 0
pos := if src[1] < nz(atr_trailing_stop[1]) and src > nz(atr_trailing_stop[1])
1
else if src[1] > nz(atr_trailing_stop[1]) and src < nz(atr_trailing_stop[1])
-1
else
nz(pos[1])

// Buy and Sell Signals
ema_value = ta.ema(src, 1)
above = ta.crossover(ema_value, atr_trailing_stop)
below = ta.crossunder(ema_value, atr_trailing_stop)

buy_signal = src > atr_trailing_stop and above
sell_signal = src < atr_trailing_stop and below

// Bar Coloring
barbuy = src > atr_trailing_stop
barsell = src < atr_trailing_stop

plotshape(buy_signal, title="Buy", text="Buy", style=shape.labelup, location=location.belowbar, color=color.green, textcolor=color.white, size=size.tiny, display=display.all,force_overlay = true)
plotshape(sell_signal, title="Sell", text="Sell", style=shape.labeldown, location=location.abovebar, color=color.red, textcolor=color.white, size=size.tiny, display=display.all,force_overlay = true)

barcolor(barbuy ? color.green : na)
barcolor(barsell ? color.red : na)

alertcondition(buy_signal, title="UT Long", message="UT Long")
alertcondition(sell_signal, title="UT Short", message="UT Short")

// RSI Calculation (Separate Pane)
change = ta.change(rsiSourceInput)
up = ta.rma(math.max(change, 0), rsiLengthInput)
down = ta.rma(-math.min(change, 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))

rsiPlot = plot(rsi, "RSI", color=#0e0e0f)
rsiUpperBand = hline(60, "RSI Upper Band", color=#787B86)
midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
rsiLowerBand = hline(40, "RSI Lower Band", color=#787B86)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")

// Smoothing MA inputs
GRP = "Smoothing"
maTypeInput = input.string("EMA", "Type", options = ["None", "SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = GRP, display = display.data_window)
maLengthInput = input.int(14, "Length", group = GRP, display = display.data_window)

var enableMA = maTypeInput != "None"

// Smoothing MA Calculation
ma(source, length, MAtype) =>
switch MAtype
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)

// Smoothing MA plots
smoothingMA = enableMA ? ma(rsi, maLengthInput, maTypeInput) : na
plot(smoothingMA, "RSI-based MA", color=color.yellow, display = enableMA ? display.all : display.none, editable = enableMA)


// EMA 5 Offset 2 (Forcefully on Chart)
ema5 = ta.ema(close, 5)
plot(ema5, title="5 EMA Offset 2", color=color.black, offset=2, linewidth=3, display=display.all,force_overlay = true)

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.