RSI + EMA Strategy
//@version=5
indicator(“Long-Term Indian Equities: 10/40 EMA + 14 RSI”, overlay=true)
// — Inputs —
fastLen = input.int(10, title=”Fast EMA Length”)
slowLen = input.int(40, title=”Slow EMA Length”)
rsiLen = input.int(14, title=”RSI Length”)
// — Calculations —
ema10 = ta.ema(close, fastLen)
ema40 = ta.ema(close, slowLen)
rsi14 = ta.rsi(close, rsiLen)
// — Plot EMAs —
plot(ema10, title=”10 EMA”, color=color.new(color.teal, 0), linewidth=2)
plot(ema40, title=”40 EMA”, color=color.new(color.orange, 0), linewidth=2)
// — Signal Logic (Weekly Chart Optimized) —
// Buy: Uptrend intact (Price & 10 EMA > 40 EMA) AND RSI pulls back into 40-48 zone and turns up
uptrend = close > ema40 and ema10 > ema40
rsiBuy = rsi14 >= 40 and rsi14 <= 48 and rsi14 > rsi14
buySignal = uptrend and rsiBuy and not rsiBuy
// Deep Value Buy: Oversold bounce below 32 RSI
deepBuy = ta.crossover(rsi14, 32)
// Sell / Trim: Extreme euphoria (RSI > 80) OR structural trend break (2 weekly closes below 40 EMA)
trimSignal = ta.crossunder(rsi14, 80)
exitSignal = close < ema40 and close < ema40 and close >= ema40
// — Plot Signals on Chart —
plotshape(buySignal, title=”Trend Buy”, location=location.belowbar, color=color.green, style=shape.labelup, text=”BUY”, textcolor=color.white, size=size.small)
plotshape(deepBuy, title=”Deep Value Buy”, location=location.belowbar, color=color.blue, style=shape.labelup, text=”VALUE BUY”, textcolor=color.white, size=size.small)
plotshape(trimSignal, title=”Trim Profits”, location=location.abovebar, color=color.orange, style=shape.labeldown, text=”TRIM”, textcolor=color.white, size=size.small)
plotshape(exitSignal, title=”Trend Exit”, location=location.abovebar, color=color.red, style=shape.labeldown, text=”EXIT”, textcolor=color.white, size=size.small)
// — Alerts —
alertcondition(buySignal or deepBuy, title=”Long-Term Buy Alert”, message=”Buy/Accumulate Signal Triggered on {{ticker}}”)
alertcondition(trimSignal or exitSignal, title=”Long-Term Sell/Trim Alert”, mes


