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

Script open-source

In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.

Vuoi usare questo script sui tuoi grafici?


Anche su:

Declinazione di responsabilità