Complete Tutorial · Auto-Trading

TradingView Webhook Complete Tutorial
From Zero to Auto-Trading

2026-06-03·12 min read·Beginner ~ Intermediate

You spot a technical strategy you want to run automatically: buy when RSI drops below 30, add to the position on a breakout above prior highs. But TradingView itself only draws charts — it doesn't place orders. This article shows you how to use a Webhook to pipe TradingView signals straight into your exchange account, fully automated.

By the end you'll know: (1) what a webhook is, (2) how to set up an Alert in TradingView, (3) how to send signals from Pine Script, (4) the two paths for connecting to an exchange (build it yourself / use a SaaS), and (5) common pitfalls and security notes.

TradingView → TVSBot → 交易所 訊號流程TradingView 觸發 Alert,HTTP POST 到 TVSBot webhook URL, TVSBot 解析 payload 後用你的 API key 對 Binance / OKX 等交易所下單。TradingViewPine 觸發 Alert{"action":"buy",...}HTTP POSTTVSBot解析 / 風控用你的 API key 下單BinanceOKXBybit
圖:TradingView Alert → TVSBot webhook → 交易所自動下單

1. What is a Webhook? And how is it different from a regular API?

A webhook is, simply put, an event-triggered HTTP POST. A regular API is you asking and the other side answering (you call their endpoint); a webhook flips that around — when an event happens, the other side proactively hits your URL.

TradingView Alerts are the event source — when your Pine condition fires (for example, RSI < 30), TradingView immediately sends an HTTP POST to the URL you provide, with the payload set to whatever message you pre-configured.

Important prerequisite
TradingView Webhooks are a paid feature, starting at the Essential plan at $14.95/month. The Free plan doesn't include it. See the full plan comparison on the TradingView pricing page.

2. Setting up an Alert + Webhook in TradingView

Step 1: Open a chart and add your strategy

Open any chart (e.g. BTCUSDT.P perpetuals), click Indicators in the bottom-left, search for the Pine strategy you want, and add it. Or write your own (example below).

Step 2: Click the bell on the right → Create Alert

Set Condition to your strategy; set Trigger to “Once Per Bar Close” (conservative — no intra-bar whipsaws).

Step 3: Notifications tab

Check Webhook URL and paste in your receiver URL, for example:

https://api.tvsbot.com/webhook/your-secret-token

Step 4: Fill the Message field with JSON

This is what TradingView will POST. The simplest version:

json
{
  "secret": "your-webhook-secret",
  "action": "{{strategy.order.action}}",
  "symbol": "{{ticker}}",
  "price": {{close}}
}

{{strategy.order.action}}, {{ticker}} and friends are TradingView's built-in variables — they get replaced with actual values when the Alert fires (buy / sell / BTCUSDT, etc.).

3. How to write Pine Script that triggers Alerts

Pine Script has two ways to fire Alerts:

Option A: strategy.entry() + Alert message

pine
//@version=5
strategy("RSI Reversal Demo", overlay=true)

rsi = ta.rsi(close, 14)

if (ta.crossover(rsi, 30))
    strategy.entry("Long", strategy.long,
      alert_message='{"action":"buy","symbol":"{{ticker}}"}')

if (ta.crossunder(rsi, 70))
    strategy.entry("Short", strategy.short,
      alert_message='{"action":"sell","symbol":"{{ticker}}"}')

When you create the Alert, enter {{strategy.order.alert_message}} in the Message field, and Pine will inject the alert_message content above into the webhook payload.

Option B: alert() function (signal-only, no orders)

pine
//@version=5
indicator("Pure Signal Demo", overlay=true)

rsi = ta.rsi(close, 14)

if (ta.crossover(rsi, 30))
    alert('{"action":"buy","symbol":"' + syminfo.ticker + '"}',
          alert.freq_once_per_bar_close)
Choosing between strategy and indicator
strategy: best for full backtests — TradingView computes PnL for you. indicator: a pure signal emitter; you compute backtest results yourself. Either works for auto-trading — pick whichever you're comfortable with.

4. Two paths for connecting to an exchange

Path A: Roll your own receiver server

Write a simple Flask / FastAPI server and host it on Heroku / Fly / a VPS. When the webhook arrives, use ccxt or the exchange's official SDK to place orders.

python
from fastapi import FastAPI, Request, HTTPException
import ccxt

