Technical Indicators

ATR (Average True Range): How to Use Volatility in Trading Bots

Average True Range measures volatility, not direction. How ATR is calculated, how to read it, and how bots use it for stops, targets, position size, grid spacing and filters.

By AlgoXP3 min readUpdated

Price inside an ATR-based channel that widens and narrows with volatility

The Average True Range (ATR) is one of the most useful indicators for automated trading, even though it never tells you whether to buy or sell. It measures how much a market typically moves over a period. That makes it the natural unit for stops, targets, position sizes and grid spacing - the parts of a strategy that decide how much you risk.

How ATR is calculated

ATR was introduced by J. Welles Wilder in 1978. It starts from the true range of each bar, the largest of:

  1. current high − current low;
  2. |current high − previous close|;
  3. |current low − previous close|.

The second and third terms capture gaps: if a market closes at 100 and opens at 104, the move counts as volatility even though the new bar’s own range may be small.

ATR is a smoothed average of true range, classically over 14 periods using Wilder’s smoothing:

ATR = (previous ATR × (n − 1) + current TR) / n

ATR is expressed in price units: on EURUSD H1 it might be 0.0012 (12 pips); on gold H1, perhaps 8 dollars.

How to read it

  • High ATR - large bars, fast markets, wide swings.
  • Low ATR - quiet markets, compression, often before breakouts.
  • ATR relative to its own history - more useful than the absolute number. Today’s ATR at the 90th percentile of the last year means unusually volatile conditions.

ATR says nothing about direction. A crash and a rally can produce the same ATR.

How trading bots use ATR

1. Stop losses

A stop at k × ATR from entry sits outside normal noise. Typical multiples: 1-1.5 for short-term systems, 2-3 for trend following. The stop widens in volatile markets and tightens in calm ones automatically.

2. Take profits

Targets at a multiple of ATR (for example 2-3 × ATR) keep risk/reward proportional to conditions.

3. Position sizing

With a fixed risk per trade, ATR decides the size:

Position size = (Equity × risk %) / (stop distance in price × value per point)

If the stop is 1.5 × ATR and ATR doubles, the position halves - the money at risk stays the same. See position sizing methods.

4. Trailing stops

An ATR trailing stop follows price at a distance of k × ATR from the highest high (for longs). The Chandelier Exit is a well-known version. See trailing stop strategies.

5. Grid spacing and entry offsets

Grid robots that space levels in ATR units adapt to volatility instead of becoming dangerously tight when markets accelerate. AlgoXP’s Maya Gold Grid ATR is built on exactly this idea for gold.

6. Volatility filters

  • Skip breakouts when the range is already wider than k × ATR (the move may be exhausted).
  • Skip trading when ATR is extremely low (no movement to pay for costs) or extremely high (news shock).

A worked example

Gold on H1, ATR(14) = 8.0 dollars. A bot risks 0.5% of a 20,000 account and uses a 1.5 × ATR stop:

  • Stop distance: 12.0 dollars.
  • Money at risk: 100.
  • With a contract value of 1 dollar per 0.01 lot per 1-dollar move (check your broker’s specification), size ≈ 100 / (12 × 1) × 0.01 ≈ 0.08 lots.

If ATR rises to 16, the stop becomes 24 dollars and size falls to about 0.04 lots. Risk is still 100.

Pitfalls

  • Wrong timeframe. ATR on M1 used for a stop on H4 trades will be far too small.
  • Spikes. One huge bar inflates ATR for a while; some traders use a median of true range or cap single bars.
  • Session effects. ATR mixes quiet Asian hours with busy London hours; session-specific systems may need session-specific volatility.
  • Over-tuning multiples. Choose multiples from a stable range, not the single best backtest value. See parameter stability.

Key takeaways

  • ATR measures typical movement, including gaps, in price units.
  • It is the natural unit for stops, targets, sizing, trailing and grid spacing.
  • Read ATR relative to its own history, and match its timeframe to your trades.
  • Volatility-scaled rules travel better across markets and years than fixed distances.

FAQ

Does a rising ATR mean price will go up?

No. ATR measures how much price moves, not where. It rises in strong rallies and in sharp sell-offs alike.

What ATR period should I use?

14 periods is the classic default from J. Welles Wilder. Shorter periods react faster to volatility changes; longer ones are steadier. For stops and sizing, 14-20 on the trading timeframe is a sensible start.

Why use ATR instead of a fixed stop in points?

Because a fixed distance is too tight in volatile markets and too wide in quiet ones. ATR-based distances scale with current conditions and transfer between instruments.

Sources and further reading

  1. StockCharts ChartSchool: Average True Range (ATR) - chartschool.stockcharts.com
  2. StockCharts ChartSchool: ATR Trailing Stops - chartschool.stockcharts.com