RSX of Double MACD [Loxx]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx

//@version=5

indicator("RSX of Double MACD [Loxx]", overlay = false, shorttitle="RSXDMACD [Loxx]", timeframe="", timeframe_gaps=true)

greencolor = #2DD204  
redcolor = #D2042D 


_rsx_rsi(src, len)=>
    src_out = 100 * src
    mom0 = ta.change(src_out)
    moa0 = math.abs(mom0)
    Kg = 3 / (len + 2)
    Hg = 1 - Kg
 
    //mom
    f28 = 0.0, f30 = 0.0
    f28 := Kg * mom0 + Hg * nz(f28[1])
    f30 := Hg * nz(f30[1]) + Kg * f28
    mom1 = f28 * 1.5 - f30 * 0.5
 
    f38 = 0.0, f40 = 0.0
    f38 := Hg * nz(f38[1]) + Kg * mom1
    f40 := Kg * f38 + Hg * nz(f40[1])
    mom2 = f38 * 1.5 - f40 * 0.5
 
    f48 = 0.0, f50 = 0.0
    f48 := Hg * nz(f48[1]) + Kg * mom2
    f50 := Kg * f48 + Hg * nz(f50[1])
    mom_out = f48 * 1.5 - f50 * 0.5
 
    //moa
    f58 = 0.0, f60 = 0.0
    f58 := Hg * nz(f58[1]) + Kg * moa0
    f60 := Kg * f58 + Hg * nz(f60[1])
    moa1 = f58 * 1.5 - f60 * 0.5
 
    f68 = 0.0, f70 = 0.0
    f68 := Hg * nz(f68[1]) + Kg * moa1
    f70 := Kg * f68 + Hg * nz(f70[1])
    moa2 = f68 * 1.5 - f70 * 0.5
 
    f78 = 0.0, f80 = 0.0
    f78 := Hg * nz(f78[1]) + Kg * moa2
    f80 := Kg * f78 + Hg * nz(f80[1])
    moa_out = f78 * 1.5 - f80 * 0.5
 
    rsiout = math.max(math.min((mom_out / moa_out + 1.0) * 50.0, 100.00), 0.00)
    rsiout

    
src = input.source(close, "Source", group =  "Basic Settings")
len = input.int(25, "RSI Period", group =  "Basic Settings")
macdFast = input.int(12, "MACD Fast Length", group =  "Basic Settings")
macdSlow = input.int(26, "MACD Slow Length", group =  "Basic Settings")

overbought = input.int(100, "Overbought Level", group =  "Basic Settings")
oversold = input.int(0, "Oversold Level", group =  "Basic Settings")
colorbars = input.bool(false, "Color bars?", group = "UI Options")

kg = (3.0) / (2.0 + len)
hg = 1.0 - kg

price = ta.sma(src, 1)
mact  = ta.ema(price, macdFast)-ta.ema(price, macdSlow)
macd  = ta.ema(mact, macdFast)-ta.ema(mact, macdSlow)
wrkVar = macd

rsx =_rsx_rsi(wrkVar, len)

plot(rsx, color = rsx > rsx[1] ? greencolor : redcolor, linewidth = 2)


plot(50, color=color.new(color.gray, 30), linewidth=1, style=plot.style_circles, title = "Zero line")

tl = plot(overbought, color=color.rgb(0, 255, 255, 100), style=plot.style_line, title = "Overbought Level 2")
tl1 = plot(overbought-5, color=color.rgb(0, 255, 255, 100), style=plot.style_line, title = "Overbought Level 1")


bl1 = plot(oversold, color=color.rgb(255, 255, 255, 100), style=plot.style_line, title = "Overbought Level 1")
bl = plot(oversold+5, color=color.rgb(255, 255, 255, 100), style=plot.style_line, title = "Overbought Level 2")

fill(tl, tl1, color=color.new(color.gray, 85), title = "Top Boundary Fill Color")
fill(bl, bl1, color=color.new(color.gray, 85), title = "Bottom Boundary Fill Color")


barcolor(colorbars ? rsx > rsx[1] ? greencolor : redcolor : na)






