tradingview strategy tutorial

How to create a trading bot in TradingView

Learn how to create a trading bot in TradingView using Pine Script strategies, alerts, and a webhook bridge to execute trades on your broker automatically.

Jonathan FillEdge 10 min read
How to create a trading bot in TradingView — FillEdge
In this article
  1. What “trading bot” actually means in TradingView
  2. Turn your indicator into a strategy
  3. Backtest before you automate
  4. Alerts and webhooks: where your bot leaves TradingView
  5. The gap between an alert and a trade
  6. Running a TradingView bot on a prop firm account
  7. How FillEdge gets your TradingView alerts to your broker
  8. FAQ

TradingView doesn’t trade. It charts, it backtests, it fires alerts. But the moment you want those alerts to open a position at your broker, you’ve left TradingView’s territory.

The thing most people call a “TradingView trading bot” is actually three separate pieces: a Pine Script strategy (say, an EMA crossover on EURUSD), an alert with a webhook, and an execution layer that places the order at your broker. TradingView handles the first two. The third is on you.

What “trading bot” actually means in TradingView

Pine Script can’t send orders to a broker. It can’t make HTTP requests, can’t open sockets, can’t talk to any external API. What it can do is run strategy logic, calculate entries and exits, and fire alerts when conditions trigger.

So when someone says they’ve built a trading bot in TradingView, what they actually have is a strategy script that generates signals. The “bot” part, the automated execution at a real broker, happens outside TradingView entirely. You need something sitting between TradingView and your broker account to receive those alerts and convert them into real orders on IC Markets, Pepperstone, or wherever your funds are held.

This is different from writing an MQL5 Expert Advisor that runs natively inside MetaTrader. An EA is a true self-contained bot: it reads price data, makes decisions, and places orders, all in one environment. TradingView splits decision-making (Pine Script) from execution (your broker’s terminal). That split is what makes TradingView great for strategy development and terrible for actual trade execution. Understanding the difference between copy trading and bot trading matters here, because a bot is your own logic running automatically, not someone else’s signals forwarded to your account.

Turn your indicator into a strategy

Most bots start as indicators. If you’ve been using one that paints buy/sell arrows on the chart, you’re halfway there. But an indicator can’t fire strategy alerts. You need to convert it to a strategy.

The difference is structural. An indicator uses indicator() at the top and calls like plotshape() to draw on the chart. A strategy uses strategy() and calls strategy.entry() to simulate trades. TradingView’s Strategy Tester only works with the second type.

Here’s a minimal example. Say your indicator logic boils down to “buy when a 9-period EMA crosses above a 21-period EMA on EURUSD, sell when it crosses below”:

//@version=6
strategy("EMA Cross", overlay=true)

fast = ta.ema(close, 9)
slow = ta.ema(close, 21)

if ta.crossover(fast, slow)
    strategy.entry("Long", strategy.long)

if ta.crossunder(fast, slow)
    strategy.entry("Short", strategy.short)

That’s it. Five lines of logic. The strategy.entry() calls are what make this a bot instead of a drawing tool. When you add an alert to this strategy, TradingView can fire a webhook every time strategy.entry() triggers.

If you already have an indicator with buy/sell conditions, converting your Pine Script indicator into a strategy is mostly a matter of replacing plot calls with strategy.entry() and strategy.exit() calls. The logic stays the same.

Backtest before you automate

TradingView’s Strategy Tester is genuinely good for one thing: telling you whether your logic has any edge at all. Add the strategy to a chart, and you get an instant full equity curve, trade list, and performance summary. No other tool makes this faster.

But the backtest lies in specific ways you need to understand before you trust it with real money.

First: fills are idealized. The Strategy Tester assumes you get filled at the exact price at which your condition triggered. It won’t be. On XAUUSD during London open, that assumption can be off by 20-50 points of slippage, depending on your broker. On a strategy that targets 100-point moves, that’s 20-50% of your edge eaten before you start.

Second: daily bars hide intrabar behavior. If your strategy runs on the daily timeframe, the backtest evaluates conditions once per day at bar close. In live trading, your alert fires at bar close, too, but the fill happens seconds or minutes later at whatever price the market is at. For high-volatility pairs, the close price and the fill price can be very different.

