AI Trading Bots: From Pine Script to Live Orders
You tell an AI your trading idea, it spits back a Pine Script, you paste it into the chart and it compiles on the first try. This is genuinely easy now. What nobody tells you upfront is that "the code compiles" and "the code places live orders" are two completely different hurdles, and Pine Script has a long list of rules that determine which side of the gap you land on. This article does not comment on whether any particular AI tool is good or bad — we have not run these tests, and this article will not either.
This is not a tutorial on writing Pine (a scripting language designed specifically for charting platforms). Instead, it gives you three things:
- Which alerts qualify for webhook delivery
- Why your conditions trigger repeatedly
- How to design so failures stay silent
Layer 0 — Does this alert even qualify to send a webhook?
This filter is the simplest but most often overlooked. You must confirm that your TradingView plan supports webhooks, otherwise everything downstream is wasted effort.
| Plan | Webhook | Active price alerts | Technical alerts |
|---|---|---|---|
| Free | No | 3 | Not listed |
| Essential | Yes | 20 | 20 |
| Plus | Yes | 100 | 100 |
| Premium | Yes | 400 | 400 |
| Ultimate | Yes | 1,000 | 1,000 |
Source: TradingView official pricing page (verified October 2026)
Free plans do not support webhooks — this is an explicit stated limitation. If you see a tutorial claiming you can run automated trading for free, step one is already wrong.
A webhook is a URL string that pushes signals from your chart to your self-hosted server, letting you receive notifications when conditions are met. In simple terms, it is the "notification pipeline" for chart signals.
Layer 1 — The snapshot mechanism means your alert has no memory
Your alert re-evaluates on every candle bar. This sounds like a good thing — checking every bar ensures conditions trigger exactly when met. But the problem is: the alert itself has no memory.
This is not a bug, it is by design. But many AI-generated strategies do not account for this, writing logic that depends on cross-bar memory like "golden cross last week, death cross this week," only to find every bar starts from zero.
If you need cross-bar state persistence, you must use the var keyword:
var preserves values across bars
var int signalCount = 0 if crossover(sma(close, 14), sma(close, 28)) signalCount := signalCount + 1 alert("Golden cross #" + tostring(signalCount), alert.freq_once_per_bar)Without var, signalCount resets to 0 on every bar and will always be 1.
There is also an advanced keyword varip (variable intrabar persist), which not only preserves values across bars but also persists through multiple price updates within the same candle bar. This is useful in live trading scenarios — but backtests will not reproduce this behavior because historical data does not have tick-level updates.
Layer 2 — Are you getting an indicator, or a strategy?
Many "AI trading bots" give you nothing more than a plain indicator. Indicators only have two states: above/below, crossed up/down. They do not tell you: "I just fired, don't notify me again."
Pine Script has two ways to send alerts:
| Function | Default trigger frequency | Suitable scenario |
|---|---|---|
| alert() | freq_once_per_bar | Automated trading requiring dynamic messages |
| alertcondition() | User selects in Alert dialog | Simple condition notifications |
| alert() + freq_once_per_bar_close | Once per bar close | Avoid unconfirmed signal duplicates |
Source: Pine Script Language Reference v6 (verified October 2026)
The default frequency for alert() is freq_once_per_bar — meaning it fires once per bar as long as alert() is called once. If you place alert() inside an if condition and that condition may be evaluated multiple times within a single bar (e.g., with calc_on_every_tick=true on a strategy), it can fire several times.
For stricter duplicate prevention, use freq_once_per_bar_close, so the alert only fires when the candle closes. This avoids the "unconfirmed signal" problem — prices may fluctuate back and forth before a bar ends, causing conditions to be met repeatedly.
Layer 3 — The equity simulation trap
TradingView uses strategy.equity to calculate the order quantity sent via webhook. strategy.equity is a number fully simulated on TradingView's servers by the Pine strategy, equal to initial_capital + netprofit + openprofit.
Number scenario: Suppose your backtest used $100,000 initial_capital, with default_qty_type set to strategy.percent_of_equity and value 10 (i.e., 10%). Your actual exchange account only has $2,000.
When the alert fires and the webhook hits your execution server, how much quantity will actually be sent?
Answer: TradingView uses 10% of the strategy.equity at that current bar to calculate the order quantity — and strategy.equity = strategy.initial_capital + strategy.netprofit + strategy.openprofit, all computed and stored by TradingView's servers. If your backtest performs well and equity grows, the webhook-sent order quantities grow too — even though your real account does not have that much money.
Layer 4 — Webhook latency and loss
TradingView has never published any SLA for alerts lost during their own outages. We also do not publish an uptime guarantee for TVSBot, because we have no public SLA to offer either.
This means if your execution server (TVSBot, your own backend, or any intermediary) does not respond with HTTP 200 within 3 seconds, TradingView will abandon the send. It does not retry.
Additionally, TradingView has rate limits: if more than 15 alerts fire within three minutes, the system automatically pauses delivery. This is not an issue during backtests (because historical bar processing is batched), but it can become a bottleneck in live trading.
Design choices can reduce the probability of missed orders and narrow their impact, but cannot reduce the possibility to zero.
Layer 5 — Exchange disconnect auto-cancel, not everyone gets it
If an exchange goes down, will my positions close automatically? No official document explicitly says yes or no. But we checked the disconnect auto-cancel mechanisms for Binance, OKX, Bybit, and Bitget, and all are strictly limited to canceling pending orders — none mention positions.
The key point: none of these features are enabled by default. Every exchange requires manual setup, and some have client tier restrictions.
| Exchange | Disconnect cancel feature | Enabled by default | Notes |
|---|---|---|---|
| Binance | Yes (Kill-Switch) | No | Only for options/futures market makers |
| OKX | Yes | No | API protocol explicitly states orders remain valid |
| Bybit | Yes (DCP) | No | Institutional clients (Ins) only |
| Bitget | Yes (Deadman Switch) | No | Requires manual heartbeat config |
Source: Comparison of exchange official documentation (verified October 2026)
The only certainty is: none of the four exchanges will auto-liquidate your positions on disconnect. If a position has already been filled and price continues moving against you, you may face losses beyond what you expected.
- 3 seconds: TradingView webhook timeout limit
- Free: plan without webhook access
- 10%: default_qty_type default ratio
- 15 per 3 minutes: alert rate limit
Frequently Asked Questions
Can AI-generated Pine Script place live orders directly?
Why does the same condition trigger multiple times?
How severe is TradingView webhook latency really?
Why do indicator historical signals change?
Get started
TVSBot turns TradingView signals into automated trading — use your own API key, dry-run first, and set your own risk controls.
Start for freeThis article does not constitute investment advice. All figures mentioned come from official documents, public interviews, on-chain data — source citations available after the RelatedPosts section below. Crypto trading carries high risk; please assess your own risk tolerance.
- How to determine position sizing for TradingView webhook automated trading: funding ratio vs fixed quantity
- Pine Script alerts have no memory: why naive trigger logic breaks automation
- How severe is TradingView webhook delay? Official specs, common causes, and what can be fixed (2026)
- API key permissions checklist for non-custodial trading bots
- What happens to your automated strategy when TradingView or an exchange goes down? How to design failover