For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Problem with Bracket Order

  • Been messing around with this for a while now. I was expecting that the main buy order would be executed once price drops to self.datas[0].close[0] * 0.99. That doesn't seem to be the case tho, instead it buys at current price and then sells on next candle. What am I missing here?

        price=self.datas[0].close[0] * 0.99,
        stopprice=self.datas[0].close[0] * 0.9)


  • Hi. I think that you should add exectype param.

    p1 = 100
    p2 = p1 - 0,01 * p1
    p3 = p1 + 0,01 * p1
    self.buy_bracket(price=p1, stopprice=p2, limitprice=p3, exectype=bt.Order.Limit)

  • Tried that. Still no luck.

    From what I understand, bt.Order.Limit is the default for exectype anyhow. From GitHub:

    def buy_bracket(
        self, data=None, size=None, price=None, plimit=None,
        exectype=bt.Order.Limit, valid=None, tradeid=0,
        trailamount=None, trailpercent=None, oargs={},
        stopprice=None, stopexec=bt.Order.Stop, stopargs={},
        limitprice=None, limitexec=bt.Order.Limit, limitargs={},

  • Soloved. Mistake on my end.