OPEN-SOURCE SCRIPT

RSI and MACD Buy/Sell Strategy with Signals

//version=5
indicator("RSI and MACD Buy/Sell Strategy with Signals", overlay=true)

// Define RSI and MACD parameters
rsiPeriod = 14
macdShort = 12
macdLong = 26
macdSignal = 9

// Calculate RSI
rsi = ta.rsi(close, rsiPeriod)

// Calculate MACD
[macdLine, signalLine, _] = ta.macd(close, macdShort, macdLong, macdSignal)
macdHist = macdLine - signalLine

// Define buy and sell conditions
buyCondition = (rsi < 30) and (macdHist < -7 or macdHist < -8)
sellCondition = (rsi > 60) and (macdHist > 6)

// Plot Buy and Sell signals directly on the main price chart
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY", textcolor=color.white, size=size.small)
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL", textcolor=color.white, size=size.small)

إخلاء المسؤولية