TradingView alert message format for MT5 (JSON)
The Message box of a TradingView alert tells MT5 Bridge what to do on your MetaTrader 5 account. It is a short piece of JSON: the action, the symbol, and optionally the size, stops and a strategy name.
The simplest message
{"apikey": "YOUR_API_KEY", "action": "buy", "symbol": "EURUSD"}
That buys EURUSD at the market price with your account's default size. Your API key is on MT5 Accounts in
the dashboard. Paste the message into the alert's Message box and the webhook URL
https://mt5bridge.net/webhook into Notifications › Webhook URL
(full set-up guide).
Every field
| Field | What it does | Also accepted as |
|---|---|---|
apikey | Required. Your account's API key: which MT5 account trades. | api_key, key, secret, passphrase |
action | Required. What to do: see the actions below. | |
symbol | Required. The instrument, as your broker names it in MT5. A TradingView prefix such as OANDA: is removed for you. | |
quantity | Size in lots, e.g. 0.10. Left out: your account's own sizing. | qty, lots, lot, volume, size |
sl | Stop loss price. | stop_loss, stoploss |
tp | Take profit price. | take_profit, takeprofit |
sl_points | Stop loss as a distance from the entry, in your broker's points (instead of a price). | sl_pts |
tp_points | Take profit as a distance from the entry, in points. | tp_pts |
price | An entry price: the buy or sell becomes a pending order that waits for it. Limit or stop is chosen for you from where the price is. | entry, entry_price, limit_price |
strategy_tag | A name for the strategy, e.g. GOLD_SCALP. Written on the MT5 order, so your history keeps strategies apart. | strategy, tag, comment |
alert_id | Optional ID, e.g. the bar time, so an alert re-sent for the same bar counts as a repeat. | id, bar_time, time |
Numbers may be written with or without quotes (0.10 or "0.10"), which helps when they
come from TradingView placeholders.
Actions
| Action | What happens | Also accepted |
|---|---|---|
buy | Opens (or adds to) a long position. | long, enterlong |
sell | Opens (or adds to) a short position. | short, entershort |
closelong | Closes the long positions on the symbol. | exitlong, close_long |
closeshort | Closes the short positions on the symbol. | exitshort, close_short |
close | Closes everything on the symbol and cancels the bridge's pending orders there. | exit, flat, close_all |
cancellong | Deletes the bridge's pending buy orders on the symbol. | cancel_buy |
cancelshort | Deletes the bridge's pending sell orders on the symbol. | cancel_sell |
cancel | Deletes all of the bridge's pending orders on the symbol. Open trades are not touched. | cancel_all, delete |
A close with a quantity closes only that much. With a strategy_tag, a cancel or close
removes only the pending orders that tag placed.
closelong first and then sell,
or use the Pine Script converter, which does this for you.Examples
Buy gold with a stop loss and take profit
{"apikey": "YOUR_API_KEY", "action": "buy", "symbol": "XAUUSD", "quantity": 0.10,
"sl": 2310, "tp": 2345, "strategy_tag": "GOLD_SCALP"}
Sell with stops in points
{"apikey": "YOUR_API_KEY", "action": "sell", "symbol": "EURUSD", "quantity": 0.20,
"sl_points": 150, "tp_points": 300}
Close everything on a symbol
{"apikey": "YOUR_API_KEY", "action": "close", "symbol": "XAUUSD"}
A pending buy at a price
{"apikey": "YOUR_API_KEY", "action": "buy", "symbol": "GBPUSD", "quantity": 0.10,
"price": 1.2650, "sl": 1.2600, "tp": 1.2750}
Using TradingView placeholders
{"apikey": "YOUR_API_KEY", "action": "{{strategy.order.action}}", "symbol": "{{ticker}}",
"quantity": "{{strategy.order.contracts}}", "alert_id": "{{time}}"}
TradingView fills in the placeholders when the alert fires. {{strategy.order.action}} gives
buy or sell for a strategy's orders.
Check what happened
Every alert that reaches the bridge is listed on Webhook Alerts in your dashboard with the result: the order and its ticket, or the reason it was refused (a wrong key, an unknown symbol, a lot size below the broker's minimum, or one of your own risk limits). The same alert sent twice within seconds is ignored.
Read the converter guide