如何使用 python 下达带有止盈和止损功能的期货市场订单

问题描述 投票:0回答:0

我正在使用回溯测试包来测试我的交易机器人,但在使用 python 下达止盈订单和买入订单时遇到了困难。现在我正在使用以下 python 代码来购买订单,例如:

    def support_trade_level(self, support, resistance, lower_support): 
        if self.close <= support + 1 and self.close >= support - 1:
            self.buy(sl= support - 2, 
                     limit= support, 
                     stop= support, 
                     tp= Support + 8)

在我的代码中,当它提供 8 点利润时,我设置平仓买入头寸,它工作正常,但是当我尝试减少止盈并将其设置为低于 7 时,它给了我 ValueError (sl < limit < tp)

为了消除这个错误,我将限价和止损价格与 sl 和 tp 一起分配,它删除了 ValueError 消息并允许我将 7 点作为获利但在后端它完全消除了获利价格并将其视为 0 所以我所有的交易都关闭了亏损(我假设它设置 tp=0 因为在那之后我所有的交易都以负数收盘)。

我希望每笔交易最多 4 个点 我不明白为什么不允许我获利低于 8 个点。有什么解决办法吗?

python-3.x bots trading algorithmic-trading
© www.soinside.com 2019 - 2024. All rights reserved.