Alpaca Guide
Connect TradingView to Alpaca (stocks & forex) using TradeAdapter’s direct API integration. This guide covers strategy and indicator alerts with the Message Generators.
Video walkthrough #
Alpaca + TradingView setup
1 — Create Alpaca account and API keys #
Alpaca is a US broker for stocks and forex. Create an account and generate API keys from the Dashboard.
-
Register at Alpaca
Go to alpaca.markets and complete registration. Confirm your email to verify the account.
-
Log in to the Dashboard
Once the account is activated, log in at app.alpaca.markets and open the Dashboard section.
-
Generate API keys
On the Dashboard you can generate keys for your Demo (Paper) account. Copy and store your API Key and Secret — you will use them in the alert message as
alpaca_api_keyandalpaca_api_secret. For live trading, use the keys from your live account.
2 — Select the Alpaca symbol in TradingView #
Open TradingView and search for the symbol using the Alpaca (or broker) prefix. Alpaca supports stocks and forex — the {{ticker}} placeholder will send this symbol to TradeAdapter.
Important
The symbol must be valid on Alpaca and match what you trade. Use order_market": "Spot" in your message.
3 — Add your strategy or indicator #
Alpaca supports both strategy and indicator alerts. Load your Pine Script onto the chart so it generates the trading signals.
Use the Alpaca Message Generator (Strategy). One alert with trigger “Order fills only”. TradingView fills action, size, and price via {{strategy.order.action}}, {{strategy.order.contracts}}, {{strategy.order.price}}.
Use the Alpaca Message Generator (Indicator). Set order_action and order size manually in the message. Create one alert per action (e.g. Buy, Sell).
Not sure if you have a strategy or an indicator? See Indicator vs Strategy.
4 — Configure order size #
Set your strategy’s position size so that {{strategy.order.contracts}} is valid for the symbol on Alpaca. For Limit orders, ensure {{strategy.order.price}} is in the correct format. For indicators, set the order size in the message accordingly.
5 — Create the TradingView alert #
Press Alt + A (or the alarm clock icon) to create a new alert.
Strategy → one alert
Under Condition, select your strategy and set trigger to “Order fills only”. TradingView fills action, size, and price via the strategy placeholders.
Alpaca: different Webhook URL for Demo vs Real
In Notifications, enable Webhook URL and paste one of these URLs from your TradeAdapter profile:
- Demo (paper):
https://tradeadapter.com/api/alpaca/demo_order - Real (live):
https://tradeadapter.com/api/alpaca/real_order
Paste the JSON message in the Message field. Build it with the Alpaca Message Generator (Strategy) or Alpaca Message Generator (Indicator).
Alert message (Strategy) #
Use this template for strategy-based alerts. Replace the placeholder values with your Alpaca API key and secret. Keep order_market as Spot. Keep the TradingView placeholders as-is.
{
"alpaca_api_key": "PUT YOUR ALPACA API KEY HERE",
"alpaca_api_secret": "PUT YOUR ALPACA SECRET HERE",
"real_order": "No",
"order_market": "Spot",
"order_type": "Market",
"isolated_margin": "No",
"exchange": "Alpaca",
"ticker": "{{ticker}}",
"time": "{{timenow}}",
"order_contracts": "{{strategy.order.contracts}}",
"order_action": "{{strategy.order.action}}",
"order_price": "{{strategy.order.price}}"
}
Message fields explained #
| Field | Description |
|---|---|
alpaca_api_key |
Your Alpaca API Key from the Alpaca Dashboard (paper or live). |
alpaca_api_secret |
Your Alpaca Secret. Store it securely and never share it. |
real_order |
"Yes" sends real orders to Alpaca. "No" sends test orders via TradeAdapter only. Use the matching Webhook URL (demo_order vs real_order) for your choice. |
order_market |
Use "Spot" for Alpaca. |
order_type |
"Market" or "Limit". For Limit orders, order_price is used as the limit price. |
isolated_margin |
Keep "No" for Spot. Only relevant if Alpaca supports margin in your setup. |
exchange |
Must be "Alpaca" so TradeAdapter routes the order to Alpaca. |
ticker |
The TradingView symbol from {{ticker}} (e.g. Alpaca symbol). |
order_contracts |
Position size from your strategy ({{strategy.order.contracts}}). |
order_action |
"BUY" or "SELL". Use {{strategy.order.action}} for strategies. |
order_price |
Price from the strategy ({{strategy.order.price}}), used for Limit orders. |
6 — Execute & monitor #
-
Start with demo
Use the demo_order webhook URL and set
"real_order": "No". Trigger a few alerts and check MyTrades to see how TradeAdapter interprets your signals. -
Switch to live when ready
Use the real_order webhook URL and set
"real_order": "Yes". Monitor your Alpaca account to confirm orders execute as expected. -
Recreate alerts after changes
If you change strategy parameters or the message, delete and recreate the TradingView alert so the new values are applied.
Important notes #
Correct Webhook URL — Demo account →
demo_order URL; Real account → real_order URL. Your TradeAdapter profile has both.
Recreate alerts after changes — If you change strategy/indicator parameters or message fields, delete and recreate the TradingView alert.
All setup guides