TradingView Webhook Complete Tutorial
From Zero to Auto-Trading
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.
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.
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-tokenStep 4: Fill the Message field with JSON
This is what TradingView will POST. The simplest version:
{
"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
//@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)
//@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)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.
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:
- Register on the platform and bind your exchange API key (read+trade only, no withdraw)
- Create a “strategy” on the platform to get a dedicated webhook URL
- Paste the URL into the TradingView Alert
- When Pine emits a signal, the platform places the order for you
5. Full payload example (TVSBot universal format)
A complete signal payload that wires into TVSBot:
{
"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.
(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
Wire your strategy to a TradingView webhook and auto-execute on Binance / OKX / Bybit and 4 more.
Start free trial7. 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
- RSI Indicator Complete Guide — Beyond 30/70
- MACD Indicator Complete Guide — How Golden/Death Crosses Really Work
- Moving Averages Complete Guide — What 5/20/200 EMA Actually Mean
- Pine Script for Beginners — Write Your First Strategy in 30 Minutes
- Why 3Commas Got $22M Stolen (Architecture Breakdown)
- TVSBot Docs — Webhook setup in detail