Learning

Average True Range – ATR

Simão Ferreira

In this article, we’ll explain why the Average True Range (ATR) indicator is important, and how to properly use it in algorithmic trading.

Table of contents

  1. What is ATR?
  2. How is ATR calculated?
  3. Common uses
  4. An example strategy using ATR on Tuned
  5. Conclusion

What is the Average True Range (ATR)?

ATR was developed by J. Welles Wilder in the 1970s as a technical indicator that measures the volatility of an asset. This lets traders classify market conditions and/or define stop losses. A good example of using ATR as stop-loss is trend following trading.

It’s important to understand that ATR only measures volatility and doesn’t indicate price direction. It takes an average selection of true ranges over a specific period in time. The true range of an asset can be defined by the greatest absolute value of one of the following:

  • |Current High – Current Low|
  • |Current High – Previous Close|
  • |Current Low – Previous Close|

These true range values are then smoothed over a certain period of time, the most common being 14 periods. With this, traders can use ATR as a filter to classify market conditions or to help These true range values are then smoothed over a certain period of time, the most common being 14 periods. With this, traders can use ATR as a filter to classify market conditions or to help define stop losses.


How is ATR calculated?

To calculate ATR we first need to have a period of which the True Range will be smoothed. We will define this period as “n”, which is usually 14.

The formula is defined as:

Current ATR = ((Prior ATR * (n-1) + Current TR)) /14

We are multiplying the previous ATR by 13 (n-1), adding the most recent True Range, and dividing the total by 14. The table below should help your understanding.

ATR Calculation

Common uses

As we’ve mentioned, there are 2 main use cases for ATR:

  • Volatility Filter
  • Defining Stop Losses

Using ATR as a Volatility Filter

Most trading systems work best when markets are volatile. This way, ATR can be used to filter conditions. It’s also possible to use ATR as a trend predictor. As we can see in the example below: when the average true range drops and stays low, it can indicate that a new trend will soon form.

ATR as Volatility Filter

Oscillator indicators are typically better suited to algorithmic trading and multiple asset strategies. ATR is not ideal to use as a filter on algorithmic trading because it’s not range-bounded or calculated in a relative way. A different approach is to use a % calculation of the ATR to have a relative calculation to become more user-friendly to automated strategies. This way the ATR displays the volatility as a percentage of the asset and not a fixed number.

Using ATR to define Stop Losses

Another way to use ATR is to define a stop loss. Let’s say an asset has an average true range of 5. When we enter a trade with this volatility in mind we can place the stop loss “x” times the ATR. Meaning that if the price moves more than the average against our trade we can automatically exit our position. This is a common use-case of the ATR indicator for algorithmic trading.


An example strategy using %ATR on Tuned

A simple example is to avoid trades when the volatility is low (red) and look for trades when the volatility is high (green).

% ATR

Tuned Code is as follows:

//@Tuned 2022 ATR Volatility Filter
        
//Atr Length
  n = intInput("Length",14)
        
//% TR Calculation
  TR = trueRange(high, low, close)/close *100

//% ATR Calculation
  ATR = sma(TR, n)
        
plot(ATR, "ATR%", "#1BC0EB", 1, PlotStyle.LINE, 0, false)
 
//Signal Push
  out(NEVER_ORDER)

Pine Alpha

//Welcome to Tuned!
//Within this editor you will be able to create your strategy
//If you have any questions please ask in Discord
//or review Documentation at https://www.tuned.com/docs/#/
 
//@version=4
//Tuned supports Pine Version 4 Only
strategy(title="% ATR Snippet", overlay = false)
 
//Inputs
  c = close
  n = 14
 
//Calculations
  true_range() =>
    max(high - low, max(abs(high - c[1]), abs(low - c[1])))
  atr = sma(true_range(), n)
 
//Plot
  plot(atr, title = "ATR%", #004BEC, 2)

Conclusion

Most often the ATR indicator is used in algorithmic trading to define stop losses, which works well in strategies requiring a strict set of rules. For example, the turtle trading experiment, where exits were defined as 2 times the stop loss plus the ATR at the moment of the trade. If the price were to move far in the opposite direction, we’d consider the trade invalid and close the position. 

Another approach for ATR is as a volatility filter with the modified version explained in the article. In this case, high values indicate volatility and continued low values suggest a new trend will form. 

There you have it! Two separate uses for one indicator. We hope you will walk away with a better understanding of ATR and with the encouragement to try experimenting with other indicators.

Happy Trading!

Tags:

Disclaimer: The opinions expressed here are for general informational purposes only and are not intended to provide specific advice or recommendations for any specific security or investment product. You should never invest money that you cannot afford to lose. Before trading using complex financial products, please ensure to understand the risks involved. Past performance is no guarantee of future results.

All investing involves risk, including the possible loss of all the money you invest, and past performance does not guarantee future performance. Historical returns expected returns, and probability projections are provided for informational and illustrative purposes, and may not reflect actual future performance.

Tuned is not a broker-dealer, exchange, custodian, wallet provider, or counterparty. Investing is highly speculative and volatile. Tuned is only suitable for investors who fully understand the risk of loss and may experience large drawdowns. Investors should never invest more than they can afford to lose.