IBridgePy starts to support Trailing Stop Limit order

A trailing stop limit order is designed to allow investors to specify a limit on the maximum possible loss without setting a limit on maximum gains. IBridgePy now supports placing these advanced order types for algorithmic trading with Interactive Brokers using Python.

trailing stop limit

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

EXCLUSIVE OFFER

Extra 7% OFF All Quantra Courses

Level up your quant trading skills with courses from Quantra by QuantInsti — Python for trading, machine learning strategies, options trading, and more.

HUI7 Browse Courses → Use code HUI7 at checkout

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 stop order with trailing protection 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.”

Need help building this strategy?

Our Rent-a-Coder team builds custom automated trading programs. From simple scripts to complex multi-account strategies — we handle it all.

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

def initialize(context):
    context.sec=symbol('AAPL')
  
def handle_data(context, data):     
    orderId = order(context.sec, 100, 
                    style = TrailStopLimitOrder(stop_price = 61.70, 
                                                trailing_amount = 0.20,
                                                limit_offset = 0.20))
    end()
    
EXCLUSIVE OFFER

Extra 7% OFF All Quantra Courses

Level up your quant trading skills with courses from Quantra by QuantInsti — Python for trading, machine learning strategies, options trading, and more.

HUI7 Browse Courses → Use code HUI7 at checkout

Ready to Automate Your Trading?

Download IBridgePy free or let our coders build your strategy.

Download Free Hire a Coder

1 thought on “IBridgePy starts to support Trailing Stop Limit order”

Leave a Comment