1
0

修复卖出逻辑的实现,不允许卖空

This commit is contained in:
2026-01-28 10:30:28 +08:00
parent 64bfd031b3
commit 5afb8ddcd1
3 changed files with 4 additions and 6 deletions

View File

@@ -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() # 平掉多仓