Alpaca bracket orders from a webhook alert

Autoview · Guide · Updated October 4, 2026

A bracket order puts your entry, your stop loss and your take profit into Alpaca as one order. The entry fills first. Then both exits go live, and when one of them fills, Alpaca cancels the other. You don't need a second alert to set the exits, and you can't end up with a stop that outlives its position.

Plenty of traders build this with their own small server, often FastAPI, that turns a TradingView alert into Alpaca's order JSON. That works, but you own the code, the hosting and every edge case. With Autoview, the alert message holds a short command and Autoview builds the bracket for you. The alert can come from TradingView, a script or any tool that can send a webhook.

The command

This buys 10 shares of AAPL at market, with a stop 2% below and a target 4% above:

e=alpaca s=AAPL b=buy q=10 t=market sl=-2% tp=4% d=1

What each part does:

  • e=alpaca is your live Alpaca account. Use e=alpaca-paper for a paper account.
  • b=buy q=10 t=market is the entry: buy 10 shares at market. Leave out t=market and the entry is a limit order instead.
  • sl=-2% is the stop loss and tp=4% is the take profit. When a command has both, Autoview sends a bracket. You don't need an extra switch for it.
  • d=1 is a dry run. Autoview logs the order it would send and stops there. Take it out when the log looks right.

Prefer exact prices over percentages? Use the fixed forms. TradingView can fill them from your alert, for example fsl={{plot_0}}, or you can type numbers:

e=alpaca s=AAPL b=buy q=10 t=market fsl=180.50 ftp=195 d=1

Want the stop to be a stop-limit instead of a plain stop? Add px= or fpx= for the limit price on the stop leg.

Put the command in the alert's message box and your Autoview webhook URL in its webhook field. The alert setup guide covers both fields.

What Autoview sends to Alpaca

If you've built this yourself, this part will look familiar. Autoview turns the command into a single request to Alpaca's orders endpoint. Here's how the pieces map:

In the commandIn the Alpaca order
s=AAPL b=buy q=10symbol, side: "buy", qty: 10
t=market, or no t=type: "market", or type: "limit" with a limit_price
Both sl= and tp=order_class: "bracket"
sl= or fsl=stop_loss.stop_price
px= or fpx=, with a stopstop_loss.limit_price
tp= or ftp=take_profit.limit_price
No tif= (a tif= value overrides it)time_in_force: "gtc" for stocks

Autoview also rounds each price to the symbol's tick size before it sends the order, which is one of the details a homemade receiver tends to miss.

Get the sign right

In Autoview, sl= and tp= aren't prices. They're offsets added to the current price, so the sign is the direction:

  • Long: the stop goes below and the target above, so sl=-2% tp=4%.
  • Short: flip both, so sl=2% tp=-4%.

The current price here is the quote Autoview reads at send time. For a market buy that's the ask, and for a limit buy it's the bid. If you pass price=, Autoview measures from that instead.

A plain number works the same way. sl=-1.5 puts the stop $1.50 under the price, not at $1.50. When you mean an exact price, use fsl= or ftp=. The stop-loss, take-profit and trailing stop guide has more on this.

Rules Alpaca enforces on brackets

Autoview passes the order on as written, so Alpaca's own rules decide whether it's accepted. From Alpaca's order docs (checked October 4, 2026):

  • Time in force must be day or gtc. Autoview defaults to gtc for stocks. Don't add t=ioc or t=fok to a bracket.
  • No extended hours. Alpaca doesn't support brackets outside regular hours. Autoview reads eh=1 only on orders that aren't brackets, so it won't help here.
  • The exits must sit on the right sides. For a buy, the take profit has to be above the stop. For a stop-loss sell, Alpaca wants the stop at least $0.01 below the base price, and above it for a buy.
  • Stocks are the safe case. Alpaca's crypto page lists market and limit orders plus stop limit orders. It doesn't list brackets. Treat this guide as a stocks guide, and dry-run anything else first.

One exit only, or exits for a position you already hold

Alpaca has two cousins of the bracket, and Autoview can send both:

  • OTO, one exit only. Add oto=1 and give either a stop or a target, not both. Alpaca's docs describe it as an entry plus one exit.
    e=alpaca s=AAPL b=buy q=10 t=market oto=1 sl=-2% d=1
  • OCO, exits for a position you already hold. Add oco=1 with both a stop and a target. Alpaca says an OCO is two exit orders on the same side, and its type must be limit, so leave out t=market. For a long position the side is sell:
    e=alpaca s=AAPL b=sell q=10 oco=1 sl=-2% tp=4% d=1

Read the dry-run log for either one before you take d=1 off. The log shows the order class and every price Autoview is about to send.

Trailing stops are separate

A bracket can't carry a trailing stop through Autoview. The bracket is built from sl= and tp= only, and ts= isn't read there.

Without a bracket, a command with ts= sends a trailing stop on its own, and it goes on the opposite side of b=. So b=buy ts=2% sends a sell trailing stop that protects a long you already hold. It doesn't open a new position. The same goes for sl= or tp= on their own, without the other one or an oco=1 or oto=1: Autoview sends a single exit order, not an entry. Match q= to your position size, and note that Alpaca says trailing stops don't trigger outside regular market hours.

Test it before it trades

  1. Connect a paper account and use e=alpaca-paper. The Alpaca paper trading guide covers the keys.
  2. Fire the alert once with d=1 and read the log. Check that it shows a bracket with both exit prices where you expect them.
  3. Remove d=1 and let it fire on paper. In Alpaca, the entry should show with two exits waiting behind it.
  4. When paper behaves, switch e=alpaca-paper to e=alpaca.

New to Alpaca on Autoview? Start with getting started with Alpaca, then come back here.

A note on what Autoview is. Autoview is an execution tool, not a trading or investment advisor. It places the orders your alerts and workflows tell it to; it doesn't generate signals or make any claim about results. Trading carries risk of loss, and you're responsible for the strategy you automate. See our disclosures.

Connect Alpaca