From Pine Script Alert to Live Bot: Closing the Gap Without Losing Control

Back to Blog

TRADINGVIEW · PINE SCRIPT · AUTOMATION

Short answer: TradingView alerts connect to a trading bot via webhooks: a Pine Script condition fires an HTTP POST with a JSON payload that the bot parses into an order. The handoff is where most automated setups actually break — duplicate fills, stale signals, and slippage the backtest never modeled. Comparing the live trade CSV against the original Strategy Tester export is how you catch the gap.

An alert firing is not the same as an order filling

A Pine Script strategy that prints buy and sell signals on a chart is a prototype, not a trading system. The gap between ‘the condition triggered’ and ‘the bot placed the order’ is where most algo setups actually break — and it’s rarely the strategy logic that’s at fault.

TradingView alerts are the standard bridge: a condition defined in Pine Script fires a webhook, and whatever is listening on the other end turns that payload into an order on an exchange. Simple in principle, but every step between the alert and the fill is a place slippage, duplication, or silent failure can creep in.

What the alert payload actually needs to carry

A webhook alert message built from Pine Script’s {{strategy.order.alert_message}} or a manually templated JSON string should carry enough for the receiving bot to act without ambiguity: symbol, side, order type, size (or a formula the bot can resolve), and a strategy or run identifier — not just ‘buy’ or ‘sell’ with nothing else.

Two failure modes show up constantly in exported trade logs once a bot has been running for a while: duplicate fills from a single alert retried by TradingView’s webhook delivery, and stale signals executed late because the listener was down when the alert fired. Both are visible after the fact in the CSV export — rarely in the equity curve.

Why the backtest CSV still matters after the bot is live

The Strategy Tester’s exported trade history isn’t just a pre-launch check — it’s the baseline you compare live execution against. If live fills consistently show worse entry prices or larger slippage than the backtest assumed, the gap is measurable trade by trade, not just a feeling that ‘live doesn’t match the backtest.’

That comparison is exactly what an audited CSV is for: catching a commission model that doesn’t match the real exchange fee, or a fill assumption that never held once real order books were involved.

Building the alert-to-bot pipeline still starts on the charting side → check TradingView’s plans for alert limits and webhook support — then run both the backtest and the live trade CSV through TGL’s auditor to see where they actually diverge.

Keep the human in the loop until the numbers earn it

None of this argues against automation — it argues against trusting an alert-to-bot pipeline just because it hasn’t visibly failed yet. The same transparency principle behind how we document our own datasets applies here: log every fill, compare it against the backtest assumption, and let the discrepancy — not the equity curve alone — decide whether the pipeline is ready for more size.

Explore

More from the blog