
波动率指标,由中间带 (SMA) and 两个外带(上方/下方的标准差)组成。带宽在波动率高时扩大,在波动率低时收缩。
波动率指标,由中间带 (SMA) and 两个外带(上方/下方的标准差)组成。带宽在波动率高时扩大,在波动率低时收缩。
布林带擅长突破检测。当带宽收缩(低波动率“挤压”)时,重大的价格变动即将来临。突破策略在价格收于上轨上方(看涨突破)或下轨下方(看跌突破)时入场,顺应波动率的扩张。
了解更多关于 Breakout Trading Strategies →import backtrader as bt
class BollingerBreakout(bt.Strategy):
params = (('period', 20), ('devfactor', 2.0))
def __init__(self):
self.bb = bt.indicators.BollingerBands(self.data.close,
period=self.p.period,
devfactor=self.p.devfactor)
def next(self):
# Price breaks above upper band = bullish breakout
if self.data.close[0] > self.bb.lines.top[0] and self.data.close[-1] <= self.bb.lines.top[-1]:
self.buy()
# Price breaks below lower band = bearish breakout
elif self.data.close[0] < self.bb.lines.bot[0] and self.data.close[-1] >= self.bb.lines.bot[-1]:
self.sell()| 参数 | 默认值 | 描述 |
|---|---|---|
| period | 20 | 中轨的 SMA 周期 |
| devfactor | 2 | 外轨的标准差倍数 |