Relatively Good Adviser
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JOJOGLO
//@version=4
study("Relatively Good Adviser", "RGA", overlay=true)
//-----Chart-Colors-----//
upColor = input(color.rgb(0, 230, 118,5), title = "upColor")
dnColor = input(color.rgb(255, 82, 82,5), title ="dnColor")
sdColor = input(color.rgb(223, 234, 120,8), title ="sdColor")
rsiColor =  input(color.rgb(223, 234, 120,8), title ="sdColor") //input(color.rgb(54, 58, 69,5), title = "rsiColor")
maColor = input(color.rgb(134, 174, 221,55), title = "maColor")
//-----Smoothed Moving Average-----//
getSMMA(len) =>
    smma = 0.0
    smma := na(smma[1]) ? sma(hlc3, len) : (smma[1] * (len - 1) + hlc3) / len
    smma
   
smma = getSMMA(3)
//-----Finger-Weighted-Price-----//
upPrice = (high + high + low) / 3
dnPrice = (low + low + high) / 3
//-----RSI-----//
rsiLine = rsi(close, 7)
//-----RSI-LOGIC-----//
signal = rsiLine > 50 ? "buy" : rsiLine <= 50 ? "sell" : "none"
//-----FWA-LOGIC----//
signal := signal == "buy" and smma > upPrice or signal == "sell" and smma < dnPrice ? "none" : signal
//-----RSI-BAR-FLIP-----//
signal := rsiLine[1] <= 50 and rsiLine > 50 or rsiLine[1] > 50 and rsiLine <= 50 ? "burnt" : signal
//-----RSI-LIMITER-----//
signal := signal[2] == "burnt" and signal == "burnt" or signal[1] == "burnt" and signal == "burnt" ? "none" : signal
limCon = signal == "burnt" ? true : false
//-----RSI-LAW-----//
signal := signal[2] == "burnt" and signal == "none" and close > smma and smma < upPrice ? "buy" : signal
signal := signal[2] == "burnt" and signal == "none" and close < smma and smma > dnPrice ? "sell" : signal
signal := signal[1] == "burnt" and signal == "none" and close > smma and smma < upPrice ? "buy" : signal
signal := signal[1] == "burnt" and signal == "none" and close < smma and smma > dnPrice ? "sell" : signal
//-----Color-&-Plot-----//
palette = signal == "buy" ? upColor :signal == "sell" ? dnColor : signal == "burnt" ? rsiColor : signal == "test" ? color.fuchsia : sdColor
plotbar(open, high, low, close, color=palette)
plot(smma, linewidth=1, color = maColor)
//-----Show-RSI-Flips-----//
upCon1 = rsiLine[1] <= 50 and rsiLine > 50 and limCon
dnCon1 = rsiLine[1] > 50 and rsiLine <= 50 and limCon
upCon2 = rsiLine[1] <= 50 and rsiLine > 50 and not limCon
dnCon2 = rsiLine[1] > 50 and rsiLine <= 50 and not limCon
upClr1 = color.rgb(0, 230, 118,5)
dnClr1 = color.rgb(255, 82, 82,5)
upClr2 = color.rgb(223, 234, 120,64)
dnClr2 = color.rgb(223, 234, 120,64)

plotshape(upCon1, style = shape.triangleup, location = location.abovebar, color = upClr1 , transp = 92)
plotshape(dnCon1, style = shape.triangledown, location = location.belowbar, color = dnClr1 , transp = 92)
plotshape(upCon2, style = shape.triangleup, location = location.abovebar, color = upClr2 , transp = 92)
plotshape(dnCon2, style = shape.triangledown, location = location.belowbar, color = dnClr2 , transp = 92)