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:
atr_mean = ta.cum(atr) / (bar_index + 1) * atr_mult
- 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.
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.
length = input.int(title="Length", defval=20, minval=1) atr_mult = input.float(defval=1.0, step = 0.1, title = "Multiplier", tooltip = "Adjust the sensitivity of the ATR Trailing Mean line.") smoothing = input.string(title="Smoothing", defval="RMA", options=["RMA", "SMA", "EMA", "WMA"]) ma_function(source, length) => switch smoothing "RMA" => ta.rma(source, length) "SMA" => ta.sma(source, length) "EMA" => ta.ema(source, length) => ta.wma(source, length)
atr= ma_function(ta.tr(true), length) atr_mean = ta.cum(atr) / (bar_index+1) * atr_mult
Under Entry Conditions, add the following to your existing conditions:
and atr > atr_mean
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.
TR = max(high - low, abs(high - previous_close), abs(low - previous_close))
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:
ATR = MA(TR, length)
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.
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.