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:

pinescript
//@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 EXCHANGE_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 value of WEBHOOK_API_KEY_BINDING on the hoox gateway (hoox setup writes it). A mismatch is rejected (403 Forbidden). For exchange testnet rehearsal, add "test": true to the JSON and configure EXCHANGE_TESTNET_* secrets — see Test Trading. DEX spots use exchange: "uniswap-ethereum" (or uniswap-arbitrum / jupiter-solana) and symbol: "ETH/USDC" — they reject "test": true.


🔔 Step 2: Creating the TradingView® Webhook Alert

Once your script is saved and added to your chart:

  1. Click the Alarm Clock (Alerts) icon on the top right panel in TradingView®.
  2. 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 the alert() functions inside your script).
  3. Under Expiration: Select your alert lifespan (Premium accounts support Open-Ended alerts).
  4. Navigate to the Notifications Tab:
    • Check the Webhook URL box.
    • Paste your public Hoox Gateway endpoint URL: https://hoox.alpha-trading.workers.dev/webhook
  5. 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 our alert() function).
  6. Click Create.

🔍 Step 3: Verifying Execution in Production

When the Moving Average crossover occurs on your chart:

  1. TradingView® compiles the JSON payload and POSTs it to your edge gateway.
  2. The hoox gateway validates the signature and routes the order to the exchange in the payload (Bybit in this example; DEX venues use BASE/QUOTE — DEX spot swaps).
  3. Check the transaction directly in your terminal:
    bash
    hoox monitor trades
    
  4. Stream live gateway telemetry logs to verify execution latency:
    bash
    hoox logs worker hoox
    

🛠️ Webhook Troubleshooting Runbook

Symptom / ErrorPrimary CauseResolution
Alert fires but no trade executesMismatched API keys or WAF block.Run hoox logs worker hoox to stream traffic. Check if the client IP was dropped by Cloudflare® WAF.
403 ForbiddenIncorrect apiKey in Pine Script™.The body apiKey must match the WEBHOOK_API_KEY_BINDING secret on the hoox gateway (hoox secrets list hoox).
409 ConflictDouble-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 rejectSymbol format mismatch.Hoox automatically converts variations (like BTC-USDT or btc/usdt) to BTCUSDT, but ensure your script sends standard uppercase symbols.

🔗 Next Steps