OPEN-SOURCE SCRIPT

MACD RSI EMA Strategy

83
//version=5
indicator("MACD RSI EMA Strategy", overlay=true)

// MACD Calculation
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
macdCrossUp = ta.crossover(macdLine, signalLine)
macdCrossDown = ta.crossunder(macdLine, signalLine)

// RSI Calculation
rsiValue = ta.rsi(close, 14)
rsiAbove50 = rsiValue > 50
rsiBelow50 = rsiValue < 50

// EMA Calculation
ema9 = ta.ema(close, 9)
priceBelowEma9 = close < ema9
priceAboveEma9 = close > ema9

// Buy and Sell Conditions
buySignal = macdCrossUp and rsiAbove50 and priceAboveEma9
sellSignal = macdCrossDown and rsiBelow50 and priceBelowEma9

// Plot Buy/Sell Signals
plotshape(buySignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal")
plotshape(sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal")

// Plot EMA
plot(ema9, title="EMA 9", color=color.blue)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.