RSI, SRSI, MACD and DMI cross - Open source code
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © Trading_Paradise



//@version=5
indicator("RSI, SRSI, MACD and DMI cross", overlay=true)

// Input
rsiLength = input.int(title="RSI Length", defval=14, minval=1)
smoothK = input.int(title="Smooth K", defval=3, minval=1)
stochLength = input.int(title="Stochastic Length", defval=14, minval=1)
atr = ta.atr(14)


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

// Stoch RSI
stochRsi = ta.stoch(source=rsiOB, high=rsiOB, low=rsiOB, length=stochLength)
stochK = ta.sma(stochRsi, smoothK)
stochD = ta.sma(stochK, smoothK)

// Signals
rsiBuy1 = rsiOB <= 35 and stochK <= 15 
rsiBuy2 =  rsiOB <= 28 and stochK <= 15 or rsiOB <= 25 and stochK <= 10 or rsiOB <= 28
rsiSell1 = rsiOB >= 75 and stochK >= 85
rsiSell2 = rsiOB >= 80 and stochK >= 85 or rsiOB >= 85 and stochK >= 90  or rsiOB >= 82

// Buy Signals
plotshape(rsiBuy1, title="Good Buy", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny)
plotshape(rsiBuy2, title="Incredible Buy", style=shape.labelup, location=location.belowbar, color=color.rgb(149, 137, 48), size=size.small)

// Sell Signals
plotshape(rsiSell1,  title="Good Sell", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny)
plotshape(rsiSell2, title="Incredible Sell", style=shape.labeldown, location=location.abovebar, color=color.rgb(186, 105, 155), size=size.small)

// Special Signals
crossup = ta.crossover(stochK, stochD) and stochK[1] <= 20
crossdown = ta.crossunder(stochK, stochD) and stochK[1] >= 80

plotshape(crossup, title="Stoch crossup", style=shape.circle, location=location.belowbar, color=color.rgb(227, 209, 209), size=size.tiny)
plotshape(crossdown, title="Stoch crossdown", style=shape.circle, location=location.abovebar, color=color.rgb(82, 77, 77), size=size.tiny)

// MACD inputs
fastLength = input.int(12, "Fast Length")
slowLength = input.int(26, "Slow Length")
signalLength = input.int(9, "Signal Length")

// MACD calculations
[macdLine, _, histLine] = ta.macd(close, fastLength, slowLength, signalLength)

// MACD Long signal
longSignal = macdLine < 0 and ta.change(histLine > 0 ? 1 : 0) == 1 and macdLine[1] < 0 and histLine[1] < 0

// MACD Short signal
shortSignal = macdLine > 0 and ta.change(histLine < 0 ? 1 : 0) == 1 and macdLine[1] > 0 and histLine[1] > 0

// Macd Plot signals
plotshape(longSignal ? low : na, title = "Macdcrossup", text="M↑", textcolor=color.blue, style = shape.flag)
plotshape(shortSignal ? high : na, title = "Macdcrossdown", text="M↓", textcolor=color.blue, style = shape.flag)

// DMI inputs
dmiLen = input(14, title="DMI Length")
adxSmoothing = input(14, title="ADX Smoothing")

// Calculate DMIs
[minusDI, plusDI, adx] = ta.dmi(dmiLen, adxSmoothing)

// Bullish signal
bullishSignal = ta.cross(minusDI, plusDI) and minusDI > plusDI

// Bearish signal
bearishSignal = ta.cross(plusDI, minusDI) and plusDI > minusDI

// Plot signals
plotshape(bullishSignal,title="DMI crossup", location=location.belowbar, style = shape.diamond, text="D+", textcolor=color.rgb(227, 209, 209), color=color.rgb(227, 209, 209), size=size.tiny)
plotshape(bearishSignal, title="DMI crossdown", location=location.abovebar, style = shape.diamond, text="D-",textcolor=color.rgb(82, 77, 77), color=color.rgb(82, 77, 77), size=size.tiny)

// RSI buy and sell alerts
rsiBuyAlert = rsiBuy1 or rsiBuy2
rsiSellAlert = rsiSell1 or rsiSell2

alertcondition(rsiBuy1, title="Good Buy ", message="Good moment to buy")
alertcondition(rsiBuy2, title="Incredible Buy", message="Incredible moment to buy")
alertcondition(rsiSell1, title="Good Sell", message="Good moment to sell")
alertcondition(rsiSell2, title="Incredible Sell", message="Incredible moment to to sell")

// Stochastic RSI cross alerts
crossUpAlert = crossup
crossDownAlert = crossdown

alertcondition(crossUpAlert, title="Stochastic RSI Cross Up", message="Stochastic RSI Cross Up")
alertcondition(crossDownAlert, title="Stochastic RSI Cross Down", message="Stochastic RSI Cross Down")

// MACD cross alerts
longSignalAlert = longSignal
shortSignalAlert = shortSignal

alertcondition(longSignalAlert, title="MACD Long Signal", message="MACD Long Signal")
alertcondition(shortSignalAlert, title="MACD Short Signal", message="MACD Short Signal")

// DMI cross alerts
bullishSignalAlert = bullishSignal
bearishSignalAlert = bearishSignal

alertcondition(bullishSignalAlert, title="DMI Bullish Signal", message="DMI Bullish Signal")
alertcondition(bearishSignalAlert, title="DMI Bearish Signal", message="DMI Bearish Signal")
