feat: 修复报错
This commit is contained in:
22
python-app/app/strategies/sma_cross.py
Normal file
22
python-app/app/strategies/sma_cross.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import backtrader as bt
|
||||
|
||||
|
||||
class SmaCrossStrategy(bt.Strategy):
|
||||
params = (
|
||||
("fast", 3),
|
||||
("slow", 8),
|
||||
("stake", 1),
|
||||
)
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.fast_sma = bt.indicators.SMA(self.data.close, period=self.params.fast)
|
||||
self.slow_sma = bt.indicators.SMA(self.data.close, period=self.params.slow)
|
||||
self.cross_signal = bt.indicators.CrossOver(self.fast_sma, self.slow_sma)
|
||||
|
||||
def next(self) -> None:
|
||||
if not self.position and self.cross_signal > 0:
|
||||
self.buy(size=self.params.stake)
|
||||
elif self.position and self.cross_signal < 0:
|
||||
self.close()
|
||||
Reference in New Issue
Block a user