Stochastic and RSI in one indicator with customized alert.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HerschelleGirnari

//@version=5
indicator(title="Stochastic Oscillator and Relative Strength Index", shorttitle="HerG Stoch & RSI", 
  format=format.price, precision=0, timeframe="", timeframe_gaps=true, scale = scale.left)

//    ------ >>>>>>     Inputs

LenB = input.int(14, title="Length", minval=1, step =1, tooltip = "No. of bars to calculate.")

StochFast = input.int(9, title="Fast Stochastic", minval=1, step = 1)
StochSlow = input.int(21, title="Slow Stochastic", minval=1, step = 1)

RSIsource = input.source(close, title = "RSI Source", tooltip = "Preferred source data.")

RSIBT1 = input.int(25, title = "Min", minval = 1, maxval = 99, step = 1, 
  tooltip = "Set RSI level for Buy trigger.", inline = "buy level", group = "RSI for Buy")
  
RSIBT2 = input.int(45, title = "Max", minval = 1, maxval = 99, step = 1, 
  tooltip = "Set RSI level for Buy trigger.", inline = "buy level", group = "RSI for Buy")
  
RSIST1 = input.int(75, title = "Max", minval = 1, maxval = 99, step = 1, 
  tooltip = "Set RSI level for Sell trigger.", inline = "Sell level", group = "RSI for Sell")
  
RSIST2 = input.int(55, title = "Min", minval = 1, maxval = 99, step = 1, 
  tooltip = "Set RSI level for Sell trigger.", inline = "Sell level", group = "RSI for Sell")

//        >>>>>  Calculations


stochFull = ta.stoch(close, high, low, LenB)

Fast = ta.sma(stochFull, StochFast)
Slow = ta.sma(stochFull, StochSlow)

RSI = ta.rsi(close, LenB)


UnderLap = ta.crossunder(Slow, Fast)
OverLap = ta.crossover(Slow, Fast)

//  >>>> Plot and Display  

plot(Fast, title="Stochastic Fast", color=color.blue, style=plot.style_line)
plot(Slow, title="Stochastic Slow", color=color.red, style=plot.style_line)
plot(RSI, title="RSI", color = color.purple, linewidth = 2)

h1 = hline(75, "Upper Band", color=color.silver)
h2 = hline(25, "Lower Band", color=color.silver)
h0 = hline(50, "Center Line", color=color.silver, linestyle= hline.style_solid)


//   >>>> Reasoning

ULSignal = RSI > RSIBT1 and RSI < RSIBT2
OLSignal = RSI > RSIST2 and RSI < RSIST1

plotshape(ULSignal ? UnderLap : na, title="Under-lap Signal",  
  style = shape.triangleup, location = location.bottom, size=size.tiny, color= color.lime)

plotshape(OLSignal ? OverLap : na, title="Over-lap Signal",
  style = shape.triangledown, location = location.top, size=size.tiny, color= color.red)


//  Alert Signal when user defined RSI level along with stochastic crossover will send confirmation of trend-setup.

flag = false

if ULSignal and UnderLap
    flag := true
else if OLSignal and OverLap
    flag := true
else
    flag := false


alertcondition(flag, title = "Buy/Sell Signal", message = "Possible trend setup for {{ticker}}. Price = {{close}}, Time: {{timenow}}")

alertcondition(ULSignal ? UnderLap: na, title = "Buy Signal", message = "Buy alarm for {{ticker}}. Price = {{close}}, Time: {{timenow}}")

alertcondition(OLSignal ? OverLap: na, title = "Sell Signal", message = "Sell alarm for {{ticker}}. Price = {{close}}, Time: {{timenow}}")











