Trend Identifier
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © spacekadet17
//@version=5

indicator(title="Trend Identifier", shorttitle="Trend Identifier", format=format.price, precision=4, overlay = false)

// indicators: price normalized alma, its 1st and 2nd derivatives
timeInterval = input(140)
smoothining = input(21)
ema = ta.alma(close,timeInterval,1.1,6)
dema = (ema-ema[1])/ema
d2ema = ta.ema(dema-dema[1],smoothining)

//plot graph
green = color.rgb(20,255,100)
yellow = color.yellow
red = color.red
blue = color.rgb(20,120,255)
tcolor = (dema>0) and (d2ema>0)? green : (dema>0) and (d2ema<0) ? yellow : (dema < 0) and (d2ema<0) ? red : (dema < 0) and (d2ema>0) ? blue : color.black
demaema = ta.ema(dema,smoothining)
plot(demaema, color = tcolor)