Third: repainting. Some indicators recalculate their values after the bar closes. A signal that looks clean in hindsight may have flickered on and off three times during the live bar. Your strategy would have fired three alerts instead of one.

The honest answer: backtest results on daily bars are a rough filter, not a prediction. Run your backtest on the timeframe you’ll actually trade on, assume 1-2 spreads of slippage on every entry and exit, and discount win rates by 5-10% from what the tester shows. If the strategy still looks profitable after that haircut, you have something worth automating.

Alerts and webhooks: where your bot leaves TradingView

Once your strategy is backtested and you’re satisfied with the results, the next step is to set up an alert that triggers a webhook. This is the mechanism that lets your strategy talk to the outside world.

In TradingView, create an alert on your strategy. Under “Notifications,” enable the webhook URL field and paste the URL of the service that will receive the signal. The alert message is the payload, a short string that tells the receiver what to do. A typical format looks like this:

buy,EURUSD,0.1,sl=1.0850,tp=1.0950,account=live1

That message tells the receiving service to open a buy order for EURUSD, 0.1 lots, with a specific stop-loss and take-profit, routed to account “live1.”

One prerequisite catches many people off guard. Webhooks require a TradingView Essential plan at a minimum. The free plan doesn’t support them. If you’re on the free plan, your strategy can backtest all day, but it can’t send signals anywhere. This is a hard gate, and there’s no workaround.

The webhook itself is just an HTTP POST request. TradingView fires it, some server receives it, and that server is responsible for turning the payload into a real trade at your broker. The question is: what’s on the other end of that URL? That’s where most setups fail, because the connection between your alert and your broker is the part TradingView doesn’t handle. If you’re trying to connect your broker to TradingView, the webhook is the only official mechanism.

The gap between an alert and a trade

So you have a strategy. It fires alerts. The alerts carry a webhook payload with your trade instructions. Now what?

This is the part that looks simple and isn’t. The alert needs to reach your broker terminal, get parsed into an order, and execute with the right symbol, lot size, direction, stop-loss, and take-profit. Every one of those steps is a potential failure point.

The most common failures aren’t dramatic. They’re quiet, small, and they add up.

Ghost positions. Your strategy closes a trade in Pine Script, but the alert fires before TradingView confirms the fill. The receiver opens a new position that was never supposed to exist. That’s a ghost. You don’t notice until you check the account the next morning.

Duplicate fills. TradingView retries a webhook that already succeeded. Your broker opens the same trade twice. Now you’re running double the intended exposure.

Out-of-order reversals. Your strategy reverses from long to short. That’s two signals (close long, open short) traveling as separate HTTP requests. If the “open short” arrives before the “close long,” you end up with both positions open simultaneously. The close then kills the wrong one.

SL drift. Your strategy calculates a stop-loss at 1.0832. By the time the order reaches the broker, the entry price has slipped, but the SL stays at the absolute value. Your actual risk per trade is different from what the backtest showed.

Each of these happens rarely on any single signal. But across 200 signals a month, you’ll hit several, and the gap between your backtest equity curve and your live one starts to widen in ways you can’t explain by looking at any individual trade. If you’re looking at a properly configured TradingView webhook and wondering why your live results don’t match your backtest, these failure modes are usually the answer.

**FillEdge closes this gap for you, automatically. → **Get early access

Running a TradingView bot on a prop firm account

Everything above applies to personal accounts. Prop firm evaluations make it worse.

A prop firm gives you a funded account with rules: a maximum drawdown (typically 5-10%), a daily loss limit (often 4-5% of starting balance), and sometimes trailing drawdown floors that ratchet up as your equity grows. Break any rule once, even by a fraction, and the evaluation ends. No appeals process. No undo.

Now imagine running an unattended TradingView bot on that account. A ghost position opens while you’re asleep. It goes against you. It breaches the daily loss limit by $12. Evaluation over.

Or your strategy reverses on XAUUSD during a volatile NFP print. The close and open signals arrive out of order, and you end up holding the wrong direction during the biggest move of the week. You wake up inverted. By the time you check, the trailing drawdown floor has been breached.

What makes this brutal is the math behind prop firm risk management rules: the limits are absolute, and a single breach on a single day voids weeks of profitable trading. A personal account can survive a ghost position. You lose some money, fix the bug, move on. But a prop firm evaluation can’t absorb even one of these failures if it happens on the wrong day, because one breach ends the entire run regardless of how many profitable signals came before it.

