Turn a TradingView strategy into an automated trading bot
You have a strategy in TradingView. The chart shows the signals, the backtest tab shows the trades, and you want it to place orders at your broker without you sitting there. There are two honest ways to do that. This guide explains both, what carries across cleanly and what does not, and what to send us if you want it built. The strategy is yours throughout; we move it, we do not judge it.
The two routes
- Route A: keep the strategy in TradingView, send alerts to a bot. TradingView fires an alert with a message; a small execution service receives it over a webhook and places the order through your broker's API. Fast to build, keeps your Pine Script as the source of truth, depends on TradingView being up.
- Route B: rewrite the strategy in Python at the broker. The rules are re-implemented against the broker's own data and API. More work, fully yours, runs without TradingView, and the backtest becomes an honest one. This is the route when the strategy is the business, not a side project.
Route A suits a strategy you are still changing, one broker, modest order complexity. Route B suits a strategy you trust, or one whose rules need more than an alert can carry (position sizing from your account balance, multi-leg options, several instruments at once).
Route A in detail: webhook alerts into an execution service
TradingView alerts can post a message to a URL. The message is text you write, so the first job is to make it structured. Something like this, with placeholders that TradingView fills in:
{
"secret": "a-long-random-string",
"ticker": "{{ticker}}",
"action": "{{strategy.order.action}}",
"qty": "{{strategy.order.contracts}}",
"price": "{{close}}",
"time": "{{timenow}}",
"id": "{{strategy.order.id}}"
}The receiver is a small web service that runs on a server you control (or we host it for you). Its job list is short and every item matters:
- Authenticate. Reject anything without the secret. TradingView's outbound IP addresses are published; the receiver can check those as well.
- Handle each alert once. Alerts can be delivered twice, and a retry after a timeout looks like a new signal. The receiver records the alert id and ignores a repeat. This one item prevents the most expensive class of bug: double orders.
- Sanity-check before sending. Symbol exists at the broker, quantity is inside your limits, price is not absurd, the market is open, and you do not already hold more than the rule allows.
- Place the order and confirm it. Through the broker's API, then read back the fill, because "sent" is not "filled".
- Know what to do when TradingView fires while the broker is down. Queue it with an expiry, or drop it and alert you. Either is fine; not deciding is not.
- A kill switch and a log. A single setting that stops all new orders, and a record of every alert in and every order out, so you can answer "what happened at 10:42?" a week later.
On brokers with a public API this is a compact piece of software: Interactive Brokers, TradeStation, Tastytrade, MetaTrader 5 via a bridge, and on the Indian side Zerodha, Angel One, ICICI Direct, Upstox and FYERS. It is usually a starter build.
Route B in detail: rewriting the Pine Script at the broker
A rewrite means the strategy runs against the broker's data and API with no TradingView in the loop. Most of Pine translates directly: moving averages, RSI, ATR, crossovers, stops and targets, session filters. The parts that need care are the ones people do not notice in TradingView because the chart does it for them:
- Repainting. A Pine script evaluated on every tick can act on a bar that has not closed. A Python version sees only closed bars. If your TradingView backtest relied on the former, the honest version will look different. Better to learn that on a paper account than in a live one.
- Higher-timeframe data and lookahead. Pulling a daily value into an intraday strategy is easy to do with a peek into the future. The rewrite has to use only what was known at the time.
- Bar timing. TradingView's bars and your broker's bars can start at different seconds and treat the first bar of the session differently. Small differences in bar boundaries change signals near the edges.
- Fills and costs. The TradingView backtester fills at the close of the signal bar by default. A real order fills later, at a worse price, and pays commission and slippage. Our guide to how we work covers the gap between a backtest and live trading in more detail.
- Sizing from the account. Pine sizes from a fixed equity number. A bot can size from your real balance and margin, which is usually what you actually wanted.
A rewrite skeleton is the same on every broker: a data loop that builds closed bars, a rules function that takes bars and returns a decision, an order layer that turns a decision into broker calls and reads back the result, and a state store that survives a restart. The strategy lives only in the rules function, which is why it stays yours and why we can build the rest without needing to agree with it.
Which brokers this works with
Any broker with an official API. For US, Canadian and European clients that is most commonly Interactive Brokers, TradeStation, Charles Schwab, Tastytrade, Saxo and the MetaTrader brokers. In India it is Zerodha, Angel One, ICICI Direct, Upstox, FYERS and Dhan, with one honest note: Indian brokers require their official API and, at most of them, a monthly API subscription. Browser automation and unofficial endpoints are not something we build on. The full list of platforms and brokers we have delivered on is on the technology page.
What to send us
The same six things as any build, plus two specific to TradingView: whether you want Route A or Route B (or our recommendation), and the Pine Script itself, or a plain-English description of the rules if you would rather not share code yet. Market and broker, rules, timeframe and instruments, data, ownership, and the budget you have in mind. The starter trading bot page shows two example briefs, and what a custom trading bot costs explains what will move the quote. We build the software to your rules; we do not supply strategies, and nothing here is investment advice.
Common questions
- Can TradingView place orders at my broker by itself?
- Only through the brokers integrated into TradingView, with their limits, and not for every order type or market. For anything else, or for Indian brokers, the alert goes to a small piece of software that places the order through your broker's own API.
- Is a webhook safe enough for real orders?
- Yes, if the receiver is built properly: a secret in the alert message, a check that each alert is handled once and only once, sanity limits on size and price, and a kill switch. A bare script that trusts anything posted to it is not safe, and we would not ship one.
- Will my strategy still repaint after it is moved?
- A rewrite in Python only ever sees closed bars, so it cannot repaint. That is also why its backtest can differ from the TradingView one: if the Pine version was quietly using information from inside the current bar, the honest version will show different results. That difference is real and worth knowing about.
- What does it cost to move a TradingView strategy to a bot?
- A webhook receiver for one broker is usually a starter build. A full rewrite depends on how much the Pine script does. Our cost guide explains what drives the number; the brief gives us what we need for a fixed quote.
- Can I keep using TradingView for charts?
- Of course. Many clients keep TradingView for charting and alerts and let the bot handle execution. The two are not in competition.