Downloading...
OPEN-SOURCE SCRIPT

Multi-Indicator Buy/Sell Signals (EMA, RSI, MACD)

112
// This source code is subject to the terms of the Mozilla Public License 2.0
// mozilla.org/MPL/2.0/
// © buy and sell signals gio1

//version=5
indicator("Multi-Indicator Buy/Sell Signals (EMA, RSI, MACD)", overlay=true)

// --- Inputs for Moving Averages ---
fastMALen = input.int(10, title="Fast EMA Length", minval=1)
slowMALen = input.int(20, title="Slow EMA Length", minval=1)

// --- Inputs for RSI ---
rsiLength = input.int(14, title="RSI Length", minval=1)
rsiOB = input.int(70, title="RSI Overbought Level", minval=50, maxval=90)
rsiOS = input.int(30, title="RSI Oversold Level", minval=10, maxval=50)

// --- Inputs for MACD ---
macdFastLen = input.int(12, title="MACD Fast Length", minval=1)
macdSlowLen = input.int(26, title="MACD Slow Length", minval=1)
macdSigLen = input.int(9, title="MACD Signal Length", minval=1)

// --- Calculate Indicators ---
// EMA
fastMA = ta.ema(close, fastMALen)
slowMA = ta.ema(close, slowMALen)

// RSI
rsi = ta.rsi(close, rsiLength)

// MACD
[macdLine, signalLine, hist] = ta.macd(close, macdFastLen, macdSlowLen, macdSigLen)

// --- Define Buy and Sell Conditions ---
// EMA Crossover Condition
emaBuy = ta.crossover(fastMA, slowMA)
emaSell = ta.crossunder(fastMA, slowMA)

// RSI Condition
rsiBuy = rsi[1] < rsiOS and rsi > rsiOS // Crossing up from oversold
rsiSell = rsi[1] > rsiOB and rsi < rsiOB // Crossing down from overbought

// MACD Condition
macdBuy = ta.crossover(macdLine, signalLine)
macdSell = ta.crossunder(macdLine, signalLine)

// --- Combine Conditions for Final Signals ---
buySignal = emaBuy and rsiBuy and macdBuy
sellSignal = emaSell and rsiSell and macdSell

// --- Plot Signals on Chart ---
plotshape(buySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(sellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

// --- Add Alert Conditions ---
alertcondition(buySignal, title="Buy Alert", message="🔔 BUY signal triggered!")
alertcondition(sellSignal, title="Sell Alert", message="🔔 SELL signal triggered!")

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.