修复卖出逻辑的实现,不允许卖空
This commit is contained in:
@@ -117,7 +117,7 @@ class MacdTrendStrategy(Strategy):
|
||||
self.buy() # 开多仓
|
||||
|
||||
# 卖出条件: MACD 死叉 OR 价格 < EMA
|
||||
elif crossover(self.signal, self.macd) or self.data.Close[-1] < self.ema[-1]:
|
||||
elif self.position.size > 0 and (crossover(self.signal, self.macd) or self.data.Close[-1] < self.ema[-1]):
|
||||
self.position.close() # 平掉多仓
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user