Skip to content
TradeBridge

Automation

Connect TradingView alerts

Create a webhook and turn TradingView strategy alerts into orders in one or many accounts.

1. Create the webhook

Open Terminal → TradingView → New webhook, choose the accounts and product (MIS, NRML or CNC) and press Create. Copy the URL and the secret — the secret is shown only once.

2. Configure the TradingView alert

In TradingView create an alert, enable Webhook URL and paste the URL. Use this as the message:

{
  "secret": "YOUR-SECRET",
  "action": "{{strategy.order.action}}",
  "symbol": "{{ticker}}",
  "quantity": "{{strategy.order.contracts}}"
}

Message options

  • action: buy, sell, or EXIT to square off that symbol in the webhook's accounts.
  • lots: use instead of quantity for futures and options, e.g. "lots": 2.
  • orderType and price: "orderType": "LIMIT", "price": 812.5 for limit orders.
  • symbol: NSE:SBIN, SBIN or NIFTY-FUT.

Safety settings

Open Edit on a webhook to turn these on. All are optional.

Fit to margin. Each alert's entry is reduced per account to what its free margin allows, or that account is skipped, instead of being rejected by the broker. The signal log says how many accounts were reduced. Exits are never reduced.

Stop-loss at the broker. Enter a percentage, for example 1. After each entry fills, a stop-loss market (SL-M) exit order is placed at your broker, that far from the fill price: below it for a buy, above it for a sell. Because the order sits at the broker, the position stays protected even if this platform or your script is down.

  • The stop is cancelled when the position is closed: by an EXIT alert, from the terminal, or by a risk limit. An EXIT cancels it before squaring off, so a stop is never left behind to open a position the other way.
  • If you close part of the position, the stop is reduced to the quantity you still hold.
  • If your broker refuses the stop (some brokers limit SL-M orders on some instruments), you get a Stop-loss not placed notification, and the position is not protected at the broker.

Dead-man's switch. Use this when your own script (Python, Amibroker and so on) sends alerts. Choose a timeout, then have the script send this to the webhook URL at least that often:

{"secret": "your-secret", "action": "heartbeat"}

Any valid alert also counts as a heartbeat. If nothing arrives within the timeout, working orders of the webhook's product in its accounts are cancelled; stop-losses stay. With Cancel working orders and square off positions, its positions in that product are also squared off. Positions in other products, such as CNC holdings, are left alone.

The switch starts after the first heartbeat and acts once per outage, then waits for the next heartbeat. You get a notification only if it actually cancelled or closed something. A script that stops after the market closes, with nothing open, is just logged.

Signal log

Each alert is logged as EXECUTED, REJECTED (for example the webhook is paused), DUPLICATE (same alert within 5 seconds), INVALID (wrong secret, unknown symbol or bad JSON) or TIMEOUT (the dead-man's switch acted). Heartbeats are not logged.

Requirements

TradingView can only call a public HTTPS address, so the trading engine must be reachable from the internet in production.

Last updated