18 lines
494 B
Python
18 lines
494 B
Python
from backtesting import Strategy
|
|
from backtesting.lib import crossover
|
|
|
|
class SMAcross(Strategy):
|
|
n1 = 50
|
|
n2 = 100
|
|
|
|
def __init__(self):
|
|
close = self.data.Close
|
|
self.sma1 = self.I(ta.trend.sma_indicator, pd.Series(close), self.n1)
|
|
self.sma2 = self.I(ta.trend.sma_indicator, pd.Series(close), self.n2)
|
|
|
|
def next(self):
|
|
if crossover(self.sma1, self.sma2):
|
|
self.buy()
|
|
elif crossover(self.sma2, self.sma1):
|
|
self.sell()
|