TradingView Webhook to MT5 and MT4: URL, Message Format and Examples

Last updated · By the TradingView Link team
Short answer

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?

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:

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?

  1. In the TradingView Link dashboard, create an MT5 or MT4 webhook and copy its URL and webhook ID.
  2. Install the EA, add https://tradingviewlink.com to the WebRequest list, attach the EA to one chart and paste in the webhook ID. The MT5 guide and MT4 guide show each screen.
  3. Click Add Secret to generate your webhook password.
  4. In TradingView, create an alert and write the message in the format below.
  5. In the alert's notifications, turn on Webhook URL and paste your URL.
  6. 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]
Alert message parameters for TradingView Link
PartWhat it doesExample
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?

Common webhook mistakes and how to fix them
MistakeWhat you seeFix
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.

Send your first webhook
The free plan includes 5 alerts a month with no credit card, enough to test the full path on a demo account.

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

Related guides