Volatility Indicators

ATR Indicator: Volatility, Stop Loss, and Position Sizing | AlfaTactix

📖 4 min read

📝 756 words

🏷️ Volatility Indicators

In this page: what ATR is, how it works, when to use it, a practical example with code, and a bonus tip.

Use ATR in a real strategy—no code required

Create a free account to save your progress and build strategies with this indicator and 80+ others in minutes. Backtest, then export to MQL5.


ATR on a price chart: illustration of the indicator and how it is used in technical analysis
ATR – chart illustration

ATR (Average True Range) Indicator Explanation

The Average True Range (ATR) is a popular technical indicator used to measure market volatility. Introduced by J. Welles Wilder Jr. in his 1978 book "New Concepts in Technical Trading Systems," ATR calculates the average range between the high and low prices of an asset over a specified period, incorporating any gaps between trading sessions. Unlike trend indicators, ATR does not indicate price direction but instead focuses solely on the degree of price movement.

How ATR Works: ATR is calculated by first determining the "True Range" (TR) for each period, which is the greatest of:

  • Current high minus current low
  • Absolute value of current high minus previous close
  • Absolute value of current low minus previous close

The ATR is then the moving average of these True Range values over a user-defined period, commonly 14 periods. This calculation method accounts for price gaps between trading sessions, making ATR particularly useful for measuring volatility across different market conditions.

When to Use ATR:

  • Volatility Assessment: Traders use ATR to gauge market volatility, helping adjust position sizes or stop-loss levels based on current market conditions.
  • Setting Stop-Losses: ATR helps place dynamic stop-loss orders that adapt to market conditions, avoiding stops that are too tight or too loose relative to actual price movement.
  • Risk Management: ATR can be used to identify periods of high or low volatility, allowing traders to adjust their risk exposure accordingly.

Advantages:

  • Provides a clear measure of market volatility regardless of trend direction, making it applicable in both trending and ranging markets.
  • Useful in various markets—stocks, forex, commodities, and cryptocurrencies—as volatility measurement is universal.
  • Helps improve risk management by adjusting stops and position sizing based on actual market volatility rather than fixed percentages.

Limitations:

  • ATR does not indicate market direction or trend strength, only the magnitude of price movement.
  • High ATR values indicate volatility but not whether prices will move up or down, requiring combination with directional indicators.
  • Should be combined with trend or momentum indicators for more effective trading decisions, as ATR alone does not provide entry or exit signals.

In summary, ATR is an essential indicator for traders focused on managing risk and understanding market volatility, making it a valuable tool in any trading strategy. For further reading, refer to Wilder's original work "New Concepts in Technical Trading Systems" (1978), Investopedia's ATR guide, TradingView's ATR documentation, and academic research on volatility measurement in financial markets such as studies published in the Journal of Financial Markets and Quantitative Finance journals.

Practical Example: Using the ATR Indicator in a Trading Strategy

The Average True Range (ATR) is a volatility indicator used to measure how much an asset typically moves over a given period. In a trading strategy, the ATR indicator helps identify high or low volatility conditions and adjust position entries, exits, or sizing accordingly.

Scenario: You're creating a breakout strategy for Ethereum (ETH/USDT) on a 15-minute chart. You want to take trades only when volatility is high enough to support a meaningful price move.

Strategy Logic:

  • Calculate the ATR(14) to measure recent volatility.
  • Enter a long or short position only when the ATR is above a predefined threshold, such as the 20-period average ATR. This signals strong price movement potential.
  • If ATR is low, avoid trading to reduce the risk of entering during sideways, range-bound markets.

Backtrader Example:

import backtrader as bt

class ATRBreakoutStrategy(bt.Strategy):
    params = dict(
        atr_period=14,
        atr_threshold_multiplier=1.0
    )
    
    def __init__(self):
        self.atr = bt.ind.ATR(period=self.p.atr_period)
        self.atr_sma = bt.ind.SMA(self.atr, period=20)
        
    def next(self):
        if not self.position:
            # Enter only when ATR is above threshold
            if self.atr[0] > self.atr_sma[0] * self.p.atr_threshold_multiplier:
                if self._breakout_detected():
                    self.buy()
        else:
            # Exit logic
            if self._exit_condition():
                self.sell()
    
    def _breakout_detected(self):
        # Add breakout detection logic
        return True
    
    def _exit_condition(self):
        # Add exit condition logic
        return False

# Usage
cerebro = bt.Cerebro()
cerebro.addstrategy(ATRBreakoutStrategy)

Expected Outcome: By using the ATR indicator, your strategy avoids entering trades when the market lacks momentum, helping you sidestep false breakouts or whipsaws. This leads to better risk-adjusted entries, more precise stop-loss placement, and improved profit potential in volatile environments.

💡 Bonus Tip

You can also use ATR to dynamically calculate stop-loss levels. For example, set your stop-loss at 1.5× ATR below the entry price to account for natural market fluctuations, as recommended in Wilder's original methodology. This approach is widely documented in risk management literature and trading strategy research.

Using the ATR indicator ensures your strategy aligns with active market conditions, improving consistency and performance over time.

Use ATR in a real strategy—no code required

Create a free account to save your progress and build strategies with this indicator and 80+ others in minutes. Backtest, then export to MQL5.

Try Strategy Builder

Use this indicator in Strategy Builder — free

Create free account