TradingView® Webhook Integration
How to configure TradingView® alerts, write copy-paste Pine Script™ v6 indicators, and link webhook signals to your edge gateway.
This page
Connecting TradingView® Alerts directly to your Hoox edge gateway is the most common way to automate your trading strategies. By combining TradingView® charting with Hoox's low-latency edge execution, you can trigger orders instantly based on mathematical indicators, chart patterns, or custom Pine Script™ v6 logic.
This tutorial walks you through writing a Pine Script™ v6 script, setting up a TradingView® webhook alert, and testing executions.
💻 Step 1: Writing a Pine Script™ v6 Signal Indicator
To trigger clean trade alerts, use TradingView®'s Pine Script™ (//@version=6). Below is a copy-paste indicator script that evaluates a Moving Average Cross strategy and generates standardized trade alert signals:
//@version=6
indicator("Hoox EMA Cross Signals", overlay=true)
// 1. Inputs & Parameters
fastLength = input.int(9, title="Fast EMA Length")
slowLength = input.int(21, title="Slow EMA Length")
// 2. Indicators Calculation
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.orange, title="Slow EMA")
// 3. Trade Conditions
longCondition = ta.crossover(fastEMA, slowEMA)
shortCondition = ta.crossunder(fastEMA, slowEMA)
plotshape(longCondition, title="Long Cross", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(shortCondition, title="Short Cross", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// 4. Alert Payloads Construction (JSON compliant)
// Live:
longAlertJson = '{"apiKey": "your-hoox-webhook-passkey", "exchange": "bybit", "action": "LONG", "symbol": "BTCUSDT", "quantity": 0.001, "leverage": 10}'
shortAlertJson = '{"apiKey": "your-hoox-webhook-passkey", "exchange": "bybit", "action": "SHORT", "symbol": "BTCUSDT", "quantity": 0.001, "leverage": 10}'
// Testnet rehearsal (optional — add "test": true; prefer BYBIT_TESTNET_* secrets):
// longAlertJson = '{"apiKey": "your-hoox-webhook-passkey", "exchange": "bybit", "action": "LONG", "symbol": "BTCUSDT", "quantity": 0.001, "leverage": 10, "test": true}'
// 5. Trigger Alerts
if (longCondition)
alert(longAlertJson, alert.freq_once_per_bar_close)
if (shortCondition)
alert(shortAlertJson, alert.freq_once_per_bar_close)
Tip
Replace "your-hoox-webhook-passkey" in your Pine Script™ with the actual
passkey configured in your CONFIG_KV store (webhooks:api_key). This is a
critical security step—the gateway will reject any alerts with mismatched keys
with a 401 Unauthorized error. For exchange testnet rehearsal, add
"test": true to the JSON and configure dedicated testnet secrets — see
Test Trading.
🔔 Step 2: Creating the TradingView® Webhook Alert
Once your script is saved and added to your chart:
- Click the Alarm Clock (Alerts) icon on the top right panel in TradingView®.
- Select Condition: Choose your indicator
"Hoox EMA Cross Signals"and select"Any Alert Function Call"(this directs TradingView® to parse the custom JSON payloads from thealert()functions inside your script). - Under Expiration: Select your alert lifespan (Premium accounts support Open-Ended alerts).
- Navigate to the Notifications Tab:
- Check the Webhook URL box.
- Paste your public Hoox Gateway endpoint URL:
https://hoox.alpha-trading.workers.dev/webhook
- Navigate to the Settings Tab:
- In the Message box, type:
{{strategy.order.alert_message}}(if using a Backtesting Strategy) or leave it blank (if using an Indicator, as the JSON payload is already defined inside ouralert()function).
- In the Message box, type:
- Click Create.
🔍 Step 3: Verifying Execution in Production
When the Moving Average crossover occurs on your chart:
- TradingView® compiles the JSON payload and POSTs it to your edge gateway.
- The
hooxgateway validates the signature and routes the order to Bybit. - Check the transaction directly in your terminal:
hoox monitor trades - Stream live gateway telemetry logs to verify execution latency:
hoox logs worker hoox
🛠️ Webhook Troubleshooting Runbook
| Symptom / Error | Primary Cause | Resolution |
|---|---|---|
| Alert fires but no trade executes | Mismatched API keys or WAF block. | Run hoox logs worker hoox to stream traffic. Check if the client IP was dropped by Cloudflare® WAF. |
401 Unauthorized | Incorrect apiKey in Pine Script™. | Run hoox config kv get webhooks:api_key to check your key. Paste the exact string into your Pine Script™ alert payload. |
409 Conflict | Double-alert fired within the same bar. | Adjust the alert frequency in Pine Script™: use alert.freq_once_per_bar_close instead of alert.freq_all to prevent rapid-fire retries. |
Invalid Symbol API reject | Symbol format mismatch. | Hoox automatically converts variations (like BTC-USDT or btc/usdt) to BTCUSDT, but ensure your script sends standard uppercase symbols. |
🔗 Next Steps
- Setting Up Telegram Alerts — Integrate Telegram notifications to get fills pushed directly to your phone.
- API Endpoint Reference — Review full request schemas and status codes.