RSI Trend Transform [wbburgin]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © wbburgin

//@version=5
indicator("RSI Trend Transform [wbburgin]",overlay=false)

import TradingView/ta/5

src = input.source(close,"RSI Source")
len = input.int(200,"RSI Length")

plotp = input.bool(true,"Price RSI",inline="P")
typp = input.string("Stochastic",options=["Stochastic","Regular"],title="",inline="P")
colp = input.color(color.yellow,title="",inline="P")
smoothp = input.int(7,"Smooth",inline="P")

plotv = input.bool(true,"Volume RSI",inline="V")
typv = input.string("Stochastic",options=["Stochastic","Regular"],title="",inline="V")
colv = input.color(color.red,title="",inline="V")
smoothv = input.int(7,"Smooth",inline="V")

plots = input.bool(false,"Combined RSI",inline="C")
cols = input.color(color.orange,title="",inline="C")
smooths = input.int(7,"Smooth",inline="C")

ub = input.int(80,"Upper Band")
lb = input.int(20,"Lower Band")

rsi_directional(src, length)=>
    p_index = 0.
    n_index = 0.
    av_src = ta.sma(src,length)
    for i=1 to length
        if av_src > av_src[1]
            p_index += av_src - av_src[1]
        if av_src < av_src[1]
            n_index += av_src[1] - av_src
    rel = ta.rma(p_index / (p_index + n_index),length) * 100

pd = rsi_directional(src,len)
vd = rsi_directional(volume,len)

rsi_ = typp == "Stochastic" ? ta.stoch(pd,pd,pd,len) : pd
vol_ = typv == "Stochastic" ? ta.stoch(vd,vd,vd,len) : vd
sq = math.avg(rsi_,vol_)

rsis = ta.ema(rsi_,smoothp)
vols = ta.ema(vol_,smoothv)
sqs = ta.ema(sq,smooths)

pp=plot(plotp ? rsis : na,color=colp,title="Price RSI")
vp=plot(plotv ? vols : na,color=colv,title="Volume RSI")
sp=plot(plots ? sqs : na,color=cols,title="Combined RSI")
ubp = plot(ub,color=color.white)
lbp = plot(lb,color=color.white)

fill(ubp,lbp,color=color.new(color.purple,88))