RSI Wave Signals
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bartua

// Optimized Trend Tracker function under copyright and courtesy of KivancOzbilgic.

//@version=5
indicator("RSI Wave Signals", overlay=false)

period1 = input(2,"Period For MA")
mtp1 = input.float(0.7,"Trailing Percentage of MA",step=0.1)


rsiLength = input(12,"RSI Length")

ottFunction(src,length,percent)=>
    valpha=2/(length+1)
    vud1=src>src[1] ? src-src[1] : 0
    vdd1=src<src[1] ? src[1]-src : 0
    vUD=math.sum(vud1,9)
    vDD=math.sum(vdd1,9)
    vCMO=nz((vUD-vDD)/(vUD+vDD))
    VAR=0.0
    VAR:=nz(valpha*math.abs(vCMO)*src)+(1-valpha*math.abs(vCMO))*nz(VAR[1])
    MAvg=VAR
    fark=MAvg*percent*0.01
    longStop = MAvg - fark
    longStopPrev = nz(longStop[1], longStop)
    longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
    shortStop =  MAvg + fark
    shortStopPrev = nz(shortStop[1], shortStop)
    shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
    dir = 1
    dir := nz(dir[1], dir)
    dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
    MT = dir==1 ? longStop: shortStop
    OTT=MAvg>MT ? MT*(200+percent)/200 : MT*(200-percent)/200 
    [dir,OTT[2],MAvg]

//MACD Calculations//

rsi = ta.rsi(close,rsiLength)+1000

[dir1,ott1,sl1] = ottFunction(rsi,period1,mtp1)

plot(ott1,title="OTT",linewidth=1,color=color.white)
plot(sl1,title="SL",linewidth=2,color=color.aqua)

overSoldLevel = input(40,title="Oversold Level") +1000
overBoughtLevel = input(60,title="Overbought Level") +1000

plot(overSoldLevel, title="Oversold",style=plot.style_circles,color=color.blue)
plot(overBoughtLevel, title="Overbought",style=plot.style_circles,color=color.blue)




