TradingView alert message: the format, example by example
The message is the only text your alert sends. To become an order on MT4, MT5 or cTrader, it follows a simple format: a JSON object or a single line of text. Here is every field, every command and examples ready to copy, all checked in the webhook tester.
The alert message
{
"action": "buy",
"symbol": "EURUSD",
"volume": 0.10,
"sl": 1.0820,
"tp": 1.0910
}
Where the message goes
In the TradingView alert window, the Message field holds the text sent at each trigger, and the Webhook URL field holds the address it is sent to. That address is the one of your TheConnector account: it already carries the access key, so the message only describes the order.
- One alert sends one message, so one command
- The access key stays in the webhook URL, never in the message
- TradingView replaces the variables such as {{ticker}} before sending
The minimal message
Two fields are enough for a valid message: the command and the symbol. The order then takes its size from the account's risk settings, and risk-based sizing needs a stop: in practice, add at least a stop-loss, or a fixed number of lots.
{"action":"buy","symbol":"EURUSD"}
buy,EURUSD
- action: what to do, buy in this example
- symbol: the TradingView ticker, matched to your broker's symbol
- The one-line text form carries exactly the same information
The fields of the message
Eight fields cover almost every need. Their names are in lowercase, their values are numbers, except the command, the symbol and the tag. A field that TheConnector does not know is ignored without a message: a misspelt name goes unnoticed, which is why the tester is worth a look before going live.
actionThe command: buy, sell, close, cancel, modifybuysymbolThe instrument, as TradingView names itEURUSDriskRisk of the order, read according to the account's risk source1volumeA fixed number of lots, which takes precedence over the risk0.10slStop-loss, in the account's price mode20tpTake-profit, in the account's price mode40priceEntry price of a pending order1.0850tagName of the strategy, to tell several apart on one symboltrend- Accepted aliases: lot or lots for volume, stoploss for sl, takeprofit for tp
- No account field: the webhook URL already designates the account
- More commands and per-alert settings are in the syntax reference
The commands
The action field takes one of the commands below. Each also accepts a spelling with an underscore, such as close_long, and long and short are accepted for buy and sell.
buy / sellOpens a market position, buying or sellingbuy,EURUSD,risk=1,sl=20buylimit / selllimitPending order below (buy) or above (sell) the pricebuylimit,EURUSD,price=1.0850,volume=0.1buystop / sellstopPending order above (buy) or below (sell) the pricesellstop,GBPJPY,price=198.250,risk=1,sl=198.800closelong / closeshortCloses the buy or the sell position on the symbolcloselong,EURUSDcloselongshortCloses both directions on the symbolcloselongshort,EURUSDcancellong / cancelshortCancels the pending buy or sell orderscancelshort,GBPJPYnewsltplong / newsltpshortMoves the stop-loss and take-profit of the open positionnewsltplong,EURUSD,sl=15,tp=60- A pending order needs its entry price
- A close or a modification names the symbol, like an entry
- breakevenlong and breakevenshort are aliases of newsltplong and newsltpshort
Buy or sell at market, with stop and target
The most common message: a market entry sized by risk, with its stop-loss and take-profit. With the risk source set to TradingView percentage and the price mode set to pips, this example risks 1% of the balance, with a stop 20 pips away and a target 40 pips away.
{"action":"buy","symbol":"EURUSD","risk":1,"sl":20,"tp":40}
- For a sale, replace buy with sell
- The risk is the loss if the stop is hit, not the size of the position
- To impose a size, send volume instead of risk
Place a pending order
A buy limit waits for the price to come down to its entry, a buy stop for the price to go up to it. This example assumes the account's price mode is absolute price: the entry, the stop and the target are market prices.
{"action":"buylimit","symbol":"EURUSD","price":1.0850,"volume":0.10,"sl":1.0820,"tp":1.0910}
- Here the size is fixed: 0.10 lot
- In pips or percentage mode, the same fields are read as distances
- cancellong removes the pending buy orders if the setup no longer holds
Close a position or move its stop
Three messages, one per alert: close the buy position, close both directions, then move the stop-loss and target of the open buy position. Like an entry, each one names its symbol.
{"action":"closelong","symbol":"EURUSD"}
{"action":"closelongshort","symbol":"EURUSD"}
{"action":"newsltplong","symbol":"EURUSD","sl":15,"tp":60}
- A close without a tag takes the first position in the requested direction
- With several strategies on the same symbol, name them with tag
- Copy one line per alert, never the whole block
Two strategies on the same symbol
Without a name, a close takes the first position it finds, perhaps the other strategy's. The tag field names the strategy: at entry, the robot writes it in the position's comment at the broker, and a named close only touches the positions that carry it.
{"action":"buy","symbol":"USDJPY","risk":1,"sl":20,"tag":"trend"}
{"action":"closelong","symbol":"USDJPY","tag":"trend"}
- Same tag in every alert of the strategy, entries and exits
- Tags are lowercased and cut to 12 characters: keep them short and distinct
- Letters, digits, - and _ only
Put TradingView variables in the message
One message can serve every chart: with {{ticker}}, the symbol follows the chart on which the alert is created. TradingView replaces the variable before sending, so TheConnector receives the actual symbol.
{"action":"buy","symbol":"{{ticker}}","risk":1,"sl":20,"tp":40}
- Text variables go in quotes ("{{ticker}}"), numbers such as {{close}} do not
- Strategy alerts: {{strategy.order.action}} says “sell” to exit a buy, so prefer alert_message
- The full list of variables is in the TradingView alerts guide
The units of the stop, the target and the price
The numbers in sl, tp and price are read according to the price mode chosen in the account settings. Absolute price: a market price, such as 1.0750. Pips: a distance from the entry, such as 20. Percentage: a distance as a percentage of the entry price, such as 0.5.
- The price mode must match what your alerts send
- Pips suit forex; on indices and metals, prefer price or percentage
- Write decimals with a dot: in the one-line form, the comma separates the fields
- Variant: sl_pips, sl_price or sl_pct (and tp_pips, tp_price, tp_pct) set the unit in the alert itself
The mistakes that get a message refused
Most refusals come from a handful of causes, and the alert history names each of them. The first one surprises: an account field copied from an old example gets the whole alert refused, even with a valid key.
- An account field that does not exactly match the account: refused as a rejected access key
- Malformed JSON: a missing quote or an extra comma
- An unknown or missing command, or a missing symbol
- A number with text or a unit, such as 20pips or 1%
Check a message before sending it
The free webhook tester reads your message with the same parser as the production gateway and shows what it understands: command, symbol, size, stop, target, tag. Nothing is sent to any account. The alert generator on the home page composes the message for you.
- Paste the message exactly as it will be in TradingView
- Replace the variables with real values before testing
- Then send a first alert to a demo account
Related guides
FAQ
Should the access key be in the message?
No. It is part of the webhook URL copied from your dashboard, which identifies the account. The message only describes the order.
JSON or one line of text: which one to choose?
Both are accepted and carry the same fields. JSON names each value, which makes it easier to reread; the one-line form, such as buy,EURUSD,risk=1,sl=20,tp=40, is shorter to type.
How do I close a position from an alert?
Send closelong to close the buy position or closeshort for the sell one, with the symbol: {"action":"closelong","symbol":"EURUSD"}. With several strategies on the symbol, add the same tag as at entry.
Why is my alert refused although the key is valid?
Most often because of an account field copied from an old example: when present, it must match the account exactly, otherwise the alert is refused as if the key were wrong. Remove it; the webhook URL is enough.
Can I send the closing price of the candle?
Yes, with the {{close}} variable, without quotes. It is useful as the entry price of a pending order, when the account's price mode is absolute price.
What happens if the message contains a field TheConnector does not know?
It is ignored, without an error. The order goes through without it, so a misspelt name changes the order without warning: check the message in the webhook tester.