布林带指标。
| 50 | |
| 51 | |
| 52 | class BOLL(IndicatorBase): |
| 53 | """ 布林带指标。 """ |
| 54 | ## @todo assure name is unique, it there are same names, |
| 55 | # modify the repeat name. |
| 56 | @create_attributes |
| 57 | def __init__(self, tracker, prices, n, name='BOLL', color='y', lw=1, style="line"): |
| 58 | super(BOLL, self).__init__(tracker, name) |
| 59 | # self.value为任何支持index的数据结构。 |
| 60 | # 在策略中,price变量可能为NumberSeries,需要用NUMBER_SERIES_SUPPORT处理, |
| 61 | # 转化为numpy.ndarray等能被指标函数处理的参数。 |
| 62 | self.value = self._boll(prices, n) |
| 63 | |
| 64 | def _boll(self, data, n): |
| 65 | """ 向量化运行的均值函数。 """ |
| 66 | data = transform2ndarray(data) |
| 67 | upper, middle, lower = talib.BBANDS(data, n, 2, 2) |
| 68 | return (upper, middle, lower) |
| 69 | |
| 70 | def plot(self, widget): |
| 71 | """ 绘图,参数可由UI调整。 """ |
| 72 | self.widget = widget |
| 73 | #self.plot_line(self.value, self.color, self.lw, self.style) |
| 74 | |
| 75 | |
| 76 | class RSI(IndicatorBase): |