```
if g.Signal == 1 and context.portfolio.long_positions[RealFuture].total_amount == 0:
if context.portfolio.long_positions[RealFuture].total_amount != 0:
log.info('空头有持仓:%s'%(RealFuture))
order_target(RealFuture,0,side='short')
order_target(RealFuture,g.TradeLots[RealFuture],side='long')
```
上面的代码是不是有些问题?我修改如下:
```
if context.portfolio.short_positions[RealFuture].total_amount != 0:
log.info('空头有持仓:%s'%(RealFuture))
order_target(RealFuture,0,side='short')
```
逻辑:在做多信号并且做多仓位0的时候,判断是否存在空头仓位,如果有空头仓位,空头仓位平仓
2018-12-08