Trailing Take Profit Order using IB Controller

I'm trying to implement a take profit trailing order using IB Controller.

Some info is here: https://www.amibroker.com/at/

But it does not explain everything.

I looked at the TWS API here: https://interactivebrokers.github.io/tws-api/adjustable_stops.html#adjusted_stop_trail

But I don't see how the data fields correspond to the IB Controller PlaceOrder function.

Here is the code I have at this point...


ibc.PlaceOrder(nm, "SELL", Shares, "TRAIL", triggerPrice, ???PctInc???, "GTC", False, 100, "", parentID );

Can someone help me with this?

Thanks...

Since "TRAIL" order requires setting both trailingPercent and trailStopPrice
https://interactivebrokers.github.io/tws-api/basic_orders.html#trailingstop
such order can't be sent currently as these fields are not accessible via PlaceOrder call

You can use "TRAIL" as follows, although not with a percent. It must be a dollar amount.

// Example TRAIL order that trails $5 below the price (populates the "amt" in TWS which is also known as "aux"):
orderID = ibc.PlaceOrder( "SPY", "Sell", 100, "TRAIL", 0, 5, "GTC", True, 100, "", 0, "", 0, "" );

This also works with ModifyOrder in the same way.

Happy autotrading!
Peter

2 Likes

Yes. I believe you are correct. Nice job. Thanks.

1 Like