Slope of KAMA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Aanyka

//@version=5


////////////////////////////////////////////////////////////
indicator(title='Slope of KAMA', shorttitle='Slope of KAMA', format=format.price, precision=2, timeframe='')
Length = input.int(21, minval=1)
xPrice = close
xvnoise = math.abs(xPrice - xPrice[1])
nAMA = 0.0
nfastend = 0.666
nslowend = 0.0645
nsignal = math.abs(xPrice - xPrice[Length])
nnoise = math.sum(xvnoise, Length)
nefratio = nnoise != 0 ? nsignal / nnoise : 0
nsmooth = math.pow(nefratio * (nfastend - nslowend) + nslowend, 2)
nAMA := nz(nAMA[1]) + nsmooth * (xPrice - nz(nAMA[1]))
nAMA2 = nAMA[1] - nAMA[2]
plot(nAMA2, color=color.new(color.blue, 0), title='Slope of KAMA', style=plot.style_columns)
