Trailing Take Profit Order using IB Controller

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

Some info is here:

But it does not explain everything.

I looked at the TWS API here:

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?


Since "TRAIL" order requires setting both trailingPercent and trailStopPrice
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!


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

1 Like