From Pine alerts to live Binance orders — master 3 mainstream approaches, full setup, and risk control to run your strategy 24/7.
TradingView is the world's largest charting and strategy community. When you write a Pine script and want it to auto-trade on Binance, Webhook is the bridge — TradingView POSTs a JSON message to a URL when your alert fires, and a server picks it up and calls Binance API to buy or sell.
The full path: TradingView alert → Webhook URL (your server or third-party) → Binance API → live order.
Pros: visual strategy logic, rich Pine ecosystem. Cons: you need to handle signing, risk control, reconnection, or pay for a ready-made platform.
| Approach | Difficulty | Cost | Latency | Best for |
|---|---|---|---|---|
| Self-hosted VPS bridge | Mid-High | $5-10/mo | 500ms-1.5s | Coders who want control |
| Third-party platform (3Commas, etc.) | Low | $15-50/mo | 800ms-2s | Users who want zero-ops |
| Binance API + local script | Low | Power bill | Local network dependent | Users with always-on PC |
Run a small Node.js / Python / Go service on a VPS, listen on a public URL, sign and call Binance API on receive. Most flexible, supports any custom risk logic.
3Commas, Cryptohopper, Wundertrading, Aleeert.com etc. They give you a ready Webhook URL — bind your Binance API and go. Easy but monthly fee + platform risk + custodial API.
The TradingView desktop client can play sound and run external scripts, triggering a local Python script that calls Binance API. No monthly fee but PC must stay on.
Below is a minimal EMA crossover long-only strategy in Pine v5, using alert_message to send JSON:
//@version=5
strategy("EMA Cross Webhook", overlay=true)
fast = ta.ema(close, 12)
slow = ta.ema(close, 26)
longCond = ta.crossover(fast, slow)
shortCond = ta.crossunder(fast, slow)
if longCond
strategy.entry("L", strategy.long, alert_message='{"passphrase":"YOUR_SECRET","action":"buy","symbol":"BTCUSDT","qty":0.01,"type":"MARKET"}')
if shortCond
strategy.close("L", alert_message='{"passphrase":"YOUR_SECRET","action":"close","symbol":"BTCUSDT"}')
Key points:
alert_message must be valid JSON for easy parsingpassphrase is a shared secret to block strangers who guess your URL{{strategy.order.alert_message}} in the Message boxhttps://your-vps.com/tv-webhookDigitalOcean / Vultr / Hetzner $5/mo with 1 vCPU 1G is enough. Pick Tokyo or Singapore for lowest latency to Binance.
TradingView only POSTs to HTTPS. Use Cloudflare free SSL or Caddy/Nginx + Let's Encrypt.
Use Express (Node) or FastAPI (Python) for a POST endpoint, validate passphrase, then call Binance API.
Use pm2 or systemd so service auto-restarts after crash, and log to file for debugging.
API mgmt → create key → enable spot/margin or futures only, do NOT enable withdrawal, whitelist your VPS public IP.
Right-click chart → Add alert → Webhook URL = https://your-vps.com/tv-webhook, Message = {{strategy.order.alert_message}}, create.
Run 50-100 USDT on BTC spot for 3-5 days. Verify every signal converts correctly before scaling.
import express from 'express';
import crypto from 'crypto';
import axios from 'axios';
const app = express();
app.use(express.json());
const KEY = process.env.BN_KEY;
const SECRET = process.env.BN_SECRET;
const PASSPHRASE = process.env.PASSPHRASE;
const BASE = 'https://fapi.binance.com';
function sign(query){
return crypto.createHmac('sha256', SECRET).update(query).digest('hex');
}
app.post('/tv-webhook', async (req, res) => {
const { passphrase, symbol, action, qty, type='MARKET' } = req.body;
if (passphrase !== PASSPHRASE) return res.status(401).send('bad passphrase');
const side = action === 'buy' ? 'BUY' : 'SELL';
const ts = Date.now();
const query = `symbol=${symbol}&side=${side}&type=${type}&quantity=${qty}×tamp=${ts}`;
const url = `${BASE}/fapi/v1/order?${query}&signature=${sign(query)}`;
try{
const r = await axios.post(url, null, { headers:{'X-MBX-APIKEY':KEY}});
res.json(r.data);
}catch(e){
console.error(e.response?.data || e.message);
res.status(500).send('order failed');
}
});
app.listen(3000, () => console.log('listening 3000'));
/fapi/v2/account, pause service if drawdown exceeds thresholdbookTicker before market order, abort if spread too wideapt install ntpRegister Binance with code BNAPP for lifetime fee rebate — high-frequency auto strategies save more.
Sign up with referral code BNAPP for lifetime fee rebate