ATR 完整教程
用波动率动态调整仓位
ATR(Average True Range,平均真实波幅)是 J. Welles Wilder 1978 年在《New Concepts in Technical Trading Systems》 发明的指标(他同年还发明了 RSI)。
这个指标不告诉你买卖方向, 只告诉你「市场目前有多波动」。 但 ATR 是真正高手用的风控核心 — 1983 年的海龟交易系统、Bill Dunn 的 DUNN Capital 40 年复合年化 19%、 几乎所有 CTA 都用 ATR 做仓位管理。
1. 什么是 ATR?背后的数学
先讲「True Range(真实波幅)」 — 一根 K 线的波动 = 三个值取最大:
TR = max(
high − low, // 当根 K 的高低差
abs(high − close_prev), // 高点到前一根收盘的差
abs(low − close_prev) // 低点到前一根收盘的差
)为什么要考虑前一根收盘?因为跳空 gap — 当前 K 线可能 high=100、low=98,看似波动小, 但前一根收盘是 105 → 实际波动 7(从 105 到 98)。
ATR 就是过去 N 根 K 的 TR 平均(N 默认 14):
ATR(14) = 过去 14 根 True Range 的「平滑移动平均」(RMA)2. 用法 ①:动态止损(最常见)
固定止损的问题:用 1% 止损,BTC 高波动时容易被洗、低波动时又太松。 ATR 止损自动调整:
//@version=5
strategy("ATR 动态停损", overlay=true)
atrLength = input.int(14, "ATR 周期")
atrMult = input.float(2.0, "停损 ATR 倍数")
atr = ta.atr(atrLength)
// 进场(随便用 EMA 交叉做示范)
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
if (ta.crossover(ema9, ema21))
strategy.entry("Long", strategy.long)
if (ta.crossunder(ema9, ema21))
strategy.entry("Short", strategy.short)
// === 动态停损 ===
longStop = strategy.position_avg_price - atr * atrMult
shortStop = strategy.position_avg_price + atr * atrMult
strategy.exit("LongExit", "Long", stop=longStop)
strategy.exit("ShortExit", "Short", stop=shortStop)
plot(atr, "ATR", color=color.purple, display=display.pane)常见 ATR 倍数:
- 1.5x:紧止损,适合震荡盘、scalp
- 2x:标准(海龟用的就是这个)
- 3x:宽止损,适合波段、给趋势空间
- 4-5x:超宽止损,适合超长线
3. 用法 ②:海龟仓位法(最值得学的)
这是 1983 年海龟交易系统的核心。详见 CTA 趋势追踪 + 海龟交易。
原理:每笔交易的「风险金额」永远是账户 1%。 用 ATR 算出止损距离,反推仓位大小。
风险金额 = 帐户资金 × 1%
停损距离 = ATR × 2
部位大小(口数)= 风险金额 / 停损距离
范例:
帐户 $10,000
ATR = $500
风险金额 = $100
停损距离 = $1,000
部位大小 = $100 / $1,000 = 0.1 BTC//@version=5
strategy("海龟部位法", overlay=true,
initial_capital=10000, default_qty_type=strategy.fixed)
atrLength = input.int(20, "ATR 周期(海龟原版用 20)")
riskPct = input.float(1.0, "每笔风险 %")
atrMult = input.float(2.0, "停损 ATR 倍数")
atr = ta.atr(atrLength)
// 部位大小 = 风险金额 / 停损距离
riskAmount = strategy.equity * riskPct / 100
stopDistance = atr * atrMult
positionQty = riskAmount / stopDistance
// 进场
if (ta.crossover(close, ta.highest(high, 20)[1]))
strategy.entry("Long", strategy.long, qty=positionQty)
if (ta.crossunder(close, ta.lowest(low, 20)[1]))
strategy.entry("Short", strategy.short, qty=positionQty)
// 动态停损
strategy.exit("LongStop", "Long",
stop=strategy.position_avg_price - atr * atrMult)
strategy.exit("ShortStop", "Short",
stop=strategy.position_avg_price + atr * atrMult)
plot(atr, "ATR", color=color.purple)4. 用法 ③:突破过滤(避免假突破)
很多突破策略会被「假突破」骗 — 价格刚刚突破前高,没等回头就回落。
解法:要求突破幅度大于 ATR × N,才算真突破:
//@version=5
strategy("ATR 过滤突破", overlay=true)
prevHigh = ta.highest(high, 20)[1]
atr = ta.atr(14)
breakoutFilter = atr * 0.5 // 至少要突破 ATR 的 50%
// 真突破:close 比前高高 ≥ 0.5 ATR
trueBreakout = close > prevHigh + breakoutFilter
if (trueBreakout)
strategy.entry("Long", strategy.long)5. 用法 ④:趋势强度判断
ATR 上升 = 市场波动增加 = 通常有强趋势或重大事件。ATR 下降 = 市场安静 = 震荡或盘整。
可以用 ATR 跟它自己的长期平均比较:
atr = ta.atr(14)
atrMa = ta.sma(atr, 50)
highVol = atr > atrMa * 1.5 // 波动率比平均高 50%
lowVol = atr < atrMa * 0.6 // 波动率比平均低 40%
// 高波动率时跑趋势策略
// 低波动率时跑网格 / 均值回归
bgcolor(highVol ? color.new(color.red, 90) : na, title="高波动")
bgcolor(lowVol ? color.new(color.blue, 90) : na, title="低波动")6. ATR 跟其他波动率指标的差别
| 指标 | 特性 | 适用 |
|---|---|---|
| ATR | 绝对价格波动,含 gap | 仓位管理、动态止损 |
| 标准差(σ) | 统计波动,假设正态分布 | Bollinger Bands 等通道 |
| 历史波动率 HV | 年化 σ,跨资产可比 | 期权定价 |
| 隐含波动率 IV | 市场预期未来波动 | 期权策略 |
7. 常见错误
❌ ATR 不是信号
有人把「ATR 变大 → 做多」「ATR 变小 → 做空」当策略。 错。ATR 只是波动率,没有方向意义。 要配合趋势或进出场规则。
❌ 把 ATR 当 %
ATR 是绝对价格,不是百分比。 BTC 在 $30k 时 ATR=$500 对应 1.67%, BTC 在 $60k 时 ATR=$500 对应 0.83%。 跨时间框架比较要正规化。
❌ 周期设太短
有人改 ATR 周期成 5 想「更敏感」。 结果 ATR 跟着最近 1-2 根极端 K 大幅震荡,止损点乱跳。 坚持用默认 14 或 20。
❌ 全部资产用同一 ATR 倍数
BTC 跟山寨币的特性不同。建议:
- BTC:ATR × 2-3
- ETH / 大型山寨:ATR × 2-2.5
- 小型山寨:ATR × 3-4(噪音大需更宽)
8. 三个关键 takeaway
- ATR 是「翻译机」:把抽象波动率翻成具体金额, 让你做仓位、止损、风险控制
- 海龟仓位法是 1983 年的革命性概念: 每笔 1% 风险、ATR 动态调整 — 至今仍是业界标准
- ATR 没有方向,不要拿来当信号。 它的价值在让你的策略适应市场状态