大佬们,cta策略移动止损和止盈是这样写的吗?我设置的fixed_size是3,但是打出来log有时候self.pos是6或者-6,stop=true不应该是停止单吗,但是委托记录里显示的全部是限价单
self.cancel_all()
...
if self.pos > 0:
self.intra_trade_high = max(bar.high_price,self.intra_trade_high)
self.intra_trade_low = bar.low_price
if self.isShort():
self.short_entry_price = bar.close_price
self.sell(self.short_entry_price,self.fixed_size)
self.short(self.short_entry_price,self.fixed_size)
# print("Sell and short")
if self.enable_take_profit:
self.sell(self.long_entry_price*(1+self.long_take_profit_perc*0.01),abs(self.pos))
if self.enable_stop_loss:
self.long_stop_loss_price = self.intra_trade_high*(1-self.perc_long_stop_loss*0.01)
self.sell(self.long_stop_loss_price,abs(self.pos),stop=True)
elif self.pos == 0:
self.intra_trade_high = bar.high_price
self.intra_trade_low = bar.low_price
if self.isLong():
self.long_entry_price = bar.close_price
self.buy(self.long_entry_price, self.fixed_size)
elif self.isShort():
self.short_entry_price = bar.close_price
self.short(self.short_entry_price,self.fixed_size)
# print("short")
elif self.pos <0:
self.intra_trade_low = min(bar.low_price,self.intra_trade_low)
self.intra_trade_high = bar.high_price
if self.isLong():
self.long_entry_price = bar.close_price
self.cover(self.long_entry_price,self.fixed_size)
self.buy(self.long_entry_price,self.fixed_size)
# print("cover and buy")
if self.enable_take_profit:
self.cover(self.short_entry_price*(1-self.short_take_profit_perc*0.01),abs(self.fixed_size))
if self.enable_stop_loss:
self.short_stop_loss_price = self.intra_trade_low*(1+self.perc_short_stop_loss*0.01)
self.cover(self.short_stop_loss_price,abs(self.pos),stop=True)