Median Average Adaptive Filter for Amibroker (AFL)
kaiji over 16 years ago Amibroker (AFL)
This indicator is by John Ehler and is an adaptive moving average that adjusts the smoothing parameter depending on the percentage difference between the outputs of the same-length medial and exponential moving average.
Indicator / Formula
Copy & Paste Friendly
Price = ( H + L ) /2;
Threshold = 0.002;
Smooth = (Price + 2 * Ref( Price, -1 ) + 2 * Ref( Price, -2 ) + Ref(Price, -3 ) )/6;
Length = 39;
Value3 = 0.2;
AvgLength = 39;
for( Length = 39; Length >= 3; Length = Length - 2 )
{
alpha = 2 / ( Length + 1 );
Value1 = Median( Smooth, Length );
Value2 = AMA( Smooth, alpha );
Value3 = Nz( abs( Value1 - Value2 )/Value1 );
AvgLength = IIf( Value3 > Threshold, Length, AvgLength );
}
alpha = 2 / (AvgLength + 1);
Filt = AMA( Smooth, alpha );
Plot( C, "Price", colorBlack, styleCandle );
Plot( Filt, "Filt", colorRed );0 comments
Leave Comment
Please login here to leave a comment.