What Is Average True Range (ATR)?
Developed by J. Welles Wilder in 1978, the Average True Range (ATR) is a technical analysis indicator that measures market volatility by calculating the moving average of true price ranges over a specified period (typically 14 days). Originally designed for stock markets, ATR now serves as a versatile tool across financial instruments, helping traders:
- Allocate capital efficiently
- Set dynamic stop-loss levels
- Adjust position sizes strategically
Wilder described ATR as "a truly robust workhorse among technical indicators" due to its ability to adapt to different asset volatilities.
Practical Applications of ATR
1. Intelligent Capital Allocation
Problem: Standard equal allocation ignores varying volatility between assets.
Solution: Use ATR to balance risk exposure across positions.
👉 Master volatility-based position sizing
Example Calculation:
For a $1M portfolio with SHFE.au1912 (ATR=6.6) and DCE.i2001 (ATR=27.3):
| Contract | ATR Value | Calculation | Position Size |
|---|---|---|---|
| SHFE.au1912 | 6.6 | 10,000 ÷ (6.6 × 1,000) | 1.52 → 1 lot |
| DCE.i2001 | 27.3 | 10,000 ÷ (27.3 × 100) | 3.66 → 3 lots |
This ensures each asset's normal fluctuations equally impact the portfolio.
2. Dynamic Stop-Loss Adjustment
Fixed Percentage Limitations:
An 8% stop-loss might be too tight for volatile assets or too loose for stable ones.
ATR Solution:
For SHFE.au1912 long position at 352.5:
- Entry: 352.5
- Add Trigger: 352.5 + (0.5 × 6.6) = 355.8
- Stop-Loss: 352.5 - (2 × 6.6) = 339.3
if position.pos_long > 0:
if current_price >= entry_price + 0.5*ATR:
increase_position()
elif current_price <= entry_price - 2*ATR:
exit_position()3. Adaptive Position Sizing
When DCE.i2001's ATR drops from 27.3 to 20:
- New Position: 10,000 ÷ (20 × 100) = 5 lots
- Adjustment: Add 2 lots (from 3 to 5)
Calculating ATR: The Technical Process
Key Formulas:
- True Range (TR):
TR = MAX(|High-Low|, |High-PrevClose|, |PrevClose-Low|) - ATR Calculation:
ATR = Simple Moving Average(TR, 14 periods)
Python Implementation:
from tqsdk.ta import ATR
klines = api.get_kline_serial("SHFE.au1912", 86400)
atr_data = ATR(klines, 14)
print(f"TR: {atr_data.tr[-1]}, ATR: {atr_data.atr[-1]}")Trading Strategy Integration
Tianqin Quant Platform Implementation:
#!/usr/bin/env python
from tqsdk import TqApi, TargetPosTask
from tqsdk.ta import ATR
SYMBOL = "SHFE.au1912"
api = TqApi()
n = ATR(api.get_kline_serial(SYMBOL, 86400, 100), 20)["atr"].iloc[-1]
while True:
api.wait_update()
if position.pos_long > 0:
if price >= entry + 0.5*n:
adjust_position(2) # Scale in
elif price <= entry - 2*n:
exit_position() # Stop-loss👉 Optimize your ATR strategy today
FAQ Section
Q1: Why use 14 periods for ATR calculation?
A: Wilder's original testing showed 14 periods optimally balances responsiveness with noise reduction. Traders may adjust based on their timeframe.
Q2: Can ATR predict price direction?
A: No. ATR measures volatility magnitude only, not direction. Combine with trend indicators for complete analysis.
Q3: How does ATR compare to standard deviation?
A: Both measure volatility, but ATR accounts for gaps between sessions, making it preferable for discontinuous markets like futures.
Q4: What's the ideal ATR percentage for stop-losses?
A: There's no universal value. Backtest with historical data to determine optimal multiples (typically 1.5-3×ATR) for your asset.
Q5: Can ATR be used for crypto trading?
A: Absolutely. Cryptocurrencies' high volatility makes ATR particularly valuable for position sizing and risk management.
Pro Tips for ATR Mastery
- Combine with Trends: Use ATR alongside ADX to distinguish between volatile trending and ranging markets.
- Session-Specific ATR: Calculate separate ATR values for Asian/London/NY sessions when trading forex.
- Normalized ATR: Divide ATR by closing price to compare volatility across differently priced assets.
- Options Trading: Higher ATR values increase option premiums—factor this into your pricing models.
Note: All code examples assume use of Tianqin's API. Remove promotional links if implementing elsewhere.