IBridgePy starts to support Trailing Stop Limit order

A trailing stop limit order is designed to allow an investor to specify a limit on the maximum possible loss, without setting a limit on the maximum possible gain. For more details about trailing stop limit order, please refer to the introduction of this type of order at https://www.interactivebrokers.com/en/index.php?f=606

IBridgePy from version 2.20180324 starts to support placing trailing stop limit order.

The following is the example provided at IB’s website

“You have purchased 100 shares of XYZ for $66.34 per share (your Average Price) and want to limit your loss. You set a trailing stop limit order with the trailing amount 20 cents below the current market price of 61.90. The trailing amount is the amount used to calculate the initial stop price, by which you want the limit price to trail the stop price.

To do this, first create a SELL order, then click select TRAIL LIMIT in the Type field and enter 0.20 in the Trailing Amt field. In a trailing stop limit order, you specify a stop price and either a limit price or a limit offset. In this example, we are going to set the limit offset; the limit price is then calculated as Stop Price – Limit Offset. You enter a stop price of 61.70 and a limit offset of 0.10. You submit the order.”

In IBridgePy, the following code can be used to place the trailing stop limit order in the above example.

def initialize(context):
def handle_data(context, data):     
    orderId = order(context.sec, 100, 
                    style = TrailStopLimitOrder(stop_price = 61.70, 
                                                trailing_amount = 0.20,
                                                limit_offset = 0.20))
One comment on “IBridgePy starts to support Trailing Stop Limit order
  1. Anonymous says:

    That is wonderful! Good work!


Leave a Reply to Anonymous Cancel reply

Your email address will not be published.