Muyyu oscillator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dnshzlkfli

//@version=5
indicator(title = "Muyyu oscillator", shorttitle = "Muyyu oscillator", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
lengthMO = input.int(title = "MO line",defval =21, minval=1)
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src, lengthMO)
dev = mult * ta.stdev(src, lengthMO)
upper = basis + dev
lower = basis - dev
mor = ((src - lower)/(upper - lower))
plot(mor, "muyyu oscillator", color.blue , linewidth = 2)
band1 = hline(0.8, "Overbought", color=#787B86, linestyle=hline.style_dashed)
band0 = hline(0.2, "Oversold", color=#787B86, linestyle=hline.style_dashed)
band2 = hline(1, "Overbought", color=#787B86, linestyle=hline.style_dashed)
band3 = hline(0, "Oversold", color=#787B86, linestyle=hline.style_dashed)
fill(band1, band0,color.rgb(38, 166, 154, 95) )




length = input.int(21, 'length', minval=1)
K1 = (2 * close - high - low) 
K2 = high != low ? high - low : 1
INT = (K1 / K2)*volume
INTSUM = math.sum(INT, length)
coloff = INTSUM > 0 ? color.rgb(38, 166, 154, 70) : color.red


//color
bullColor = input.color(color.rgb(38, 166, 154, 70), inline = "1")
bearColor = input.color(color.red, inline = "1")

backgroundColor = if INTSUM >= 0
    color.from_gradient(INTSUM, 0, 1000, color.new(bullColor, 75), bullColor)
else
    color.from_gradient(INTSUM, -1000, 0, bearColor, color.new(bearColor, 75))
    
bgcolor(backgroundColor)