Adaptive Trend Indicator [Quantigenics]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Quantigenics

//@version=5

indicator("Adaptive Trend ",overlay = true)
AdapTrendLength = input.int(defval = 5,title = "Adaptive Trend Length")
UpColor         = input.color(defval = color.aqua,title = "Up Color")
DownColor         = input.color(defval = color.red,title = "Down Color")

Avg = ta.ema(ohlc4, AdapTrendLength)
MedAvg =ta.ema(high-(high-low)/2,3)
Adcalc = (MedAvg+(ta.ema(ta.ema(Avg, AdapTrendLength), AdapTrendLength)+Avg))/3

AdapTrend = ta.linreg( Adcalc, AdapTrendLength*2, 0 ) 

var linecolor = color.aqua

if AdapTrend > AdapTrend[1] 
    linecolor := UpColor
else if AdapTrend < AdapTrend[1] 
    linecolor := DownColor

plot(AdapTrend,title = "Adaptive Trend",color = linecolor[1])

