Auto alerts for BUY and SELL signals.
TradingView Pine Script (v6) that combines:
-
Heikin Ashi candles for smoother trends.
-
EMA (7, 21, 50) for short, mid, and long-term trend filters.
-
SMA (user adjustable, e.g., 200-period).
-
RSI for momentum confirmation.
-
Auto Buy/Sell signals when trend + momentum conditions align.
//@version=6
indicator(“SMA + Heikin Ashi + EMA 7/21/50 + RSI Strategy”, overlay=true, timeframe=””, timeframe_gaps=true)// === INPUTS ===
smaLength = input.int(200, “SMA Length”)
ema1Length = input.int(7, “EMA 1 (Fast)”)
ema2Length = input.int(21, “EMA 2 (Medium)”)
ema3Length = input.int(50, “EMA 3 (Long)”)
rsiLength = input.int(14, “RSI Length”)
rsiOB = input.int(70, “RSI Overbought”)
rsiOS = input.int(30, “RSI Oversold”)// === HEIKIN ASHI CALC ===
haClose = (open + high + low + close) / 4
haOpen = na(haOpen[1]) ? (open + close)/2 : (haOpen[1] + haClose[1]) / 2
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))// === MOVING AVERAGES ===
sma = ta.sma(close, smaLength)
emaFast = ta.ema(close, ema1Length)
emaMed = ta.ema(close, ema2Length)
emaLong = ta.ema(close, ema3Length)// === RSI ===
rsi = ta.rsi(close, rsiLength)// === TREND CONDITIONS ===
bullTrend = (emaFast > emaMed and emaMed > emaLong and haClose > sma and rsi > 50)
bearTrend = (emaFast < emaMed and emaMed < emaLong and haClose < sma and rsi < 50)// === BUY & SELL SIGNALS ===
buySignal = bullTrend and ta.crossover(emaFast, emaMed) and rsi > 50
sellSignal = bearTrend and ta.crossunder(emaFast, emaMed) and rsi < 50// === PLOT MOVING AVERAGES ===
plot(sma, “SMA”, color=color.orange, linewidth=2)
plot(emaFast, “EMA 7”, color=color.teal)
plot(emaMed, “EMA 21”, color=color.blue)
plot(emaLong, “EMA 50″, color=color.red)// === SIGNAL PLOTS ===
plotshape(buySignal, title=”BUY”, location=location.belowbar, color=color.green, style=shape.labelup, text=”BUY”)
plotshape(sellSignal, title=”SELL”, location=location.abovebar, color=color.red, style=shape.labeldown, text=”SELL”)// === ALERT CONDITIONS ===
alertcondition(buySignal, title=”BUY Alert”, message=”Buy Signal Triggered”)
alertcondition(sellSignal, title=”SELL Alert”, message=”Sell Signal Triggered”)// === SHOW RSI ON SEPARATE PANEL ===
indicator(“RSI Panel”, overlay=false)
plot(rsi, “RSI”, color=color.purple)
hline(rsiOB, “Overbought”, color=color.red)
hline(rsiOS, “Oversold”, color=color.green)
How this works:
-
Buy Signal: When EMA 7 crosses above EMA 21, trend is bullish (above EMA 50 & SMA), and RSI > 50.
-
Sell Signal: When EMA 7 crosses below EMA 21, trend is bearish (below EMA 50 & SMA), and RSI < 50.
-
Plots: EMA 7 (teal), EMA 21 (blue), EMA 50 (red), SMA (orange).
-
Alerts: Auto alerts for BUY and SELL signals.
-
RSI Panel: Separate RSI indicator with OB/OS lines.