开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: Can a bracket order have two take profit orders to exit a position at two different profit levels?


 

开云体育

I tried out my suggestion and it seems to work fine. I bought 1000 shares of TSCO at market at the LSE, with a stop-loss STP order at 215 and a take-profit LMT order at 225.

?

After the entry market order filled, I modified both the stop-loss and take-profit orders to a size of 500 and set the parentId to 0 in both.

?

Then I create a new OCA group with a sell 500 STP order at 215 and a sell 500 LMT at 223.

?

The TWS API tab now looks like the attached screenshot. Note that this shows a Position of 3200 – that's because I already had 2200 TSCO in the portfolio.

?

Because there are four PLACE_ORDER operations to do after the entry order has filled, there is still a small risk of getting into trouble if you lose your TWS connection for any reason during that sequence: but given that you can just bang these operations in within a very short time, you'd have to be very unlucky.

?

Also some refinement would presumably be needed if the entry order had partial fills: you'd have to monitor the executions until the entry order was fully filled.

?

?

?

?

?

?

From: [email protected] <[email protected]> On Behalf Of Richard L King
Sent: 29 April 2021 10:18
To: [email protected]
Subject: Re: [TWS API] Can a bracket order have two take profit orders to exit a position at two different profit levels?

?

No, there's no easy way to do that.

?

Obviously you can program this so that you create a bracket order with a stop-loss but no take-profit: as soon as the entry order fills, create the two take-profit orders, and then monitor the stop-loss so that if it fills, you can cancel the take-profits. Easy enough, provided you use a stop order for your stop-loss rather than a stop-limit, which then gives you potential complications with partial fills. And of course ?your program has to keep running to ensure that the take-profits are cancelled if need be.

?

A possible alternative that I haven't tried but seems like it should work is to create your initial bracket order with stop-loss and a single take-profit, and then when the entry order fills, halve the size of the OCA group containing the stop-loss and take-profit, and then create another OCA group containing another half-size stop-loss and the other take-profit. Once that's done you can walk away, as it were. The only question in my mind is whether you can actually change the size of an OCA group that was once attached to a parent order, but I can't see why it wouldn't be allowed. I'll try this when I've got a few spare minutes.

?

?

From: [email protected] <[email protected]> On Behalf Of Levente
Sent: 28 April 2021 22:48
To: [email protected]
Subject: [TWS API] Can a bracket order have two take profit orders to exit a position at two different profit levels?

?

I would like to know if there is a mechanism that would allow me to place a position opening order for N contracts, together with two take profit orders, each of size N/2 but at different price levels.
If I create a bracket order with these 3 orders, when the position opening order fills the two take profit orders will be activated, but they will belong to the same OCA group, so that when the first one fills, the other will get cancelled automatically, which is not what I want.

Join [email protected] to automatically receive all group messages.