TradingView Alerts to Webhook: Step‑by‑Step Workflow, Alert Payload Templates, and Maintenance Checklist
TradingViewAlertsWebhookPine ScriptAlgo TradingTrading Bot

TradingView Alerts to Webhook: Step‑by‑Step Workflow, Alert Payload Templates, and Maintenance Checklist

MMarket Lens Editorial Team
2026-11-11
8 min read

Learn how to connect TradingView alerts to a webhook and trading bot with Pine Script payloads, broker mapping, testing, monitoring, and rollback steps.

TradingView Alerts to Webhook: A Reliable Workflow for Trading Bots

TradingView alerts can connect a chart condition to a webhook receiver and, ultimately, an execution bot. This guide explains the full workflow, provides reusable Pine Script and JSON payload patterns, maps alert fields to broker parameters, and gives you a testing, rollback, and maintenance routine before and after going live.

Overview

A webhook is an HTTP endpoint that receives an alert message from TradingView. In a typical algo trading setup, the process has five stages:

  1. Chart trigger: A condition occurs in an indicator or TradingView strategy.
  2. Pine Script message: The script creates a structured alert containing the intended action and relevant market data.
  3. TradingView alert: The alert is configured with the correct condition, frequency, expiration, and webhook URL.
  4. Webhook receiver: Middleware validates the request, records it, and translates the message into the format expected by a broker or exchange API.
  5. Execution and monitoring: The bot checks risk rules, submits or rejects the order, and records the result for later review.

The webhook should not be treated as a direct substitute for risk controls. A valid alert only says that a condition occurred; it does not guarantee that an order should be placed. The receiver should independently check the symbol, side, quantity, price, account status, duplicate-event status, and trading permissions before sending an order.

Before building the connection, define whether the alert is an entry, exit, stop adjustment, cancellation, or informational event. Keep the message vocabulary small and explicit. For example, use buy, sell, close_long, and close_short rather than relying on ambiguous text such as signal.

What to track

1. Build a structured Pine Script alert

A machine-readable message is safer than a sentence intended for a human. Include a unique event identifier, the action, symbol, timeframe, signal price, and a version number. The receiving application can then reject incomplete or outdated messages.

For a study or indicator, a dynamic alert() call can create a JSON message when a condition is true:

//@version=6
indicator('Webhook signal example', overlay=true)

fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
longSignal = ta.crossover(fast, slow)
shortSignal = ta.crossunder(fast, slow)

if longSignal
    message = str.format('{{"version":"1","event_id":"{0}-{1}","action":"buy","symbol":"{2}","timeframe":"{3}","price":{4}}}', str.tostring(time), syminfo.tickerid, syminfo.tickerid, timeframe.period, str.tostring(close, format.mintick))
    alert(message, alert.freq_once_per_bar_close)

if shortSignal
    message = str.format('{{"version":"1","event_id":"{0}-{1}","action":"sell","symbol":"{2}","timeframe":"{3}","price":{4}}}', str.tostring(time), syminfo.tickerid, syminfo.tickerid, timeframe.period, str.tostring(close, format.mintick))
    alert(message, alert.freq_once_per_bar_close)

This example is a starting pattern, not a complete trading system. Confirm that the signal is evaluated on the intended bar, and decide whether intrabar alerts are acceptable. Bar-close alerts are often easier to reconcile with backtests, while intrabar alerts can arrive before a candle is complete and may change the operational behavior of the strategy.

If you use a strategy script, you can also configure order-fill alerts and provide an alert message through the strategy's order functions. Keep the payload format consistent between indicator alerts and strategy alerts so the receiver does not need separate parsing logic for every script.

2. Configure the TradingView alert

  1. Add the script to the intended chart and confirm the symbol, exchange, session, and timeframe.
  2. Create an alert using the script condition. Select the intended trigger frequency rather than accepting a default without review.
  3. Enable the webhook URL field and enter an HTTPS endpoint controlled by your receiving service.
  4. Use the alert message generated by the script, or enter a fixed test payload when validating the endpoint.
  5. Set an expiration that matches your operating plan and document the alert name, chart, and script version.

Do not assume that changing a script automatically changes an existing alert. After editing Pine Script, review the alert and recreate or update it if necessary. A useful naming convention includes the environment, symbol, timeframe, and version, such as paper-BTCUSD-15m-v3 or live-SPY-1h-v2.

3. Design the webhook receiver

The receiver should separate intake from execution. First, accept the request, validate its shape, authenticate it, and store the raw message. Then place it in a queue or controlled processing step. This prevents a slow broker response from making the alert intake difficult to diagnose.

Use HTTPS, keep credentials out of the TradingView message where possible, and authenticate requests with a secret that can be rotated. Never place broker API keys in Pine Script. The receiver should use environment-managed credentials and restrict those credentials to the minimum permissions required. If the endpoint is exposed publicly, add rate limits, request-size limits, structured logs, and an emergency disable switch.

4. Use a predictable payload

A general TradingView webhook template can look like this:

{
  "version": "1",
  "event_id": "unique-event-id",
  "source": "tradingview",
  "environment": "paper",
  "action": "buy",
  "symbol": "EXCHANGE:SYMBOL",
  "timeframe": "15",
  "order_type": "market",
  "quantity": 1,
  "signal_price": 100.25,
  "stop_loss": 98.75,
  "take_profit": 103.25,
  "bar_time": "2026-01-01T12:00:00Z"
}

