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



  • 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?



  • 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.



  • 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)
    
    


  • @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.


  • administrators

    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?


  • administrators

    @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.