If you’re going to run a bot on a prop firm evaluation, you need something between your strategy and the broker that understands the firm’s rules and can block or reduce a trade before it causes a violation. Manual monitoring doesn’t scale, especially if you’re running more than one evaluation at a time.

How FillEdge gets your TradingView alerts to your broker

FillEdge is an execution bridge. You point your TradingView webhook at FillEdge, and FillEdge delivers the trade to your broker account with verified fills and exact stop-loss placement.

The setup takes about fifteen minutes. You get a single webhook URL when you sign up. Every strategy you run points at the same URL. The alert message format is simple, and FillEdge’s template builder generates the exact string for you. Paste it into TradingView, save, done.

What happens after the alert fires is where FillEdge is different from a raw webhook relay.

Every signal is reconciled against the actual fill. FillEdge compares what TradingView sent (entry price, SL, TP, lot size, direction) with what the broker executed. If the two match, the signal gets a ✓MATCHED badge. If the stop-loss landed at the exact price your strategy calculated, even when the entry slipped by a few points, it gets 🎯LOCKED. Mismatches show you exactly what differed and why.

Ghost positions get intercepted before they reach the broker. When FillEdge detects a duplicate execution or a signal that contradicts your strategy’s current state, it blocks the trade and tags it 👻CAUGHT or 🛡️BLOCKED. No silent rejections. You see every interception in the dashboard with the reasoning attached.

Reversals are sequenced correctly. If close and open signals arrive out of order, FillEdge delivers them in the right sequence: close first, then open. The signal log shows 🔀REORDERED so you know the bridge intervened.

For prop firm accounts, FillEdge ships with built-in compliance profiles for FTMO, Funding Pips, FundedNext, The 5%ers, and others. Bind your account to a profile. From that point on, every incoming signal is checked against your remaining risk budget before it reaches the broker. If a trade would breach a rule, FillEdge blocks it or auto-reduces the lot size. Your choice, per strategy.

And if you’ve been comparing MetaTrader and TradingView as separate tools, FillEdge is the piece that connects them. Your strategy stays in Pine Script. Your execution happens at the broker through whatever terminal you use. The bridge makes sure the two agree.

The journal that FillEdge generates automatically records every signal, every fill, every reconciliation decision, and every guardrail intervention. Per-strategy performance, slippage tracking, latency numbers, anomaly flags. The spreadsheet you were going to build and abandon after a week is already done.

FAQ

Can you build a bot for TradingView?

Yes, but TradingView only handles half of it. You can write a Pine Script strategy that generates buy and sell signals, backtest it, and set it to fire webhook alerts when conditions trigger. The actual trade execution (placing orders at your broker) happens outside TradingView, through a webhook bridge like FillEdge that receives those alerts and delivers them to your broker account as real trades.

Can I run a TradingView bot on a prop firm account?

You can, but unattended automation on a prop firm evaluation carries real risk. A single ghost position, a duplicate fill, or an out-of-order reversal can breach a daily loss limit or trailing drawdown floor and end the evaluation instantly. If you’re automating a prop firm account, you need a bridge with built-in compliance guardrails that can block or reduce a trade before it violates your firm’s rules.

What programming language does TradingView use for trading bots?

Pine Script. It’s TradingView’s built-in language, designed specifically for writing indicators and strategies on TradingView charts. Pine Script is easier to learn than Python or MQL5 for trading logic, but it can’t place orders at a broker directly. To turn a Pine Script strategy into a working bot, you need to pair it with TradingView’s webhook alerts and an external execution bridge that sends the trades to your broker.

How long does it take to set up automated trading from TradingView?

It depends on what you’re connecting to. A DIY setup with a VPS, a Python script, and a broker API can take a weekend and tends to break when anything updates. With FillEdge, the full setup takes about fifteen minutes: sign up, install the Expert Advisor on your terminal, paste your webhook URL and alert message into TradingView, send a test signal, and you’re live.

More from FillEdge

Lock the best price before FillEdge opens to general public.

The first 50 traders lock today's price permanently — it never goes up, no matter the features we add. Get early access and we'll email you the moment the bridge is live.

Join and you'll only get FillEdge launch updates. Unsubscribe anytime.