TradingView Webhook to MT4 and MT5: Building a Reliable Bridge
TradingView cannot place trades in MetaTrader by itself. To turn a TradingView alert into an MT4 or MT5 order you need a bridge: TradingView sends an HTTP POST (the webhook) to a server, and an expert advisor running in your terminal collects that message and places the trade. You can buy that bridge as a service or build it yourself, but either way the weak points are the same: delivery delays, missed alerts, bad position sizing and a terminal that is not running when the signal arrives.
Key takeaways
- A webhook is a one-way HTTP message from TradingView; MetaTrader has no public inbox, so something must receive the message and hand it to an EA.
- Webhook alerts need a paid TradingView plan and, at the time of writing, two-factor authentication on the account. Check TradingView's current plan page before you build around them.
- Calculate lot size inside MetaTrader from account equity and stop distance, not from the "contracts" figure in a Pine strategy.
- Your terminal must be online 24/5, which in practice means a VPS, and every leg of the chain needs logging so you can prove what happened to each alert.
- US accounts are subject to FIFO and no-hedging rules, so the bridge must close positions rather than open opposite ones.
What a TradingView-to-MetaTrader bridge actually does
When an alert condition triggers, TradingView can do several things: show a pop-up, send an email, push a notification to your phone, or call a webhook URL. The webhook option sends the alert's message text as the body of an HTTP POST request to any URL you supply. TradingView only delivers to standard web ports (80 for HTTP and 443 for HTTPS), and it expects the receiving server to respond quickly. Its documentation says requests are cancelled if the remote server takes more than about three seconds to answer, so the receiver should acknowledge immediately and process afterwards.
MetaTrader 4 and 5 are desktop programs. They do not listen for incoming web requests, and your home PC is usually behind a router that blocks unsolicited traffic anyway. So the bridge has three parts:
- Receiver. A small web service with a public HTTPS address. It accepts the POST from TradingView, checks it is genuine, and stores it in a queue.
- Transport. The EA in your terminal polls the receiver every second or two using MQL's
WebRequest()function, or a commercial bridge uses its own connection to push the message down. - Executor. The EA parses the message, applies your risk rules, checks spread and margin, sends the order, and reports back.
Everything you care about as a trader sits in step three.
Your three realistic options
Traders in the UK, Australia and the US generally end up with one of three setups. None is "best" in the abstract; it depends on your coding ability and how much you are willing to depend on a third party.
| Approach | How it works | Strengths | Weaknesses |
|---|---|---|---|
| Commercial bridge service | You paste the provider's webhook URL and licence key into TradingView; their EA runs in your MT4/MT5 and receives the signals | Quick to set up, usually supports partial closes, break-even and lot-sizing options, no server to maintain | Monthly fee, your signals pass through someone else's server, you are tied to their message syntax and uptime |
| Self-hosted receiver plus your own EA | A small server (for example a cloud function or a script on a VPS) queues alerts; your EA polls it with WebRequest | Full control, no subscription, you can log and validate exactly as you like | You must write and maintain both halves; bugs in your code become trading losses |
| Skip MetaTrader: broker trading inside TradingView | Connect a supported broker directly to TradingView and trade from the chart | No bridge at all for manual trading from charts | Alerts still cannot place orders by themselves through the native integration; full automation still needs an API-based bridge |
For manual chart trading, see our guide on connecting a broker to TradingView. Automation still needs one of the first two routes.
Designing the alert message
The message body is plain text that you write in the alert dialog. Most bridges expect either a short command string or JSON. JSON is easier to validate, so a typical self-built format looks like this:
{"key":"a-long-random-secret","symbol":"{{ticker}}","side":"{{strategy.order.action}}","price":"{{close}}","sl_pips":25,"tp_pips":50,"id":"{{timenow}}"}
The double-brace items are TradingView placeholders that are replaced at the moment the alert fires. {{ticker}} gives the chart symbol, {{close}} the bar's close, and the strategy.* placeholders are only available for alerts created from a Pine strategy rather than an indicator. A few practical rules:
- Map symbols explicitly. TradingView may call it EURUSD while your broker's MetaTrader symbol is EURUSD.r, EURUSDm or EURUSD.pro. Keep a mapping table in the EA rather than assuming names match. Gold is the classic trap: XAUUSD on the chart, GOLD or XAUUSD.s at the broker.
- Include a unique id. Network retries and accidental duplicate alerts happen. The EA should refuse to execute the same id twice.
- Send distances, not absolute prices, for stops. TradingView's data feed is not your broker's feed. A stop at 1.08250 computed from TradingView's price may sit inside the broker's spread or minimum stop distance. Sending "25 pips" and letting the EA anchor it to the broker's actual fill price is more robust.
- Keep secrets out of the chart. The secret key in the message is what stops strangers who discover your URL from sending fake orders. Use a long random string, and rotate it if you ever share a screenshot of the alert dialog.
Position sizing belongs in MetaTrader, not in Pine
Pine strategies size trades in "contracts" based on TradingView's simulated equity. That number has nothing to do with your live MetaTrader balance, your account currency or your broker's contract size. Passing it straight through is one of the most common ways a bridge oversizes a live account.
The safer pattern is to send the stop distance and let the EA compute lots from real equity. A worked example on EUR/USD, where one standard lot is 100,000 units and one pip is worth USD 10 per lot for a USD account:
| Input | Value |
|---|---|
| Account equity | USD 10,000 |
| Risk per trade | 1% = USD 100 |
| Stop distance from alert | 25 pips |
| Pip value per standard lot | USD 10 |
| Lots = 100 / (25 x 10) | 0.40 lots |
| Margin at 30:1 (UK/EU/Australia retail), EUR/USD at 1.0800 | 0.40 x 100,000 x 1.0800 / 30 = about USD 1,440 |
| Margin at 50:1 (US retail majors) | about USD 864 |
The EA should then round down to the broker's volume step (often 0.01), cap the result at a maximum you set, and refuse the trade if free margin is insufficient. For cross pairs and gold the pip value changes with price and account currency, so read SYMBOL_TRADE_TICK_VALUE and SYMBOL_TRADE_TICK_SIZE from the terminal rather than hard-coding USD 10. The position size calculator is a good way to sanity-check what your EA produces before you go live.
Setting it up step by step
1. Prepare the TradingView side
Write and test your indicator or strategy on the chart. Decide whether alerts should fire "once per bar close" or intrabar. Intrabar alerts can send an order for a signal that later disappears from the chart. Bar-close alerts are slower but match what you see historically.
2. Stand up the receiver
Whether it is a commercial URL or your own, it must be HTTPS on port 443, it must answer within a second or two, and it must log every request with a timestamp. If you self-host, reject any request without the correct key, and consider allowlisting the source IP addresses TradingView publishes for webhooks.
3. Install and permission the EA
Copy the EA into the MQL4 or MQL5 Experts folder, restart, attach it to one chart, and enable algorithmic trading. For a self-built EA you also need to add the receiver's URL under Tools, Options, Expert Advisors, "Allow WebRequest for listed URL", or every request will fail silently with error 4060 (MT4) or 4014 (MT5). The installation walkthroughs for MT4 and MT5 cover the folders and permissions in detail.
4. Move the terminal to a VPS
Alerts fire whether or not your laptop is awake. If the terminal is closed, signals are missed or, worse, a stale batch executes when you reopen it. A Windows VPS close to your broker's servers keeps the EA running 24/5. Compare providers in our forex VPS hosting guide.
5. Test on demo with deliberate failures
Do not just confirm that a buy alert produces a buy. Stop the receiver, send a duplicate id, an unknown symbol, and an alert while the market is closed. Each should produce a logged rejection, not a surprise position.
Latency and slippage: what to expect
A webhook chain adds delay at every hop: TradingView evaluating the alert, delivering the POST, your receiver queuing it, the EA's polling interval, and finally the broker's execution. In normal conditions the total is often a few seconds; during busy periods it can be longer, and TradingView does not guarantee delivery times. For a swing strategy on the four-hour chart, two seconds is irrelevant. For a scalping system targeting five pips, it can consume much of the edge, and the backtest on TradingView, which assumes fills at its own prices, will look better than live results.
Two habits help. Have the EA skip the trade if the broker price has moved more than a set threshold (say three pips on a major) from the alert price, and record alert time, order time and fill price for every trade so you know your real slippage.
Regional rules that change how the bridge must behave
United States
Retail forex in the US is only offered through firms registered with the CFTC and members of the NFA, and CFDs are not available to US retail traders. NFA rules impose first-in, first-out closing and prohibit holding simultaneous long and short positions in the same pair in the same account. A bridge that answers a "sell" alert by opening a short while a long is still open will be rejected or, depending on the broker, will net against the position. Design your messages so a "sell" means "close the long, then optionally open a short", and size in line with the 50:1 cap on majors and 20:1 on other pairs. Our list of CFTC-regulated forex brokers is the starting point for US accounts; check which of them offer MetaTrader at all, because availability has changed over time.
UK and Australia
FCA and ASIC rules cap retail leverage at 30:1 on major pairs, lower on minors, gold and indices, and require negative balance protection. Hedging is generally allowed. Remember that protection depends on the legal entity: an Australian trader onboarded to a brand's offshore entity does not get ASIC protections just because the brand also holds an ASIC licence.
Bridges and prop firms
Many traders want TradingView signals to drive a funded account. Prop firms vary a lot here. Some allow EAs and third-party bridges, some allow EAs but ban copying signals from others, and some prohibit any external automation during the evaluation. Firms also watch for identical trades across many accounts, which is exactly what a webhook feeding several terminals produces. Read the firm's rules, ask support in writing if unclear, and see our overview of prop firms that allow EAs. A breach discovered after a payout request can void the payout.
Building it yourself: what the EA must handle
If you go the self-built route, the polling EA is a few hundred lines in either language, though MQL4 and MQL5 differ enough in order handling that you should pick one. A minimal production checklist:
- Poll on a timer with
EventSetTimer(), not on ticks, so quiet markets do not delay processing. - Validate key, symbol, side and id before doing anything else.
- Check market open, spread limit, maximum open positions and daily loss limit.
- Normalise prices and volumes to the symbol's digits and volume step.
- Retry requotes a limited number of times, then give up and log it.
- Acknowledge each processed id back to the receiver so it is not handed out again.
- Write a readable journal line for every decision, including rejections.
Frequently asked questions
Can TradingView send orders to MT4 or MT5 without a third-party tool?
No. TradingView can call a webhook URL, but MetaTrader has no built-in way to receive it. You need either a commercial bridge, which supplies the receiving server and an EA, or your own receiver plus an EA that polls it with WebRequest. Both achieve the same result; the difference is cost, control and who maintains the code.
Do I need a paid TradingView plan for webhooks?
At the time of writing, webhook alerts are only available on paid TradingView plans, and TradingView also requires two-factor authentication on the account before webhooks can be used. Plan features and alert limits change, so confirm on TradingView's official pricing page before you build around them.
How fast is a TradingView to MetaTrader webhook?
Typically a few seconds from alert to order in normal conditions, but there is no guaranteed delivery time. The total depends on when the alert evaluates, TradingView's delivery, your receiver, the EA polling interval and broker execution. That is fine for swing and intraday systems but a real cost for scalping, so measure it on demo before trusting backtests.
Why did my alert fire but no trade open?
The usual causes are: the URL is not on MetaTrader's WebRequest allowlist, algorithmic trading is switched off, the symbol name does not match the broker's, the market was closed, the lot size was below the minimum or above free margin, or the terminal was offline. A bridge with proper logging tells you which one in seconds.
Is it safe to put my webhook URL in TradingView?
The URL itself is stored in your TradingView account, but anyone who learns it could send fake signals. Protect it with a long secret key inside the message, reject anything without that key, use HTTPS, and consider allowlisting TradingView's published source IP addresses. Never post screenshots of the alert dialog with the key visible.
Can I use a webhook bridge on a prop firm account?
Sometimes. Rules vary by firm and sometimes by account phase. Some allow EAs and bridges, others prohibit third-party signal copying or flag identical trades across accounts. Read the firm's terms, get written confirmation if anything is unclear, and remember that a rules breach can void a payout even after you have passed the evaluation.
This article is general information, not personal financial advice. Figures such as spreads, fees, leverage and rules change; confirm them with the provider and check the provider is authorised for your country of residence.