Constance Brown RSI
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Decam9

//@version=4
study(title = "Constance Brown Altered RSI", shorttitle = "CB Altered RSI", overlay = false)

//Plot the RSI
rsiLength = input(defval = 14, title = "RSI Length"), rsiSource = input(defval = close, title = "RSI Source")
rsi = rsi(rsiSource, rsiLength)
Signal = ema(rsi,input(9, title = "Signal length"))
plot(rsi, color = color.purple, title = "RSI")
plot(Signal, color = color.black, title = "Signal")

//Trend Determination
Ma1 = input(defval = 100, title = "Short Trend MA")
Ma2 = input(defval = 200, title = "Long Trend MA")
isUptrend = sma(close,Ma1) >= sma(close,Ma2)

//colors
green = color.rgb(0,255,0,0)
red = color.rgb(255,0,0,0)
clear = color.rgb(0,0,0,100)
bullshade = color.rgb(0,255,0,99)
bearshade = color.rgb(255,0,0,99)

//Bullzone Resistance
BullOBT = plot(90, color = isUptrend ? green : clear, linewidth = 1, title = "Bullish Resistance")
BullOBB = plot(80, color = isUptrend ? green : clear, linewidth = 1, title = "Bullish Resistance")

//Bearzone Resistance
BearOBT = plot(65, color = isUptrend ? clear : red, linewidth = 1, title = "Bearish Resistance")
BearOBB = plot(55, color = isUptrend ? clear : red, linewidth = 1, title = "Bearish Resistance")

//Bullzone Support
BullOST = plot(50, color = isUptrend ? green : clear, linewidth = 1, title = "Bullish Support")
BullOSB = plot(40, color = isUptrend ? green : clear, linewidth = 1, title = "Bullish Support")

//Bearzone Support
BearOST = plot(30, color = isUptrend ? clear : red, linewidth = 1, title = "Bearish Support")
BearOSB = plot(20, color = isUptrend ? clear : red, linewidth = 1, title = "Bearish Support")


//Fill the zones 
fill(BullOBT, BullOBB, color = isUptrend ? bullshade : clear, title = "Bullzone Resistance shade")
fill(BullOST, BullOSB, color = isUptrend ? bearshade : clear, title = "Bullzone Support shade")
fill(BearOBT, BearOBB, color = isUptrend ? clear : bullshade, title = "Bearzone Resistance shade")
fill(BearOST, BearOSB, color = isUptrend ? clear : bearshade, title = "Bearzone Support shade")
