Partial take profit order?

I would like to place a partial take profit order with a linked stop loss order to fully close the position, and am wondering if this is possible in Alpaca?

For example, let’s say I own 100 shares of security ABC currently trading at $10 per share. I would like to place the following orders -

Limit sell 50 shares at $15 per share
Stop loss sell 100 shares at $7.50 per share

The issue is that if my limit sell executes, I now have an invalid stop sell for more shares than I own. If I set it up as a OCO order, the problem would be I would have no exit from the trade if the price were to fall below my exit point after the take profit order was executed.

One way I can think of achieving this would be to set it up as three linked trades -

Limit sell 50 shares at $15 per share
Stop sell for 100 shares at $7.50 (canceled by limit execution)
Stop sell for 50 shares at $7.50 (triggered by limit execution)

Or alternatively -

Limit sell 50 shares at $15 per share
Stop sell for up to 100 shares at $7.50

However, I’m not sure if either of these approaches are supported by the Alpaca API. Any ideas?

@thebarryman There isn’t a ‘direct’ way to place an order to “partially take profit or fully close” a position. One-Cancels-Other (OCO) orders are required to have the same quantity. However, you accomplish this with a OCO order and a simple stop loss order.

Using your example, and you own 100 shares of security ABC currently trading at $10 per share. You would like to place the following orders -

Limit sell 50 shares at $15 per share
Stop loss sell 100 shares at $7.50 per share

Submit two orders

Order A
OCO order
Limit sell 50 shares at $15 per share
Stop loss sell 50 shares at $7.50 per share

Order B
Simple order
Stop loss sell 50 shares at $7.50 per share

There’s a stop loss in place for the entire 100 shares if the price drops below $7.50. You have a take profit for 50 shares if the prices goes up to $15, which if it executes, will cancel the stop loss order for those shares.

1 Like

Now there’s a great solution! Thanks for your help.

Follow-up question for you - how should I handle buy orders to enter into these positions?

My plan is to submit the buy as a market order to be executed at open. Assuming the order is actually filled as soon as the market opens, then I think it would be safe to submit my sell orders at the same time as the buy order.

But I am worried about execution order, what would happen if the stop triggers on market open and the sell order is executed before the buy?

For now, I am planning on just submitting the sell orders after the buy executes, but it would be great to conditionally submit them on buy execution - or, if I could safely assume that the market buy would always execute first.

@thebarryman I believe what you are looking for is a “bracket order”. There’s a bit of info in the docs here. Basically, it submits 3 orders at one time. 1) an initial market or limit order to open the position, 2) a take profit limit order and a 3) stop loss order. The take-profit and stop loss orders are submitted only after the initial order fills.

That should do what you want.

I have seen the bracket order but it doesn’t seem to be able to accommodate the setup you suggested above, where there are two sell trades in tandem that need to be submitted.

Maybe two bracket orders could be used? But only one of the trades should have a limit sell associated with it.

One more question @Dan_Whitnable_Alpaca, I’m not seeing a way to actually create the OCO order from your C# API. Is this only available by posting a JSON request directly?

@thebarryman You mentioned the bracket order “doesn’t seem to be able to accommodate the setup you suggested above, where there are two sell trades in tandem that need to be submitted”. If you want a buy+stop_loss+take_profit then the bracket order will work. If, as you originally stated, you want some of the position to have a take profit and some not, then you could enter two bracket orders Or, you could enter a bracket order (for the portion you want to have a take profit) and a One-Triggers-Other (OTO) order (for the portion you don’t want a take profit order). However, there isn’t a real downside to including the take profit order and setting a very high limit price (hey you might get lucky and it fills). Submitting two bracket orders would keep all your orders the same.

Regarding the C# implementation, I’m not familiar with that SDK. Maybe someone else here could help?

1 Like

.NET SDK has Wiki pages and most top-level questions are covered there. For instance, different helper methods for order creation are covered on this page.

1 Like