Pine Node Editor
Home Tutorial Guides Pricing
Add to Chrome
Guide

TradingView alerts and webhooks for trading bots

From a signal on the chart to an order on the exchange.

Every Long, Short and Exit Signal node sends an alert message when it fires, ready for a webhook. TradingView's webhook alerts need a paid TradingView plan.

Create the alert

  1. Add the strategy to the chart (see From the editor to a TradingView chart).
  2. Open Create alert and pick your strategy as the condition.
  3. In the drop-down under it, choose alert() function calls only. The other options also send TradingView's plain-text "order filled" messages, which a JSON bot can't parse.
  4. Leave the Message field as it is: with "alert() function calls only" it isn't used — the message comes from the strategy.
  5. Under Notifications, enable Webhook URL and enter your bot's address.
After updating the extension or changing the graph, regenerate the script, replace it on the chart and recreate the alert. An existing alert keeps running the code it was created with.

What your bot receives

Entry (Long / Short Signal):

{"side":"buy","ticker":"BTCUSDT","price":67250.5,"qty":0.0148,"amount":995.3,
 "leverage":1,"tp":68595.51,"sl":66578,"trail":null,"trail_activation":null}

Exit (Exit Signal):

{"side":"close","ticker":"BTCUSDT","price":68010.2,"qty":0.0148,"leverage":1}
FieldMeaning
sidebuy, sell or close
ticker, priceSymbol and the signal bar's close
qty, amountOrder size in units and its value in the quote currency, from the Order size in the strategy's Properties (change it there, no regenerating). On exits, qty is the position being closed.
leverageFrom Strategy Settings
tp, slTake-profit and stop-loss prices, or null when not used. With trailing on, tp is null.
trailTrailing distance in price units, or null
trail_activationPrice at which the trailing stop should switch on, or null

Price levels are estimated from the signal bar's close; the real fill happens at the next bar's open, so a bot that places its own orders should treat them as close estimates.

Alerts fire only when the strategy really enters or exits: a repeated signal while a position is already open, or an exit signal while flat, sends nothing.

What the bot has to do itself

Take-profit, stop-loss and trailing exits are resting orders inside TradingView's strategy; they don't send an alert of their own when they fill. A bot that trades for real should place or manage those exits from the levels in the entry message.

Custom message templates

To match your bot's format, write your own message in a signal node's Alert message field, or once for the whole graph in an Alert Message node. Available tokens:

  • From the strategy: {{side}}, {{qty}}, {{amount}}, {{tp}}, {{sl}}, {{trail}}, {{trail_activation}}, {{leverage}}
  • Usual TradingView names: {{ticker}}, {{exchange}}, {{close}}, {{open}}, {{high}}, {{low}}, {{volume}}, {{time}}, {{timenow}}, {{interval}}, {{strategy.order.action}}, {{strategy.order.contracts}}, {{strategy.order.price}}

Example for a bot that expects its own field names and a secret:

{"action":"{{strategy.order.action}}","symbol":"{{ticker}}","size":{{qty}},
 "stop":{{sl}},"take":{{tp}},"secret":"your-bot-secret"}

TradingView itself doesn't fill these placeholders in strategy alert() messages; the editor turns them into the real values when it generates the script, so templates copied from bot guides work as written.

Binance Futures Signal Trading

Binance can receive TradingView webhooks directly for USDⓈ-M futures, without a bot of your own. It only opens orders: it does not set take-profit, stop-loss or trailing, change leverage or close positions from a signal — Binance asks you to set those on the position yourself. Its message format needs your personal signal_id and UID:

{"symbol":"{{ticker}}","side":"buy","qty":"{{qty}}","price":"{{close}}",
 "trigger_time":"{{timenow}}","signal_id":"your-signal-id","UID":"your-uid"}

For fully automated exits, use your own bot or a bot service that reads take-profit, stop-loss and trailing from the message.

Test without a bot

Open webhook.site, copy the unique URL it gives you and use it as the alert's webhook URL. Every alert that fires shows up there with the exact message your bot would get.

More guides: all guides · step-by-step tutorial · what's new

© Pine Node Editor. All rights reserved.
Guides Changelog Privacy Policy Terms of Service Contact