Use numeric JSON values for prices and quantities when the receiver expects numbers. Validate decimal precision, minimum order size, lot size, and whether the broker expects a base-asset quantity, quote-currency amount, contracts, or shares.

5. Map fields to broker parameters

Alert fieldTypical broker or exchange parameterValidation to perform
actionSide, order action, or position instructionAllow only approved values; distinguish entry from exit.
symbolInstrument, ticker, or contract symbolMap TradingView symbols to the broker's exact identifier.
order_typeMarket, limit, stop, or stop-limitRequire the relevant price fields for non-market orders.
quantityQuantity, size, or order amountCheck risk budget, precision, minimum size, and available buying power.
signal_priceReference price or limit priceDo not treat it as a fill price; compare it with current market data if needed.
stop_loss and take_profitAttached exits or separate protective ordersCheck tick size, direction, distance, and whether the API supports bracket orders.
event_idClient order ID or idempotency keyReject duplicates before submitting a second order.

Broker APIs differ in naming and behavior, so this table is a conceptual mapping rather than a universal request schema. Read the destination API documentation and write a small adapter for each broker or exchange. Keep the TradingView payload stable while changing only the adapter layer.

For position sizing and stop placement, see the TradingView position size and stop-loss guide. A webhook can automate an order, but it cannot decide whether the risk is appropriate unless you explicitly encode and enforce that rule.

Cadence and checkpoints

Before every live deployment

  • Run the script on the intended symbol and timeframe and verify that the chart condition occurs where expected.
  • Send a test message to a non-production endpoint or paper account.
  • Confirm that the receiver logs the complete request without exposing secrets.
  • Check authentication, JSON parsing, symbol mapping, side, quantity, and order type.
  • Test duplicate delivery using the same event_id; the second request should not create another position.
  • Test malformed JSON, an unknown symbol, an unsupported action, an excessive quantity, and a stale timestamp.
  • Confirm that a broker rejection is recorded and does not trigger an unbounded retry loop.
  • Verify the emergency stop, alert disable process, and manual position-closing procedure.

Keep a paper-trading or sandbox path separate from production. Label every environment in the payload and use separate credentials and endpoints. Before moving to live execution, compare alert events with the strategy's historical and forward-testing results. The TradingView backtesting guide covers common ways that backtests can diverge from live behavior.

After deployment

Review the system after the first few signals rather than waiting for a trade to fail. Match each TradingView event to a receiver log, broker request, broker response, and final position state. Useful fields include received time, event ID, processing status, rejection reason, retry count, order ID, fill status, and resulting position.

On a monthly basis, review alert activity, duplicate rates, rejected orders, latency, open positions, and any difference between intended and actual quantities. On a quarterly basis, review credentials, endpoint access, dependency versions, broker API changes, symbol mappings, and the script's assumptions about sessions and bar timing.

How to interpret changes

A missing order does not automatically mean that TradingView failed. Trace the event through each layer:

  1. No chart event: Check the condition, timeframe, session filters, bar confirmation, and whether the alert is still active.
  2. Chart event but no receiver log: Check the webhook URL, alert status, endpoint availability, and network or service logs.
  3. Receiver log but no broker request: Inspect authentication, schema validation, duplicate handling, risk limits, and symbol mapping.
  4. Broker request but rejected order: Check permissions, buying power, quantity precision, market hours, instrument status, and order parameters.
  5. Order accepted but position is wrong: Reconcile partial fills, retries, close-versus-reverse logic, and whether the bot received a stale or repeated event.

Pay particular attention to changes in signal frequency. A sudden increase can result from a script edit, a timeframe change, a duplicate alert, a session setting, or a condition that is firing on every update rather than once per completed bar. A sudden decrease can result from an expired alert, a disabled script, a symbol mismatch, or a receiver rejecting a newly changed payload.

When behavior changes, pause live execution first if the cause is uncertain. Preserve the raw payload and logs, reproduce the issue in paper trading, and make one change at a time. If the strategy logic itself needs review, the Pine Script tutorial on building and maintaining indicators provides a useful development workflow.

When to revisit

Revisit this workflow immediately after any change to Pine Script alert formatting, alert frequency, chart timeframe, symbol convention, webhook headers, receiver code, authentication, or broker API behavior. A small naming or schema change can be enough to stop execution or produce an unintended order.

Use a recurring schedule as well:

  • Before each live deployment: Repeat the test plan, including duplicate-event and rollback tests.
  • Monthly: Review logs, failed requests, retries, alert status, exposure, and reconciliation between signals and positions.
  • Quarterly: Rotate secrets where appropriate, review permissions, test the emergency stop, confirm API mappings, and inspect external service dependencies.
  • After an incident: Disable or isolate the affected alert, preserve evidence, identify the failing layer, and document the corrective change before re-enabling execution.

Maintain a short change record containing the script version, payload version, endpoint version, broker adapter version, and deployment date. Mark the test plan and safety checklist for immediate review when TradingView changes alert formatting or webhook behavior. This simple record makes it easier to determine whether a new failure is caused by market conditions, strategy logic, infrastructure, or an integration change.

The safest default is to automate notification first, paper execution second, and live execution only after the complete path has been tested with realistic edge cases. A TradingView alerts webhook can be a dependable part of an algo trading system, but reliability comes from validation, idempotency, monitoring, and a practiced rollback process—not from the alert alone.

Related Topics

#TradingView#Alerts#Webhook#Pine Script#Algo Trading#Trading Bot
M

Market Lens Editorial Team

Trading Technology Editors

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.