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

大佬们,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)
Member
avatar
加入于:
帖子: 4622
声望: 284

stop=True是本地停止单,在价格触发之后,会以盘口五档或者涨跌停价发出。但是委托记录显示的是交易所方显示的类型。

Member
avatar
加入于:
帖子: 25
声望: 0

我记得好象在哪里看到过,停止单触发后,变成限价单成交,所以成交记录显示的是限价单。

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

沪公网安备 31011502017034号

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