## Median Average Adaptive Filter

The Median Average Adaptive Filter (MAAF) was authored by John Ehlers. The MAAF requires the current price and three previous prices, some averaging, some while loop for an alpha calculation and then a final feedback to fill its calculation. The user may change the input (midpoint) and a threshold value. This indicator’s definition is further expressed in the condensed code given in the calculation below.

See also article by John Ehlers ### How To Trade Using the Median Average Adaptive Filter

The Median Average Adaptive Filter is a trend indicator and may be used in conjunction with other studies. No trading signals are calculated.

### How To Access in MotiveWave

Go to the top menu, choose Study>John Ehlers>Median Average Adaptive Filter

or go to the top menu, choose Add Study, start typing in this study name until you see it appear in the list, click on the study name, click OK.

Important Disclaimer: The information provided on this page is strictly for informational purposes and is not to be construed as advice or solicitation to buy or sell any security. Please see our Risk Disclosure and Performance Disclaimer Statement.

### Calculation

//input = price, user defined, default is midpoint
//th = threshold = user defined, default is .002
//median = function, returns price at middle of period
//prev = previous, index = current bar number

```len = 39;
prevP1 = price[index-1];
prevP2 = price[index-2];
prevP3 = price[index-3];
smth = (price + 2*prevP1 + 2*prevP2 + prevP3) / 6;
value3 = .2;
prevV2 = value2[index-1];
while (value3 moreThan th AND len moreThan 0)
alpha = 2 / (len + 1);
value1 =  median(len, smth);
value2 = alpha * smth + (1 - alpha) * prevV2;
if (value1 != 0) value3 = Math.abs(value1 - value2) / value1;
len = len - 2;
endWhile
if (len lessThan 3) len = 3;
alpha = 2 / (len +1);
prevF = filt[index-1];
Plot: filt = alpha*smth + (1 - alpha) * prevF;```