As of July 2026, the fastest way to automate TradingView alerts to OANDA is a webhook bridge: your Pine Script strategy fires an alert, TradingView POSTs a JSON payload to a small server you control, and that server calls OANDA’s v20 REST API to place the order. OANDA also has a native TradingView integration, but that one is for trading manually from the chart — it does not auto-execute your alerts. For hands-off forex automation you need the alert → bridge → v20 API path, and this guide walks through every piece with working code.
I’m Jayadev Rana, a TradingView-certified Pine Script developer. Over 8+ years I’ve shipped 7,700+ strategies for clients in 14+ countries, and OANDA bridges are one of the most common builds European traders ask me for.
Native OANDA integration vs. webhook automation — know the difference
OANDA has completed its broker integration with TradingView, so from a chart you can open the trading panel, select OANDA, and place forex and CFD orders by hand without leaving TradingView. In Europe this runs through OANDA’s CFD account type. It’s genuinely useful for discretionary trading.
But here’s the distinction that trips people up: the native integration is manual. Clicking "Buy" on the panel sends an order; a Pine Script alert() firing does not. If you want your strategy’s signals to reach OANDA with no human in the loop, you need a webhook that posts to a bridge, and the bridge talks to the v20 REST API. That is what the rest of this guide covers.
| Feature | Native OANDA + TradingView | Webhook → v20 bridge |
|---|---|---|
| Execution | Manual click from chart | Automated from alerts |
| Runs your Pine strategy hands-free | No | Yes |
| Needs a server / bridge | No | Yes |
| TradingView plan | Free tier works for manual | Essential+ (webhooks) |
| Best for | Discretionary trading | Systematic / algo trading |
What you need before you start
- An OANDA account — start with a practice (demo) account so you can test against fake money.
- A v20 personal access token, generated from My Account → My Services → Manage API Access. Treat it like a password; a single token grants access to all of your sub-accounts and does not expire unless you revoke it.
- Your account ID (it looks like
101-004-1234567-001). - A TradingView plan that supports webhooks — as of 2026 that is the Essential tier or higher. The free plan only sends pop-up and email alerts.
- A small always-on server (a cheap VPS or a serverless function) to host the bridge.
OANDA v20 REST API essentials
Two things to get right first: the base URL and the auth header.
Base URLs (note the path says v3 even though the API is branded "v20"):
- Practice:
https://api-fxpractice.oanda.com - Live:
https://api-fxtrade.oanda.com
To place an order you POST to the Orders endpoint with a Bearer token:
POST /v3/accounts/{accountID}/orders
Authorization: Bearer YOUR_V20_TOKEN
Content-Type: application/json
The same endpoint handles market, limit, stop, trailing-stop and guaranteed-stop-loss orders, so once the bridge speaks to it you can extend your strategy freely.
The alert → bridge → OANDA flow
1. Pine Script v6 strategy with an alert message
In Pine Script v6 you attach a JSON string to each entry via alert_message, then reference it in the alert dialog. Here’s a minimal EMA-cross example:
//@version=6
strategy("OANDA EUR/USD Bridge Demo", overlay=true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
longCond = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)
if longCond
strategy.entry("Long", strategy.long,
alert_message = '{"secret":"CHANGE_ME","side":"buy","instrument":"EUR_USD","units":"1000"}')
if shortCond
strategy.entry("Short", strategy.short,
alert_message = '{"secret":"CHANGE_ME","side":"sell","instrument":"EUR_USD","units":"1000"}')
When you create the alert, set the message to {{strategy.order.alert_message}} and paste your bridge URL into the Webhook URL field. One detail I always double-check is the alert frequency, so I don’t fire duplicate orders on the same bar — I broke that down fully in once per bar vs. once per bar close.
2. The TradingView webhook JSON payload
When the alert fires, TradingView sends exactly what is in the message. Your bridge receives a payload like this:
{
"secret": "CHANGE_ME",
"side": "buy",
"instrument": "EUR_USD",
"units": "1000"
}
TradingView only sets the application/json content-type when the message parses as valid JSON, so a stray comma will break parsing on the bridge side. I include a secret field and reject any payload that doesn’t match — the webhook URL is effectively public, so that shared secret is your only gate against someone else spraying orders at it.
3. The OANDA v20 order request body
The bridge maps side to the sign of units (positive = long, negative = short) and POSTs this body to OANDA:
{
"order": {
"type": "MARKET",
"instrument": "EUR_USD",
"units": "1000",
"timeInForce": "FOK",
"positionFill": "DEFAULT"
}
}
A full request from the command line looks like this (practice host shown):
curl -X POST "https://api-fxpractice.oanda.com/v3/accounts/101-004-1234567-001/orders" -H "Authorization: Bearer YOUR_V20_TOKEN" -H "Content-Type: application/json" -d '{"order":{"type":"MARKET","instrument":"EUR_USD","units":"1000","timeInForce":"FOK","positionFill":"DEFAULT"}}'
The single most common bug I fix in OANDA bridges is the sign of the units field. Positive units open a long, negative units open a short, and one missing minus sign silently flips every short into a long. I also default to FOK (fill-or-kill) time-in-force on forex majors, so a partially fillable order is rejected cleanly instead of leaving me holding a half-size position.
Want this bridge built, tested and deployed for your OANDA account? Message me on WhatsApp at +91 77352 68199 and I’ll scope it with you.
Test on practice before you ever touch a live token
Every bridge I ship gets wired to api-fxpractice.oanda.com first. I fire 20–30 test alerts, confirm the order IDs come back in OANDA’s response, check the fills on the account, and only then swap in the live token and the api-fxtrade.oanda.com base URL. It costs about an hour and it has saved every client from expensive first-day surprises. The same pattern works for other venues — I documented a near-identical build for Interactive Brokers, and if you’d rather route to MetaTrader I cover that under MT4/MT5 automation. The Pine Script side is shared across all of them.
EU and UK regulatory notes for forex/CFD traders
If you are trading from Europe, automation does not change the rules your account operates under. Under ESMA’s retail measures, leverage on major currency pairs is capped at 30:1 (20:1 for non-major pairs and gold), with negative-balance protection and a margin close-out rule set at 50% of required margin per account. The UK’s FCA adopted equivalent caps — 30:1 on major forex pairs — after Brexit. Professional-client accounts can access higher leverage but give up some of these protections. I mention this neutrally: know which OANDA entity and account category you are trading under before you automate, because your bridge will happily send whatever size you code.
Frequently asked questions
Can TradingView place OANDA trades automatically without a bridge?
No. OANDA’s native TradingView integration lets you trade manually from the chart’s trading panel. To auto-execute Pine Script alerts you still need a webhook posting to a bridge that calls the v20 API.
Do I need a paid TradingView plan?
Yes for automation. Webhook URLs on alerts require the Essential tier or higher as of 2026; the free plan only supports pop-up and email alerts.
Is OANDA’s v20 API free to use?
OANDA provides v20 REST API access to account holders and you generate the personal access token from your profile at no extra charge that I’m aware of, but pricing and terms vary by region — always confirm the current details with OANDA before you rely on them.
Which OANDA endpoint places the order?
POST to /v3/accounts/{accountID}/orders with a Bearer token. Use the api-fxpractice.oanda.com host for demo and api-fxtrade.oanda.com for live.
Can you build and maintain the whole setup for me?
Yes — custom Pine Script strategies, the webhook bridge, and OANDA order routing are exactly what I do. See my Pine Script development and strategy development services for scope and turnaround.
Ready to automate your OANDA forex strategy end to end? Message me on WhatsApp at +91 77352 68199 and let’s get your bridge live.
Risk disclaimer: Trading forex and CFDs on leverage carries a high risk of rapid loss and is not suitable for everyone. Under ESMA and FCA rules, a large share of retail CFD accounts lose money. Automated systems can fail, misfire, or execute unintended orders. Nothing in this article is financial advice or a promise of profit. Test on a practice account, never risk money you cannot afford to lose, and confirm all API details and regulations with OANDA for your region.

Leave a Reply