backtrader.indicators.sma module¶
SMA Indicator Module - Simple Moving Average.
This module provides the SMA (Simple Moving Average) indicator for calculating the non-weighted average of the last n periods.
- Classes:
MovingAverageSimple: SMA indicator (alias: SMA).
示例
- class MyStrategy(bt.Strategy):
- def __init__(self):
self.sma = bt.indicators.SMA(self.data.close, period=20)
- def next(self):
- if self.data.close[0] > self.sma[0]:
self.buy()
- elif self.data.close[0] < self.sma[0]:
self.sell()
- class backtrader.indicators.sma.MovingAverageSimple[源代码]¶
-
Non-weighted average of the last n periods
- Formula:
movav = Sum(data, period) / period
- alias = ('SMA', 'SimpleMovingAverage')¶
- __init__(*args, **kwargs)¶
- frompackages = ()¶
- packages = ()¶
- backtrader.indicators.sma.SMA¶