OPEN-SOURCE SCRIPT

Average True Range Trailing Mean [Alifer]

Upgrade of the Average True Range default indicator by TradingView. It adds and plots a trailing mean to show periods of increased volatility more clearly.


ATR TRAILING MEAN
A trailing mean, also known as a moving average, is a statistical calculation used to smooth out data over time and identify trends or patterns in a time series.
In our indicator, it clearly shows when the ATR value spikes outside of it's average range, making it easier to identify periods of increased volatility.

Here's how the ATR Trailing Mean (atr_mean) is calculated:


  • The ta.cum() function calculates the cumulative sum of the ATR over all bars up to the current bar.
  • (bar_index + 1) represents the number of bars processed up to the current bar, including the current one.
  • By dividing the cumulative ATR ta.cum(atr) by (bar_index + 1) and then multiplying it by atr_mult (Multiplier), we obtain the ATR Trailing Mean value.

If atr_mult is set to 1.0, the ATR Trailing Mean will be equal to the simple average of the ATR values, and it will follow the ATR's general trend.
However, if atr_mult is increased, the ATR Trailing Mean will react more strongly to the ATR's recent changes, making it more sensitive to short-term fluctuations.
On the other hand, reducing atr_mult will make the ATR Trailing Mean less responsive to recent changes in ATR, making it smoother and less prone to reacting to short-term volatility.

In summary, adjusting the atr_mult input allows traders to fine-tune the ATR Trailing Mean's responsiveness based on their preferred level of sensitivity to recent changes in market volatility.


IMPLEMENTATION IN A STRATEGY
You can easily implement this indicator in an existing strategy, to only enter positions when the ATR is above the ATR Trailing Mean (with Multiplier-adjusted sensitivity). To do so, add the following lines of codes.

Under Inputs:

This will allow you to define the Length of the ATR (lookback length over which the ATR is calculated), the Multiplier to adjust the Trailing Mean's sensitivity and the type of Smoothing to be used for the ATR.

Under Calculations:

This will calculate the ATR based on Length and Smoothing, and the resulting ATR Trailing Mean.

Under Entry Conditions, add the following to your existing conditions:

This will make it so that entries are only triggered when the ATR is above the ATR Trailing Mean (adjusted by the Multiplier value you defined earlier).


ATR - DEFINITION AND HISTORY
The Average True Range (ATR) is a technical indicator used to measure market volatility, regardless of the direction of the price. It was developed by J. Welles Wilder and introduced in his book "New Concepts in Technical Trading Systems" in 1978. ATR provides valuable insights into the degree of price movement or volatility experienced by a financial asset, such as a stock, currency pair, commodity, or cryptocurrency, over a specific period.


ATR - CALCULATION AND USAGE
The ATR calculation involves three components:

1 — True Range (TR): The True Range is a measure of the asset's price movement for a given period. It takes into account the following factors:
  • The difference between the high and low prices of the current period.
  • The absolute value of the difference between the high price of the current period and the closing price of the previous period.
  • The absolute value of the difference between the low price of the current period and the closing price of the previous period.

Mathematically, the True Range (TR) for the current period is calculated as follows:


2 — ATR Calculation: The ATR is calculated as a Moving Average (MA) of the True Range over a specified period.

The ATR is calculated as follows:


3 — ATR Interpretation: The ATR value represents the average volatility of the asset over the chosen period. Higher ATR values indicate higher volatility, while lower ATR values suggest lower volatility.

Traders and investors can use ATR in various ways:
  • Setting Stop Loss and Take Profit Levels: ATR can help determine appropriate stop-loss and take-profit levels in trading strategies. A larger ATR value might require wider stop-loss levels to allow for the asset's natural price fluctuations, while a smaller ATR value might allow for tighter stop-loss levels.
  • Identifying Market Volatility: A sharp increase in ATR might indicate heightened market uncertainty or the potential for significant price movements. Conversely, a decreasing ATR might suggest a period of low volatility and possible consolidation.
  • Comparing Volatility Between Assets: Since ATR uses absolute values, it shouldn't be used to compare volatility between different assets, as assets with higher prices will consistently have higher ATR values, while assets with lower prices will consistently have lower ATR values. However, the addition of a trailing mean makes such a comparison possible. An asset whose ATR is consistently close to its ATR Trailing Mean will have a lower volatility than an asset whose ATR continuously moves far above and below its ATR Trailing Mean. This can help traders and investors decide which markets to trade based on their risk tolerance and trading strategies.
  • Determining Position Size: ATR can be used to adjust position sizes, taking into account the asset's volatility. Smaller position sizes might be appropriate for more volatile assets to manage risk effectively.
aliferATRatrtmaverageAverage True Range (ATR)meanrangeTMtrailingTRUE

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?


또한 다음에서도:

면책사항