Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    new sell order executed alone with previous BracketOrder(stop loss)

    General Code/Help
    2
    5
    416
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      Fei Xue last edited by

      Hi there,

      I have created a bracket order as suggested:

      mainside = self.buy(price=13.50, exectype=bt.Order.Limit, transmit=False)
      lowside  = self.sell(price=13.00, size=mainside.size, exectype=bt.Order.Stop,
                           transmit=False, parent=mainside)
      highside = self.sell(price=14.00, size=mainside.size, exectype=bt.Order.Limit,
                           transmit=True, parent=mainside)
      

      A few bars later, I created a sell order to sell out whole stakes in next(). However, previous bracket order (stop loss) has also been triggered and both orders have been executed and position goes to negative. Do you have any idea how to avoid that?

      Thanks so much!

      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        It isn't clear what you are trying to say, because not enough information is provided. From your message let's assume the following:

        • Bracket Orders are issued. Main Order (Buy) is active and the 2 bracketing (Sell) orders are inactive (they only become active when the main order is executed)
        • Main Order (Buy) is executed and the 2 bracketing (Sell) orders become active
        • You issue a new Sell order and is executed
        • One of the 2 bracketing orders (Sell) is also executed. The other is correspondingly canceled.

        Yes, you have a negative position, i.e.: you have gone short.

        What is your expectation?

        The only thing which seems logical is to canel the bracketing orders before issuing the new sell to avoid them being executed.

        1 Reply Last reply Reply Quote 0
        • F
          Fei Xue last edited by

          Yes, that is what happened. Is there any mechanism available in BackTrader to support long-only strategy?
          If not, I need to manage all active sell order in the implementation of my strategy and cancel all (some) of them before issuing new sell order, right?

          Thanks!

          B 1 Reply Last reply Reply Quote 0
          • B
            backtrader administrators @Fei Xue last edited by

            @fei-xue said in new sell order executed alone with previous BracketOrder(stop loss):

            Yes, that is what happened. Is there any mechanism available in BackTrader to support long-only strategy?

            You can implement a custom Sizer (Docs - Sizers) and avoid selling if your position is already at 0.

            @fei-xue said in new sell order executed alone with previous BracketOrder(stop loss):

            If not, I need to manage all active sell order in the implementation of my strategy and cancel all (some) of them before issuing new sell order, right?

            This is a MUST, not something you think you might do, but it's a lot better if the platform can think for you. You need to manage your orders and your positions.

            1 Reply Last reply Reply Quote 0
            • F
              Fei Xue last edited by

              It is clear for me now. Thank you so much!!!

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors