// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("EhlersDistCoefFilter");

//EhlersDistCoefFilter
//Taken from the article in TASC's April 2001 Issue.

Price = (H+L)/2;
CoefLookback = 5;

Coef = (Price-Ref(Price, -1))^2+(Price-Ref(Price, -2))^2+(Price-Ref(Price, -3))^2+(Price-Ref(Price, -4))^2+(Price-Ref(Price, -5))^2;

SumCoef=0;
SumCoefPrice=0;
for(i=0; i < CoefLookback; i++) {
	SumCoef = SumCoef + Ref(Coef, -i);
	SumCoefPrice = SumCoefPrice + (Ref(Coef, -i) * Ref(Price, -i));
}
DCEF = SumCoefPrice / SumCoef;

Plot(Close, "Close", colorWhite, styleLine);
Plot(DCEF, "NonLinear Ehlers Filter", IIf(Close>DCEF, colorGreen, colorRed), styleLine);
_SECTION_END();