TradingView Webhook to MT5 and MT4: URL, Message Format and Examples
TradingView can post an alert to a URL, but MetaTrader can't receive it by itself, so you need a
bridge. Paste the bridge's URL into the alert's Webhook URL field and write the
order in the message box. With TradingView Link, that's your webhook password on the first line
and an instruction on the next, such as long EURUSD q=0.1 sl=300 tp=600.
What do you need for a TradingView webhook to MT5?
- A TradingView plan with webhooks: Essential or any higher plan. The free Basic plan has none.
- 2-factor authentication on your TradingView account, which TradingView requires for webhook alerts.
- MT4 or MT5 running on a PC or VPS, on a demo account while you test.
- A bridge. This page uses TradingView Link, which has a free plan for testing. Other bridges are compared here.
What does TradingView actually send?
When the alert fires, TradingView sends an HTTP POST request to your URL with the alert message as the body. A few rules from TradingView's help page explain many failed setups:
- A message that is valid JSON goes out as
application/json. Anything else goes out astext/plain. - Only ports 80 and 443 are accepted, and IPv6 isn't supported.
- If the server takes longer than three seconds to process the request, TradingView cancels it.
- Webhooks can occasionally fail. The Webhook status column in the alert log shows what happened to each one.
TradingView Link's format is plain text, so it goes out as text/plain. TradingView
warns against putting login details in a webhook, and the first line here isn't one: it's a
password you generate for that one webhook. Never use your TradingView or broker password there.
How do you set up the webhook?
- In the TradingView Link dashboard, create an MT5 or MT4 webhook and copy its URL and webhook ID.
- Install the EA, add
https://tradingviewlink.comto the WebRequest list, attach the EA to one chart and paste in the webhook ID. The MT5 guide and MT4 guide show each screen. - Click Add Secret to generate your webhook password.
- In TradingView, create an alert and write the message in the format below.
- In the alert's notifications, turn on Webhook URL and paste your URL.
- Let the alert fire on a demo account, then check the Trade and Experts tabs in MetaTrader.
What is the alert message format?
The password goes on its own first line. Every line after it is one instruction: the action, the symbol, the size, then any options.
YourWebhookPassword
Action Symbol q=size [options] | Part | What it does | Example |
|---|---|---|
| Action | What to do: long, short, flat (close), cancel (pending orders), modify, or {{strategy.market_position}} from a strategy | long |
| Symbol | The instrument, spelled exactly as your broker spells it | EURUSD |
| q | Order size in lots. Add qt=percent to size it as a percentage of your account balance | q=0.1 |
| sl, slp | Stop loss: sl is a distance in pips or a percentage, slp is a price | sl=300, sl=3%, slp=2.19 |
| tp, tpp | Take profit: tp is a distance in pips or a percentage, tpp is a price | tp=600, tp=3%, tpp=2.19 |
| p | Makes it a limit order: the entry as a price, pips or a percentage | p=-3000 |
| e | Minutes before an unfilled limit order expires | e=15 |
| m | Magic number, so several strategies can share one symbol | m=1001 |
| cq | With flat: the percentage of open lots to close | cq=30% |
| ts | Trailing stop distance in pips | ts=1000 |
| s | Trading sessions in broker server time. Days run 1 to 7, Monday to Sunday | s=14:30-19:00, s=5=14:30-15:00 |
| r | Price range: the order is placed only if the price is inside it | r=6000-7000 |
| t | With cancel: only long or only short pending orders | t=long |
A pip here means the smallest price step your broker defines for that symbol, which isn't the same on every instrument. Check your stop and target distances on a demo account before you go live. The documentation has the full reference.
Which alert messages can you copy?
Replace the first line with your own password and the symbols with your broker's names.
Market order with stop loss and take profit
YourWebhookPassword
long EURUSD q=0.1 sl=300 tp=600 Buys 0.1 lots at the market price.
Order driven by a strategy
YourWebhookPassword
{{strategy.market_position}} BTCUSD q=0.06 slp=40000 tp=1000 TradingView replaces the placeholder with long, short or flat, so one alert handles entries and exits. It suits strategies that open and close whole positions.
Size by account balance
YourWebhookPassword
{{strategy.market_position}} BTCUSD q=10 qt=percent slp=40000 tp=1000 Trades with 10% of the account balance.
Two orders from one alert
YourWebhookPassword
short BTCUSD q=0.1 sl=800 tp=1000
short BTCUSD q=0.2 sl=800 tp=1000 Each line is its own order. The whole message still counts as one alert.
Close everything on a symbol
YourWebhookPassword
flat US500 Closes all open US500 positions.
Close part of a position
YourWebhookPassword
flat BTCUSD cq=30% Closes 30% of the open BTCUSD lots.
Limit order with an expiry
YourWebhookPassword
short BTCUSD q=0.1 p=-300 tp=1000 e=15 Cancels itself if it isn't filled within 15 minutes. On MT5, a negative p sets the offset from the market price.
Cancel pending orders
YourWebhookPassword
cancel BTCUSD t=long Cancels the long pending orders on BTCUSD. Leave out t= to cancel them all.
Move the stop to breakeven
YourWebhookPassword
modify BTCUSD sl=-1 tp=3% sl=-1 means breakeven, and sl=-2 removes the stop.
Trailing stop
YourWebhookPassword
long EURUSD q=0.1 ts=1000 The stop follows the price as it moves in your favour.
Keep strategies apart with a magic number
YourWebhookPassword
long BTCUSD q=0.1 sl=300 tp=600 m=1001 Give each strategy its own number, and use it on its flat lines too.
Only during a session
YourWebhookPassword
short NAS100 q=0.1 s=14:30-19:00 Active from 14:30 to 19:00 in your broker's server time.
Only inside a price range
YourWebhookPassword
long BTCUSD q=0.1 r=91000-91300 Places the order only if the price is between 91,000 and 91,300.
Which mistakes stop the webhook from trading?
| Mistake | What you see | Fix |
|---|---|---|
Using {{strategy.order.action}} | "Invalid order type" in the Experts tab | It sends buy or sell. Use {{strategy.market_position}}, or alert_message in Pine |
| TradingView's ticker instead of the broker's symbol | "Symbol not found" in the Experts tab | Use the name in your Market Watch, including any suffix |
| Password missing or not on the first line | The alert fires, but no order arrives | Put the password alone on line 1, and check it matches the dashboard |
| Webhook URL not turned on in the alert | No webhook entry for the alert | Edit the alert, turn on Webhook URL and paste the URL again |
| Old bridge EA still attached | Two orders from one alert | Keep only one bridge EA on the account |
Still stuck? The troubleshooting guide lists every EA message and its fix.
Frequently asked questions
Can TradingView send a webhook straight to MT5 or MT4?
No. TradingView can post a webhook to a URL, but MetaTrader doesn't receive webhooks by itself. A bridge such as TradingView Link receives the webhook, and its Expert Advisor in your terminal places the order.
Where do I get the webhook URL for MT5?
From the bridge you use. In TradingView Link, every MT4 or MT5 webhook has its own URL in the dashboard. Paste it into the Webhook URL field in the TradingView alert.
Which TradingView plan has webhooks?
Essential and every plan above it. The free Basic plan doesn't. TradingView also requires 2-factor authentication on the account before it sends webhook alerts.
Does the alert message have to be JSON?
Not for TradingView Link. The message is plain text: the webhook password on the first line, then one instruction per line. Other bridges use other formats, so check the one you use.
Is it safe to put a password in the alert message?
The first line is a webhook password you generate for that webhook in the dashboard. It isn't your TradingView or broker password, and you should never use those there. If it leaks, delete it, create a new one and update your alerts.
Why did my webhook fire but no trade appear?
Check TradingView's alert log first, including the Webhook status column. If the webhook was delivered, check that the EA is connected and read the Experts tab in MetaTrader, which names the problem, such as a wrong symbol.
Do I need to keep TradingView open?
No. Alerts run on TradingView's servers, so you can close the chart. MT4 or MT5 must stay open with the EA running, on your PC or a VPS.
Sources
- TradingView: how to configure webhook alerts
- TradingView: how to use a variable value in an alert
- TradingView pricing (webhook notifications by plan)
- TradingView Link documentation (message syntax)
Related guides
- How to connect TradingView to MT5
- How to connect TradingView to MT4
- PineConnector alternative with MT4 support
- Best TradingView to MT5 bridges, compared
- Free TradingView to MT5 bridge: what you get for $0
- Free and cheapest TradingView to MT4 bridges
- How to automate a TradingView strategy on MT4 and MT5
- TradingView to MT5 not working? How to fix it
- Prop-firm EA rules: FTMO, FundedNext and The5ers
- TradingConnector alternative for MT4 and MT5
- WebhookTrade alternative for MT4 and MT5
- How to convert Pine Script to MQL5, and when not to
- Does TradingView's free plan have webhooks? Plans compared
- Do you need a VPS for TradingView to MT5?
- How to automate a TradingView strategy on FTMO
- How to run multiple strategies on one MT5 account with magic numbers
- Pricing: plans, limits and what else you pay for
- Full documentation: alert syntax, EA settings and troubleshooting
- FAQ: trials, billing and signal limits