How to Place a Bracket Order to Manage Entry & Exit?
An informative guide on how to place a bracket order - a chain of three orders that can be used to manage your position entry along with a target-exit and stop loss order.
This tutorial is a step by step demonstration on how to place a Bracket order and is part of the Alpaca 101 Tutorial Series. We will move forward assuming that you’ve registered on the Alpaca website. If you haven’t please visit Alpaca and sign up. Feel free to check out the other tutorials in this series at Alpaca Resources.
What is a Bracket order?
A Bracket order is a chain of three orders that can be used to manage your position entry along with a target-exit and stop loss order. It is a common use case of an OTOCO (One Triggers OCO {One Cancels Other}) order.
The first order within bracket order is a long/short order to enter a new position, and once it is filled, either of the last two conditional orders are activated. One of the two closing orders is called a take-profit order, which is a limit order, and the other is called a stop-loss order, which is either a stop or stop-limit order. Importantly, only one of the two exit orders can be executed. Once one of the exit orders is filled, the other is canceled.
How to Create a Bracket Order
Step 1:
Log in to your Alpaca account and click on “Paper Overview”. That should lead to a web page as shown in the picture below.
As we can see, a new paper trading account has a starting equity of $100,000 and a buying power of $400,000. These can be reset at any time during your usage by clicking the “Reset” button and they will return back to their original equity of $100,000 and a buying power of $400,000 respectively.
Step 2:
Let’s create a class called “pythonBuyBot” and paste our code for the endpoints in the class.
Step 3:
Similarly let’s create a function to place a bracket order. Within this bracket order, our first order will be to buy one stock of Apple(AAPL), add a stop-loss and take-profit of 5%.
One can find similar code in the Alpaca Docs
Step 4:
Below find a GIF showing everything we have discussed today:
After running the code, this is what your portfolio and order history could look like (prices can vary).
Thank you for using Alpaca. Here are a couple more links that you might be interested in.
Sign up for the weekly newsletter to keep up with the API updates and upcoming competitions, job opportunities by clicking here.
You can also follow Alpaca and our weekly updates on our LinkedIn, Alpaca Community Slack and @AlpacaHQ on Twitter!
Commission-Free trading means that there are no commission charges for Alpaca self-directed individual cash brokerage accounts that trade U.S. listed securities through an API. Relevant SEC and FINRA fees may apply.
Brokerage services are provided by Alpaca Securities LLC ("Alpaca"), memberFINRA/SIPC, a wholly-owned subsidiary of AlpacaDB, Inc. Technology and services are offered by AlpacaDB, Inc.