RSI true swings
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradeswithashish

//@version=5
indicator(title="RSI true swings indicator", shorttitle="RSI True swings", overlay=true)
upthresh=input.int(title="RSI Upper threshhold", defval=60, minval=50, step=5, maxval=90)
lwthresh=input.int(title="RSI Lower threshhold", defval=40, minval=10, step=5, maxval=50)
//volume criteria checkup
volcheck=volume>ta.sma(volume, 20)
my_rsi=ta.rsi(close, 14)

//Candle size must be above average 
bullbar_check= close>high[1] and (high-low)>ta.sma(high-low, 20) and (close-low)>(high-close) and low<=high[1]
bearbar_check= close<low[1] and (high-low)>ta.sma(high-low, 20) and (high-close)>(close-low) and high>=low[1]

//RSI crossover/crossunder must fulfilling following criteria
rsicrossover=ta.crossover(my_rsi, lwthresh) and volcheck and bullbar_check and volume>volume[1] and close>high[1] and open<close and close>high[2] and my_rsi[1]>lwthresh-10
rsicrossunder=ta.crossunder(my_rsi, upthresh) and volcheck and close<low[1] and bearbar_check and volume>volume[1] and open>close and close<low[2] and my_rsi[1]<upthresh+10


//Plotting the signal confirming
plotshape(rsicrossover, title="Short exit or Buy Entry", style= shape.labelup, location=location.belowbar, color=color.green, size=size.tiny, text="BUY", textcolor=color.white)
plotshape(rsicrossunder, title="Bull exit or Short entry", style= shape.labeldown, location=location.abovebar, color=color.red, size=size.tiny, text="SELL", textcolor=color.white)

rec_high=ta.highest(high,5)
rec_low=ta.lowest(low, 5)
if rsicrossover
    alert(str.tostring(syminfo.ticker)+": Exit SELL or BUY now"+"\n Stoploss below " + str.tostring(rec_low) + "\n CMP "+ str.tostring(close), alert.freq_once_per_bar_close)

if rsicrossunder
    alert(str.tostring(syminfo.ticker)+": Exit BUY or SELL now \n Stoploss above"+ str.tostring(rec_high) + "\n CMP "+ str.tostring(close), alert.freq_once_per_bar_close)