rumpypumpydumpy

Median Absolute Deviation Filtered SMA & BB

Median Absolute Deviation (MAD) is a robust measurement of variability and more resilient against outliers and small samples.

This experiment uses MAD as a means of filtering outliers from an SMA calculation. First we construct the equivalent of a Bollinger Band, but based on the median as the basis and a multiple(k) of MAD as the outlier cutoff.

k can be set a number of ways. As a simple multiple (3 - very conservative / 2.5 - moderately conservative / 2 - poorly conservative). Alternatively MAD can be used as an estimator of standard deviation by using a multiple of 1.4826 (SD1 - 1.4826 / SD2 - 2.9652 / SD3 - 4.4478).

Once we have a cutoff range an SMA is calculated with the outliers filtered out. Additionally a Bollinger band can be output using the filtered SMA as the basis and a multiple of the MAD instead of SD for the bands.



Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?