OPEN-SOURCE SCRIPT

Enhanced Buy/Sell Signals

99
//version=5
indicator("Enhanced Buy/Sell Signals", overlay=true)

// Parameters
lengthRSI = input(14, title="RSI Length")
lengthSMA = input(50, title="SMA Length")
overbought = input(70, title="Overbought Level")
oversold = input(30, title="Oversold Level")
fastLength = input(12, title="MACD Fast Length")
slowLength = input(26, title="MACD Slow Length")
signalSmoothing = input(9, title="MACD Signal Smoothing")

// Indicators
rsi = ta.rsi(close, lengthRSI)
sma = ta.sma(close, lengthSMA)
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)

// Buy/Sell Conditions
buySignal = ta.crossover(rsi, oversold) and close > sma and ta.crossover(macdLine, signalLine)
sellSignal = ta.crossunder(rsi, overbought) and close < sma and ta.crossunder(macdLine, signalLine)

// Plotting
plotshape(series=buySignal, title="Buy", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellSignal, title="Sell", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// Alerts
alertcondition(buySignal, title="Buy Signal", message="Buy signal detected!")
alertcondition(sellSignal, title="Sell Signal", message="Sell signal detected!")

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.