TradingView alerts
Turn a TradingView alert into an order on your MetaTrader account.
Every account can have a private webhook URL. Paste it into a TradingView alert, put a small JSON message in the alert, and each time the alert fires OrderFill places the order on your account.
Set it up
- In the dashboard, open the account (or Alerts) and choose Turn on TradingView alerts.
- Copy the webhook URL. Anyone with it can trade this account, so keep it private. If it leaks, choose Replace URL and the old one stops working at once.
- In TradingView, create an alert. Under Notifications, tick Webhook URL and paste it.
- In the alert's Message box, put one of the messages below.
OrderFill answers TradingView straight away and places the order immediately after. If the account's terminal was asleep it is started first, which can take up to a minute; the order is not lost while that happens. Every alert, and what the broker said, is in the account's Recent alerts log.
Messages
Market order with a stop and a target:
{
"id": "{{ticker}}-{{timenow}}",
"action": "buy",
"symbol": "XAUUSD",
"volume": 0.10,
"sl": 2380.50,
"tp": 2412.00,
"comment": "breakout-long"
}
Pending order:
{
"id": "{{ticker}}-{{timenow}}",
"action": "buy_limit",
"symbol": "EURUSD",
"volume": 0.50,
"price": 1.0820,
"sl": 1.0790,
"tp": 1.0900
}
Move a position's stop or target (add price to move a pending order instead):
{ "id": "{{ticker}}-{{timenow}}", "action": "modify", "ticket": 123456789, "sl": 2390.00, "tp": 2425.00 }
Close one position, part of one, or everything on a symbol:
{ "id": "{{ticker}}-{{timenow}}", "action": "close", "ticket": 123456789 }
{ "id": "{{ticker}}-{{timenow}}", "action": "close", "ticket": 123456789, "volume": 0.05 }
{ "id": "{{ticker}}-{{timenow}}", "action": "close_all", "symbol": "XAUUSD" }
close with a symbol and no ticket closes every position on that symbol;
close_all with no symbol closes every position on the account.
Fields
| Field | Required | Meaning |
|---|---|---|
id | recommended | The dedupe key. An alert with an id already received is not traded again, so a TradingView resend cannot double an order. Make it unique per alert: {{ticker}}-{{timenow}} or {{strategy.order.id}}-{{timenow}}. Without an id, an identical message within the same minute counts as a resend. |
action | yes | buy, sell, buy_limit, sell_limit, buy_stop, sell_stop, modify, close, close_all |
symbol | to open | The usual name (XAUUSD, EURUSD). OrderFill maps it to your broker's spelling, such as XAUUSDm on Exness. See Symbols. |
volume | no | Lots. Omit it to trade the symbol's minimum. On close, closes that much of the position. |
price | for limit and stop | The order's trigger price. On modify, moves a pending order. |
sl, tp | no | Stop loss and take profit, as prices. |
ticket | for modify, and close of one position | The position or order to act on. |
comment | no | Up to 64 characters, shown on the trade in MetaTrader. |
Numbers may be sent as text ("0.10"), which is what TradingView placeholders such as
{{close}} produce.
Replies and limits
200with{"ok": true, "delivery": "..."}: received; the order is placed next.200with{"ok": true, "duplicate": true}: thatidwas already received; nothing new is traded.400: the message could not be read. The reason is in the reply and in the alert log.404: the URL is wrong, replaced or turned off.429: alerts are arriving faster than the account's trading limit (see Rate limits).
In production, alerts are accepted only from TradingView's published webhook addresses.