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/

    Stop orders on interactive brokers

    General Code/Help
    4
    7
    1351
    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.
    • A
      ard9000 last edited by

      I have a strategy that I'm implementing using the IB broker to interface with for my test account. Everything works great except stop orders. In my backtest strategy I have:

      stop_order = self.close(data_min, price=stop_price, exectype=bt.Order.Stop)
      self.orders.append(stop_order)
      

      Where data_min is the minute data feed I'm using. When stop orders are placed this way using exectype=bt.Order.Stop, there is no stop loss order created. Either with IB or within the strategy itself, if the price moves through the stop price, it never exits.

      All of the other entries and exits with BT work great with IB.

      Is there a specific exectype for IB market stop loss orders?

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by ab_trader

        self.close is a market order, it doesn't use price and order type. self.buy or self.sell with appropriate order type need to be used.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        B 1 Reply Last reply Reply Quote 0
        • A
          ard9000 last edited by

          The result is the same if I use:

          stop_order = self.close(data_min, price=stop_price, exectype=bt.Order.Stop)
          
          stop_order = self.buy(data_min, price=stop_price, exectype=bt.Order.Stop)
          
          stop_order = self.sell(data_min, price=stop_price, exectype=bt.Order.Stop)
          
          
          A 1 Reply Last reply Reply Quote 0
          • A
            ard9000 @ard9000 last edited by

            @ard9000

            Bump.

            My hopes to this being resolved are fading quick. It doesn't appear, based on this and my other post about the getposition() bugs in live IB trading, that anyone is using BT for live equities trading.

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

              0_1526297769852_5dee70e0-1c1e-4e5d-b718-63816c85dc2f-image.png

              Using the standard test code available in the sources, by simply forcing a buy to use Stop.-

              It simply works. You may want to share with us things like a working sample, how you execute the code ...

              @ard9000 said in Stop orders on interactive brokers:

              My hopes to this being resolved are fading quick

              How quick are you expecting things to get resolved?

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

                @ab_trader said in Stop orders on interactive brokers:

                self.close is a market order

                Not really. The default behavior is Market, but one can change the execution type. close is meant simply to calculate the opposite size of the current open position.

                1 Reply Last reply Reply Quote 0
                • K
                  kirahvi last edited by

                  @ard9000 Did you get this working?

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