TradingView webhooks to your broker API
Write a Pine Script strategy with Claude or ChatGPT, validate it in TradingView’s Strategy Tester, then route its alerts through a webhook to a cloud runtime that calls your broker’s REST API directly. No MetaTrader terminal, no Windows VPS.
TradingView alerts can POST a JSON body to any HTTPS URL you control. TradingHost hosts that URL as an always-on container, parses the payload, and submits the order to the broker. Broker-agnostic by design: forex and CFD brokers, stock and futures brokers, and crypto exchanges all work the same way, as long as the broker publishes a REST or websocket API.
Latency expectation: TradingView’s server-side alert fires within roughly 1 to 3 seconds of the bar closing, then your broker’s REST endpoint adds its own order acknowledgement (typically 100 to 500 ms). End-to-end round trip is a few seconds, not a few milliseconds. The workflow fits swing, positional and slow intraday strategies; it is not the right path for scalping, latency arbitrage or sub-minute execution.
Section 01 · How it fits together
Four pieces, one loop
The whole workflow runs on four tools that each do one job. TradingView decides when to trade. GitHub stores the receiver code. TradingHost runs that code in the cloud and hosts the webhook URL. The broker executes the order. Once you can name which tool does what, every other section here is a detail you can skim.
Your chart and signal source
TradingView
Hosts your Pine Script strategy, runs the Strategy Tester, and fires alerts when entry or exit conditions hit. Alerts can POST a JSON payload to a webhook URL.
Your receiver code
GitHub
Stores the small receiver service that parses the TradingView payload and calls the broker REST API. Version-controlled, private if you want it.
Your cloud runtime
TradingHost
Pulls the receiver code from GitHub, builds a container, and exposes a stable HTTPS webhook URL that TradingView can POST to. Always on. No desktop to keep open.
Your execution venue
Broker API
Receives the order from your TradingHost container over the broker’s REST API. Broker-agnostic: any broker or exchange with a documented REST or websocket API works the same way.
From zero to a live signal
- Write a Pine Script strategy on TradingView, with Claude or ChatGPT pair-writing the code.
- Backtest the strategy in TradingView’s Strategy Tester before considering it live.
- Fork a TradingHost webhook receiver starter into your GitHub account and customise it for your broker.
- Point a TradingHost runtime at the repo and pick a region; the runtime exposes a public webhook URL.
- Create a TradingView alert on the strategy, paste the webhook URL, set the message body to JSON with the strategy.order placeholders.
- When the alert fires, TradingView POSTs to TradingHost, your container parses the payload, and your broker API call places the order.
Round-trip timing: TradingView’s server-side alert fires 1 to 3 seconds after a bar closes, and the broker REST endpoint typically acknowledges an order in 100 to 500 ms. End-to-end you are looking at single-digit seconds, not milliseconds. This is fine for swing and slow-intraday strategies; it is not the right fit for scalping or latency arbitrage.
Section 02 · At a glance
At a glance
- Workflow
- TradingView Pine Script alert to cloud webhook receiver to broker REST API
- Pine Script version
- Pine Script v6 (current TradingView language version)
- Alert transport
- HTTPS POST to a user-supplied webhook URL
- Allowed ports
- TradingView delivers to ports 80 and 443 only; other ports are rejected
- Response timeout
- Receiver must respond within three seconds or the request is cancelled
- Payload format
- Body of the alert message; sent as application/json when the body is valid JSON
- Strategy placeholders
- {{strategy.order.action}}, {{strategy.order.contracts}}, {{ticker}}, {{close}}, and similar
- Required plan tier
- TradingView Plus, Premium or Ultimate (Essential and free do not include webhooks)
- Account requirements
- Two-factor authentication must be enabled on the TradingView account
- Receiver runtime
- Containerised always-on service on TradingHost, deployed from GitHub
- Languages
- Any language that can run a small HTTP server in a container (Python, Node, Go, Rust, etc.)
- Broker support
- Broker-agnostic: any broker or exchange with a documented REST or websocket API (forex, CFD, stocks, futures, crypto)
- Example broker
- OANDA v20 REST API is used as a brief, low-maintenance illustration of the receiver-to-broker call; the page is not OANDA-specific
- TradingHost role
- Runtime, deployment, logs, health checks, region selection, encrypted broker credentials
- TradingView role
- Charting, Pine Script execution, alert generation, webhook delivery
- Affiliation
- TradingHost is independent and is not affiliated with TradingView, PineConnector, OANDA or any other named service
Section 03 · Write Pine Script with AI
Pair-write the strategy with Claude or ChatGPT
Pine Script is a small, well-documented language and the current generation of large language models have all read TradingView’s public Pine Script v6 reference. Describe the strategy in plain English in Claude or ChatGPT (or in Cursor with either model behind it): what to monitor, what triggers a long, what triggers a short, how to size the order, when to exit. Paste the generated code into TradingView’s Pine Editor and let the editor flag syntax issues.
Two things to be explicit about with the model. First, ask for a Pine Script strategy script (it must declare strategy() rather than indicator()), because only strategies expose the {{strategy.order.action}} and {{strategy.order.contracts}} placeholders you will need in the webhook body. Second, ask the model to fire its entries with strategy.entry() and exits with strategy.close(), and to write any ad-hoc notifications with the alert() function rather than alertcondition(); the modern alert() function exposes the same strategy placeholders and accepts a freq argument that controls whether the alert fires on every tick, once per bar, or once per bar close.
Read every line the model writes. Trading code is unforgiving of subtle bugs around order sizing, position state and intra-bar behaviour. Ask the model to explain any non-obvious calculation before you accept it. If you want a deeper AI-IDE flow (Pine plus a Python or Go receiver, both in one editor), the Cursor workflow page covers the IDE side of the same loop.
Section 04 · Backtest before going live
Run the Strategy Tester before you wire the webhook
TradingView’s Strategy Tester runs your Pine Script strategy across the chart’s available history, reporting net profit, profit factor, drawdown, win rate and a full list of synthetic trades. The Performance Summary, List of Trades and Properties tabs give you enough to decide whether the strategy is worth wiring up to a real broker.
Do this step before you create any TradingView alert with a webhook URL. A live webhook on an unvalidated strategy is the most expensive way to discover a bug.
Section 05 · Alerts and webhooks
Configure the TradingView alert and webhook URL
Open the Create Alert dialog on your chart, pick the strategy as the condition, then switch to the Notifications tab and tick Webhook URL. Paste the TradingHost webhook endpoint as the URL. The body you type into the Message field is what TradingView will POST to that URL when the alert fires.
Write the Message as JSON. TradingView detects valid JSON automatically and sets the request Content-Type to application/json, which is what your receiver expects. A minimal strategy alert body carries the ticker, the side (from {{strategy.order.action}}), the size (from {{strategy.order.contracts}}), and a shared secret that your receiver checks before forwarding anything to the broker.
Transport rules TradingView documents
- Method
- HTTP POST. The alert message body is sent as the request body.
- Ports
- Ports 80 and 443 only. Webhook URLs with any other explicit port are rejected.
- Content-Type
- application/json when the alert message body is valid JSON. Otherwise plain text.
- Timeout
- Three seconds. If the receiver does not respond inside that window the request is cancelled.
- Source IPs
- TradingView publishes its outbound webhook IP addresses on the alert configuration screen. Whitelist them on your firewall or webhook receiver.
- Account
- Webhook alerts require two-factor authentication on the TradingView account.
- Plan tier
- Webhook alerts are gated to the Plus, Premium and Ultimate plans. The Essential and free tiers do not include the webhook delivery method.
Alert message placeholders
- {{ticker}}
- Symbol shown on the chart at the time of the alert.
- {{exchange}}
- Exchange code, where applicable.
- {{close}}
- Closing price of the bar that fired the alert.
- {{volume}}
- Volume of the bar that fired the alert.
- {{time}}
- Bar open time in UTC.
- {{strategy.order.action}}
- Returns "buy" or "sell" for the strategy order that fired. Strategy alerts only.
- {{strategy.order.contracts}}
- Number of contracts or units in the executed order. Strategy alerts only.
- {{strategy.order.price}}
- Fill price reported by the strategy. Strategy alerts only.
- {{strategy.order.id}}
- Identifier the strategy assigned to the order. Strategy alerts only.
- {{strategy.order.comment}}
- Optional comment string the strategy attached to the order.
One Pine Script subtlety worth knowing: indicator scripts can fire alerts with alertcondition() or alert(), but only strategy scripts expose the {{strategy.*}} placeholders. If you want the webhook body to carry the side and size of the trade, the script must declare strategy(), not indicator().
Section 06 · Receive on TradingHost
Host the webhook URL on a runtime, not on your laptop
The webhook URL TradingView posts to has to be online whenever the market is open. A laptop is the wrong place for it; a desktop machine with a flaky internet connection is the wrong place for it; and a generic Windows VPS works, but only as long as you remember to keep it patched and the relevant terminal running.
TradingHost gives you a Kubernetes-backed Linux container that runs from a GitHub repo and exposes a stable HTTPS endpoint. Your receiver code is whatever you want (a Python FastAPI handler, a Node Express route, a Go net/http server), as long as it speaks HTTP on port 443 and responds inside TradingView’s three-second window. When you push code to GitHub, TradingHost rebuilds the container and redeploys; the webhook URL stays the same.
Broker API credentials live as encrypted secrets on the runtime, not inside your GitHub repo. The shared secret you put in the TradingView Message body lives there too. Your receiver validates the shared secret on every inbound request, then reads the broker credentials from the environment and calls the broker API.
Logs are streamed back so you can see, in order: TradingView posted, payload parsed, order submitted, broker confirmed. If anything fails, the log line says where.
Section 07 · Execute on the broker
Any broker with an API; the receiver shape does not change
TradingHost is broker-agnostic. The TradingHost container does not care which broker sits behind the REST endpoint it calls; the same receiver shape works whether the destination is a forex broker, a stock broker, a futures broker, or a crypto exchange. What differs is the authentication scheme, the instrument symbology, and the order-type vocabulary the broker exposes. Everything else stays the same.
Broker families this workflow supports
- Forex and CFDs
- Brokers with v20-style REST APIs and similar (OANDA, IG, Switch Markets and others on /brokers/forex-and-cfd/).
- Stocks and futures
- Brokers with REST or FIX gateways (Interactive Brokers and others on /brokers/stocks-and-futures/).
- Crypto exchanges
- Spot and derivatives venues exposed as REST plus websocket (Binance, Bybit, OKX, Coinbase, Kraken and 60+ more on /brokers/crypto/, mostly via CCXT).
- Anything else
- Any broker with a documented HTTP order interface. The receiver pattern below does not change.
What the receiver does on every inbound webhook
- Validate the shared secret from the TradingView alert body before forwarding anything.
- Map the TradingView ticker to the broker’s instrument code (most brokers use a slightly different symbology).
- Build the order request with the side encoded in the size sign, a market order type, and the broker’s recommended time-in-force.
- Send the request with the broker’s authentication header (Bearer token, HMAC-signed payload, OAuth, depending on the broker).
- Log the response, surface errors, and return a fast 200 OK to TradingView inside the three-second timeout.
A brief illustration: OANDA v20
OANDA is a low-maintenance worked example because its v20 REST reference is fully documented at developer.oanda.com and free practice accounts are easy to open. The shape: a Bearer personal access token in the Authorization header, a POST to /v3/accounts/{accountID}/orders with a market order body, against api-fxtrade.oanda.com for live or api-fxpractice.oanda.com for practice. That is one broker out of many; the receiver code for Interactive Brokers, Binance, OKX or Switch Markets follows the same pattern with that broker’s auth scheme and endpoint. The /brokers/ pages cover the per-broker specifics.
Section 07.5 · Operational safety
Things that bite you when real money is on the line
TradingView alert delivery is best-effort. Webhooks can be dropped, repeated, or delayed. Broker APIs can return retries that look the same as a fresh order. Pine Script bugs can produce position sizes far outside the strategy’s intended risk. The receiver is where you put the seatbelt. Six guardrails below; each is a small piece of receiver code that prevents a failure mode the trader cannot fix once it has shipped.
01 · Receiver downtime
What happens if the receiver was down when an alert fired?
TradingView does not queue or retry failed webhook deliveries by default. If the receiver returns a non-2xx response, or takes longer than three seconds to respond, the alert is dropped. The strategy continues firing alerts on later bars, but the missed signal is gone. Guardrail: keep the receiver as simple as possible so it always responds within the timeout, log every incoming payload to disk before doing any work so a missed order shows up in the runtime logs, and monitor the runtime uptime so you know if the receiver was unreachable when a signal fired.
02 · Duplicate alerts
TradingView can fire the same alert more than once
Pine Script values update on every tick inside a live bar. An alertcondition or alert call set to "Every tick" can fire multiple times on the same logical signal. Even with "Once per bar close" set, TradingView retries can occasionally deliver the same payload twice in a row. Guardrail: include a stable identifier in the alert body (the bar time, the order ID generated by the strategy, or a hash of the payload) and reject any incoming payload whose identifier the receiver has already processed in the last few minutes. Keep that dedupe key in memory or in a small key-value store inside the runtime.
03 · Order idempotency
Design every broker call so a retry does not create a duplicate position
Most broker REST APIs accept an idempotency key, a client-supplied order ID that the broker uses to deduplicate the same submission across retries. Set this on every order the receiver places. Use the same identifier you use for alert dedupe (the bar time or the strategy-generated order ID) so the receiver, TradingView, and the broker all agree on which logical order is which. Without this, a retry triggered by a transient network blip can double-fill the position.
04 · Position-size guard
Cap the size you trust from {{strategy.order.contracts}}
Pine Script’s strategy.order.contracts placeholder reports the size the strategy thinks it is trading. A bug in the strategy logic, a misconfigured position size, or a runaway loop can produce a contracts value far larger than the account can carry. Guardrail: hardcode a maximum size in the receiver, separate from the strategy, and reject any order whose contracts value exceeds it. The receiver is the last line of defence between a Pine bug and a margin call.
05 · Credential isolation
One scoped API key per strategy, never a master key
If a broker API key gets compromised through a misconfigured environment, a leaked log line or a build artifact, the blast radius is whatever the key can do. Use a separate broker API key per strategy with only the permissions that strategy needs (trade scope yes, withdrawal scope no), store it in the TradingHost secrets store rather than in code, and rotate keys after any incident.
06 · Paper before live
Run the loop against a paper account for a week before sizing up
Most brokers offer a paper trading or sandbox environment that takes the same API calls as the live account. Point the receiver at the sandbox first, run the strategy through a week of real TradingView alerts and verify that every signal turned into the expected paper order. Live money is the wrong place to discover that {{strategy.order.action}} encoded as "buy" instead of "long" trips your enum check.
Section 08 · Vs PineConnector + MT4/MT5
Why route a webhook through a cloud runtime instead of a MetaTrader EA
The most common existing path from a TradingView alert to a real order goes through PineConnector, a third-party bridge that forwards alerts to an Expert Advisor inside a MetaTrader 4 or MetaTrader 5 terminal. The EA submits the order through MetaTrader, so the terminal has to stay running on a Windows machine. TradingHost removes that leg entirely: the webhook lands on a container, the container calls the broker REST API, and there is no MetaTrader terminal, no MQL Expert Advisor, GitHub as the source of truth, and a Linux container running in a managed region rather than a Windows desktop you have to keep awake.
Side by side
Pick PineConnector if you specifically want to keep using MetaTrader, your broker is MT-only, or you do not want to write any code at all. Pick TradingHost if you want broker REST API access without MetaTrader in the middle, want strategies written in a general-purpose language, want GitHub as the source of truth, and want to retire the Windows VPS.
Section 10 · FAQ
Frequently asked questions
Yes. TradingView gates webhook alerts to the Plus, Premium and Ultimate plans. The Essential and free tiers do not include the Webhook URL notification method.
TradingView sends an HTTP POST to the webhook URL you configured. The request body is whatever you typed into the alert Message field. If that body parses as valid JSON, TradingView sets the Content-Type to application/json; otherwise the request is plain text.
TradingView does not document a retry policy or formal delivery guarantee. The transport rules it does document are: ports 80 and 443 only, and a three-second response window before the request is cancelled. Treat webhook delivery as best-effort and design your receiver to be idempotent.
You can. TradingView publishes the list of source IP addresses it sends webhooks from on the alert configuration screen. Some receivers reject any request from outside that list as an extra defence beyond the shared secret in the message body.
Pine Script v6, the current language version. TradingView has stated that future updates are applied exclusively to v6.
Only strategy scripts expose the {{strategy.order.action}}, {{strategy.order.contracts}}, {{strategy.order.price}} and similar placeholders you will use in the JSON body. Indicator scripts can still fire alerts via alert() or alertcondition(), but their alert messages cannot reference the strategy.* placeholders.
alertcondition() is the original primitive and works in indicators only; its frequency is chosen by the user in the Create Alert dialog. alert() is the newer function, works in indicators and strategies, can sit in local scope, and takes a freq argument (alert.freq_all, alert.freq_once_per_bar, alert.freq_once_per_bar_close) directly in code.
For live trading, prefer once per bar close. During a real-time bar, Pine values can update on every tick and may differ at bar close, which can fire an entry that then disappears when the bar finalises. Once per bar close fires only when the bar is confirmed.
PineConnector forwards TradingView webhooks to a MetaTrader 4 or MetaTrader 5 Expert Advisor running inside a MetaTrader terminal. PineConnector’s own docs note that the terminal must be running continuously, that MetaQuotes VPS is not compatible, and that a Windows VPS is required for hosting. TradingHost replaces the MetaTrader leg with a Linux container that calls the broker REST API directly. See the Windows VPS comparison for the runtime difference.
Any broker with a documented REST or websocket order interface. TradingHost is broker-agnostic: forex and CFD brokers (OANDA, IG, Switch Markets and others), stock and futures brokers (Interactive Brokers and others), and crypto exchanges (Binance, Bybit, OKX, Coinbase, Kraken and more). See the brokers index for the supported venues.
Only the broker-specific bits: the authentication header (Bearer token, HMAC-signed payload, OAuth), the instrument symbology, and the order-type vocabulary. The overall shape (validate secret, map ticker, build order, send, log) is the same. For crypto venues, CCXT abstracts most of the difference away.
Encrypted secrets attached to the TradingHost runtime, not in the GitHub repo. Your receiver reads them from the environment at request time. See the platform secrets page for the credential handling model.
TradingView, your broker, and TradingHost are billed separately. TradingHost’s runtime plans are listed on pricing. You stop paying for a Windows VPS, a MetaTrader-hosting tier and a separate webhook bridge license.