app = FastAPI()
exchange = ccxt.binance({
    "apiKey": "YOUR_KEY",
    "secret": "YOUR_SECRET",
    "options": {"defaultType": "future"},
})

@app.post("/webhook/{secret}")
async def receive(secret: str, request: Request):
    if secret != "YOUR_WEBHOOK_SECRET":
        raise HTTPException(401, "invalid secret")
    body = await request.json()

    side = body["action"]   # buy / sell
    symbol = body["symbol"] # BTCUSDT
    qty = 0.001  # Hardcoded or pull from body

    order = exchange.create_market_order(symbol, side, qty)
    return {"ok": True, "order_id": order["id"]}

The upside: full control. The downside: you need to know deployment and handle all of this yourself:

  • Storing API keys securely (don't commit plaintext .env files to GitHub)
  • HTTPS (TradingView only supports HTTPS webhooks)
  • Order error handling (insufficient balance, minimum size, IP allowlists, etc.)
  • Multi-strategy management (one endpoint per strategy, or routing logic)
  • Risk controls (stop-loss, max daily loss, emergency kill switch)
  • Multi-account sync (how do you wire up three exchanges at once?)

Path B: Use a SaaS (recommended if you don't want to run servers)

Platforms like TVSBot, 3Commas, and Cryptohopper handle all of the above for you. You just:

  1. Register on the platform and bind your exchange API key (read+trade only, no withdraw)
  2. Create a “strategy” on the platform to get a dedicated webhook URL
  3. Paste the URL into the TradingView Alert
  4. When Pine emits a signal, the platform places the order for you
Why TVSBot
TVSBot is a non-custodial architecture — your API keys are encrypted at rest with Fernet AES-128, and the platform never directly holds funds. You can bind 7 exchanges at once (Binance / OKX / Bitget / Bybit / Gate / BingX / Hyperliquid), and one signal fans out to multiple accounts with a single click. See pricing

5. Full payload example (TVSBot universal format)

A complete signal payload that wires into TVSBot:

json
{
  "secret": "your-webhook-secret",
  "action": "buy",
  "symbol": "BTC/USDT:USDT",
  "qty_type": "margin_pct",
  "qty": 5,
  "leverage": 5,
  "tp_pct": 3,
  "sl_pct": 1.5,
  "exchange": "binance",
  "market_type": "futures"
}

Translation: open a position using 5% of your margin, 5x leverage, 3% take-profit, 1.5% stop-loss. TVSBot translates that into the actual order quantity (using your bound API key to fetch balance and current price).

6. Security and common pitfalls

(1) Always require a secret

A webhook without a secret is wide open — anyone who learns the URL can fire bogus orders. Always include a secret field in the payload, and only execute when the receiver verifies it.

(2) Disable Withdraw permission on API keys

The API key you create for the strategy should only have Trade checked — never check Withdraw. That way, even if the key leaks, an attacker can only place wild orders, not move funds out.

Reference: the 2022 3Commas incident
3Commas, a custodial platform, was breached, exposing 100,000 API keys — and keys that had Withdraw permission were drained. For details, see Why 3Commas got $22M stolen.

(3) Once Per Bar vs. Once Per Bar Close

Once Per Bar fires the moment the condition is met, but the condition could reverse before the bar closes → false signal.Once Per Bar Close waits for the bar to close before firing, which is much more conservative. Beginners should default to the latter.

(4) TradingView free tier limits

The free tier only allows 1 active alert at a time. To run multiple strategies you have to upgrade — or use TVSBot's “single-alert multi-strategy routing” feature, where the payload carries a strategy field specifying which strategy to dispatch to, letting one alert quota drive N strategies.

(5) No retry mechanism

TradingView webhooks don't auto-retry on failure. If your receiver is briefly down, you miss the signal. Either keep your server's uptime high, or use a SaaS with an SLA.

Get started

Ready to ship what you just learned?

Wire your strategy to a TradingView webhook and auto-execute on Binance / OKX / Bybit and 4 more.

Start free trial

7. Further learning

After reading this, you can already run the basic flow. Recommended next steps:

  • Core indicators: how RSI / MACD / EMA are computed, and when to use each one (see related reading below)
  • Risk controls: max daily loss, max position size, kill switch
  • Multiple timeframes: daily for direction + hourly for entries
  • Backtest vs. live: a profitable backtest doesn't guarantee live profits — forward-test for at least 14 days