VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 134
声望: 0

如果有成交的情况下,这几个订单列表没有看到被清空的操作, 如果self.pos==0,然后挂出上下两个价位都挂出停止单,那么下一笔bar 来了之后就把原来的挂单撤单 ,也没有找到重新挂出去的操作 ,请老师解答 ,谢谢
self.buy_vt_orderids = []
self.sell_vt_orderids = []
self.short_vt_orderids = []
self.cover_vt_orderids = []
def on_15min_bar(self, bar: BarData):
""""""

    # 生成交易信号
    am = self.am
    am.update_bar(bar)
    if not am.inited:
        return

    self.boll_up, self.boll_down = am.boll(self.boll_window, self.boll_dev)
    self.boll_mid = am.sma(self.boll_window)
    self.atr_value = am.atr(self.atr_window)

    if self.pos == 0:
        self.intra_trade_high = bar.high_price
        self.intra_trade_low = bar.low_price

        self.buy_price = self.boll_up
        self.sell_price = 0
        self.short_price = self.boll_down
        self.cover_price = 0

    elif self.pos > 0:
        self.intra_trade_high = max(self.intra_trade_high, bar.high_price)
        self.intra_trade_low = bar.low_price

        self.long_sl = self.intra_trade_high - self.atr_value * self.atr_multiplier
        self.long_sl = max(self.boll_mid, self.long_sl)

        self.buy_price = 0
        self.sell_price = self.long_sl
        self.short_price = 0
        self.cover_price = 0

    elif self.pos < 0:
        self.intra_trade_low = min(self.intra_trade_low, bar.low_price)
        self.intra_trade_high = bar.high_price

        self.short_sl = self.intra_trade_low + self.atr_value * self.atr_multiplier
        self.short_sl = min(self.boll_mid, self.short_sl)

        self.buy_price = 0
        self.sell_price = 0
        self.short_price = 0
        self.cover_price = self.short_sl

    # 根据信号执行挂撤交易
    if self.pos == 0:
        # 检查之前委托都已经结束
        if not self.buy_vt_orderids:
            # 检查存在信号
            if self.buy_price:
                self.buy_vt_orderids = self.buy(self.buy_price, self.fixed_size, True)
                self.buy_price = 0      # 执行需要清空信号
        else:
            # 遍历委托号列表撤单
            for vt_orderid in self.buy_vt_orderids:
                self.cancel_order(vt_orderid)

        if not self.short_vt_orderids:
            if self.short_price:
                self.short_vt_orderids = self.short(self.short_price, self.fixed_size, True)
                self.short_price = 0
        else:
            for vt_orderid in self.short_vt_orderids:
                self.cancel_order(vt_orderid)
    elif self.pos > 0:
        if not self.sell_vt_orderids:
            if self.sell_price:
                self.sell_vt_orderids = self.sell(self.sell_price, abs(self.pos), True)
                self.sell_price = 0
        else:
            for vt_orderid in self.sell_vt_orderids:
                self.cancel_order(vt_orderid)
    else:
        if not self.cover_vt_orderids:
            if self.cover_price:
                self.cover_vt_orderids = self.cover(self.cover_price, abs(self.pos), True)
                self.cover_price = 0
        else:
            for vt_orderid in self.cover_vt_orderids:
                self.cancel_order(vt_orderid)
Member
avatar
加入于:
帖子: 134
声望: 0

如果有成交 self.buy_vt_orderids = []
self.sell_vt_orderids = []
self.short_vt_orderids = []
self.cover_vt_orderids = []
这四个列表中的订单编号会消失吗

Member
avatar
加入于:
帖子: 3254
声望: 218

在on_stop_order里移除了

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】