OPEN-SOURCE SCRIPT

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

83
// 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!")

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.