DEMA Supertrend Bands [Misu]
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
//@version=5
indicator(title="DEMA Supertrend Bands [Misu]", shorttitle="DEMA Supertrend [Misu]", overlay=true, timeframe="", timeframe_gaps=true)
lenMas                  = input.int(10, minval=1, title="Length DEMA")
lenAtr                  = input.int(14, minval=1, title="Length Atr")
mult                    = input.float(1.5, step=0.1, minval=0.001, maxval=50, title="Band Mult")

 // @function to get dema.
getDema(float src, simple int length) => 
    ema1= ta.ema(src, length)
    ema2 = ta.ema(ema1,length)
    differenceFast = ema1 - ema2
    zerolagEMA = ema1 + differenceFast
    dema = (2 * ema1) - ema2
    dema

atr           = ta.atr(lenAtr)
bandOffset    = mult * atr

upperBand     = getDema(high + bandOffset, lenMas)
lowerBand     = getDema(low - bandOffset, lenMas)

prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])

lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand

avPlot = plot((lowerBand + upperBand)/2, title='Mid Band', linewidth=1, color=color.orange)
upPlot = plot(upperBand, title='Up Band', linewidth=1, color=color.green)
lowPlot = plot(lowerBand, title='Low Band', linewidth=1, color=color.red)

fill(upPlot, avPlot, color.new(color.green, 90), 'Upper Area')
fill(avPlot,lowPlot, color.new(color.red, 90), 'Lower Area')

