simonw 行情中断过,然后的逻辑的就乱了(似乎bar的时间与pos的值都不对)
策略是此前分享的R_Breaker ,在update_bar 会调用cancel_all
问题
1:过程中连续开了两个1手多单,
2:有委托没找到
3:在最后收盘时也没有平仓
这些问题在实盘中可能遇到吗
self.tend_high, self.tend_low = am.donchian(self.donchian_window)
if bar.datetime.time() < self.exit_time:
if self.pos == 0:
self.intra_trade_low = bar.low_price
self.intra_trade_high = bar.high_price
if self.tend_high > self.sell_setup:
long_entry = max(self.buy_break, self.day_high)
self.buy(long_entry, self.fixed_size, stop=True)
self.short(self.sell_enter, self.multiplier * self.fixed_size, stop=True)
elif self.tend_low < self.buy_setup:
short_entry = min(self.sell_break, self.day_low)
self.short(short_entry, self.fixed_size, stop=True)
self.buy(self.buy_enter, self.multiplier * self.fixed_size, stop=True)
elif self.pos > 0:
self.intra_trade_high = max(self.intra_trade_high, bar.high_price)
long_stop = self.intra_trade_high * (1 - self.trailing_long / 100)
self.sell(long_stop, abs(self.pos), stop=True)
elif self.pos < 0:
self.intra_trade_low = min(self.intra_trade_low, bar.low_price)
short_stop = self.intra_trade_low * (1 + self.trailing_short / 100)
self.cover(short_stop, abs(self.pos), stop=True)
Close existing position
else:
if self.pos > 0:
self.sell(bar.close_price 0.99, abs(self.pos))
elif self.pos < 0:
self.cover(bar.close_price 1.01, abs(self.pos))