IndicatorRe: Volatility Indicators for MT4

69
Percentile Filtered ATR

Since its introduction in 1978 by J. Welles Wilder, Average True Range (ATR) has been one of the popular ways for traders to measure volatility in the market (or the “bounciness” of price movement). The indicator is commonly used for position sizing as well as establishing profit targets or stop-loss orders. It is also a component in several indicators that employed volatility in the calculation, e.g. Chandelier Exit, Damiani Volatmeter, Angle of Average & Volatility Quality.

One major downside of the ATR is that it is very susceptible to outliers i.e. large increase/decrease in true range value that only occurred in a short amount of time. This is most apparent in MT4 built-in ATR which used simple moving average in the calculation, shown in the figure below. The red line is the built-in ATR indicator with a period of 42. It can be observed that sudden spikes in the range value is followed by a huge and abrupt increase in the value of the ATR. Even though the price movement was relatively calm for a significant amount of time after the huge spikes, the ATR clearly does not reflect this. The increase in ATR value persisted for 42 candles as the huge spike in value get carried over to future -- an inherent property of averaging data ordered in time series.


My own variant of the ATR, termed Percentile Filtered ATR, attempt to resolve this issue by arranging the true range values within the specified lookback period in ascending order, then either discard the true range values near the extrema or giving less weightage to those values during the averaging process. The result is shown in the figure above (blue line). Compared with the usual ATR, the Percentile Filtered ATR can be adjusted to be much more presentative of the overall “bounciness” of price movement.

The amount of data that need to be discarded / given less weightage can be varied by changing the value of Lower Cutoff Percentile and Upper Cutoff Percentile. For example, setting 20 for Lower Cutoff Percentile and 70 for Upper Cutoff Percentile means that approximately 20% of data at the lower end and 30% of data (100% -70% = 30%) at the upper end will be discarded / given less weightage during averaging. There are three types of filter mode that come with this indicator:

1. Simple Cutoff – All true range values beyond the Lower Cutoff Percentile and Upper Cutoff Percentile are ignored in the averaging process. If value lower & upper cutoff values are set to be the same, then it is very similar to picking a value using the nearest-rank method. Note: setting the lower cutoff to 0 and upper cutoff to 100 does not result in the default ATR, rather a modified ATR that ignore the smallest and largest true range values within the specified lookback period.

2. Weighted Cutoff (Normal) – True range values beyond the specified cutoff range are not discarded as in the Simple Cutoff mode, but weighted according to its percentile rank. The values closer to the extrema are given the less weight, while the values near the value with the specified cutoff percentile are given the most weight.

3. Weighted Cutoff (Stronger) – Similar to Weighted Cutoff (Normal), except that the smallest & largest TR values are given zero weightage i.e. ignored.

In Weighted Cutoff mode (Normal or Stronger), the variation in the weightage can be adjusted by changing the PF Weight value. Value of 1.0 results in linear weightage (as in linear-weighted moving average). The PF Weight is not limited to integers, and you can input number such as 0.5 or 1.7. Higher value results in less weightage given to true range values closer to the extrema. Note: setting it to zero basically while in Weighted Cutoff mode turns the indi into simple ATR.

I also included an option in the indicator named as the TR Weight. Its purpose is to adjust the weightage given to the close/open price in the current candle and high/low in the previous candle when calculating the true range value. Higher value = higher weightage. Setting it to zero results in the original true range calculation.

**Note: The indicator itself only produced one line, as shown in the figure below. The extra ATR line in the previous figure was added for comparison purpose only


These users thanked the author khtauon for the post (total 3):
RodrigoRT7, PanicTrader, yoake

Re: Volatility Indicators for MT4

70
khtauon wrote: Thu Jan 14, 2021 5:52 pm Percentile Filtered ATR

Since its introduction in 1978 by J. Welles Wilder, Average True Range (ATR) has been one of the popular ways for traders to measure volatility in the market (or the “bounciness” of price movement). The indicator is commonly used for position sizing as well as establishing profit targets or stop-loss orders. It is also a component in several indicators that employed volatility in the calculation, e.g. Chandelier Exit, Damiani Volatmeter, Angle of Average & Volatility Quality.

One major downside of the ATR is that it is very susceptible to outliers i.e. large increase/decrease in true range value that only occurred in a short amount of time. This is most apparent in MT4 built-in ATR which used simple moving average in the calculation, shown in the figure below. The red line is the built-in ATR indicator with a period of 42. It can be observed that sudden spikes in the range value is followed by a huge and abrupt increase in the value of the ATR. Even though the price movement was relatively calm for a significant amount of time after the huge spikes, the ATR clearly does not reflect this. The increase in ATR value persisted for 42 candles as the huge spike in value get carried over to future -- an inherent property of averaging data ordered in time series.


PFATR1.jpg


My own variant of the ATR, termed Percentile Filtered ATR, attempt to resolve this issue by arranging the true range values within the specified lookback period in ascending order, then either discard the true range values near the extrema or giving less weightage to those values during the averaging process. The result is shown in the figure above (blue line). Compared with the usual ATR, the Percentile Filtered ATR can be adjusted to be much more presentative of the overall “bounciness” of price movement.

The amount of data that need to be discarded / given less weightage can be varied by changing the value of Lower Cutoff Percentile and Upper Cutoff Percentile. For example, setting 20 for Lower Cutoff Percentile and 70 for Upper Cutoff Percentile means that approximately 20% of data at the lower end and 30% of data (100% -70% = 30%) at the upper end will be discarded / given less weightage during averaging. There are three types of filter mode that come with this indicator:

1. Simple Cutoff – All true range values beyond the Lower Cutoff Percentile and Upper Cutoff Percentile are ignored in the averaging process. If value lower & upper cutoff values are set to be the same, then it is very similar to picking a value using the nearest-rank method. Note: setting the lower cutoff to 0 and upper cutoff to 100 does not result in the default ATR, rather a modified ATR that ignore the smallest and largest true range values within the specified lookback period.

2. Weighted Cutoff (Normal) – True range values beyond the specified cutoff range are not discarded as in the Simple Cutoff mode, but weighted according to its percentile rank. The values closer to the extrema are given the less weight, while the values near the value with the specified cutoff percentile are given the most weight.

3. Weighted Cutoff (Stronger) – Similar to Weighted Cutoff (Normal), except that the smallest & largest TR values are given zero weightage i.e. ignored.

In Weighted Cutoff mode (Normal or Stronger), the variation in the weightage can be adjusted by changing the PF Weight value. Value of 1.0 results in linear weightage (as in linear-weighted moving average). The PF Weight is not limited to integers, and you can input number such as 0.5 or 1.7. Higher value results in less weightage given to true range values closer to the extrema. Note: setting it to zero basically while in Weighted Cutoff mode turns the indi into simple ATR.

I also included an option in the indicator named as the TR Weight. Its purpose is to adjust the weightage given to the close/open price in the current candle and high/low in the previous candle when calculating the true range value. Higher value = higher weightage. Setting it to zero results in the original true range calculation.

**Note: The indicator itself only produced one line, as shown in the figure below. The extra ATR line in the previous figure was added for comparison purpose only


PFATR5.jpg



Percentile_Filtered_ATR.mq4
Definitely an interesting concept, thank you for sharing. Have you considered adding an option to express current ATR as an % of the N-period average?


Who is online

Users browsing this forum: Amazon [Bot], Banzai, GetThere, Majestic-12 [Bot], SEMrush [Bot], snoopyzam, specialkey, Steam1, stond and 78 guests