November 14, 2026 · 12 min read · Pineflows team
How to Create a Trading Bot: Test Before You Go Live
Learn how to create a trading bot from Pine Script strategy to live Robinhood orders, with backtest checks, test mode and safety controls.

You've written the strategy, the equity curve in the Strategy Tester slopes up and to the right, and the webhook URL is sitting in your clipboard. So you arm the alert with a single share and spend the afternoon refreshing the broker app. Nothing fills. Or something fills twice. Or the exit triggers while the entry never did. If any of that is familiar, the fault is probably not in your signal logic. Most guides on how to create a trading bot stop at the entry rule and the webhook, which is about a third of the work and the least dangerous third. What follows is the build order I'd use, and the controls I wouldn't switch live without.
Table of Contents
- The Four Stages From Idea to Live Bot
- How to Build and Validate the Strategy
- Safety Controls Every Bot Needs Before Launch
- How to Route TradingView Alerts to Robinhood
- Alert Failures and How to Fix Them
- Confirm the Test Results Before Going Live
The Four Stages From Idea to Live Bot
The failure that catches people first isn't a bad entry. It's silence. A backtest runs inside a simulator that assumes a fill whenever a condition is met; a live bot runs against a broker that can reject an order, a token that expires after a password change, and a webhook that can deliver the same message twice. The SEC staff report on algorithmic trading lists automation among the sources of operational failure, incorrectly deployed algorithms, abrupt liquidity changes and clearing problems, and it makes the point that greater speed and automation amplify a malfunction rather than confining the damage to a single trade.
That reframes the whole project. The strategy logic is one component of a system, and the rest of the system decides whether a bug costs you one trade or forty.

| Stage | What You Do | Pass Condition | Common Failure |
|---|---|---|---|
| 1. Define rules | Write entry, exit, sizing and max-loss rules as fixed code | Every rule can be read with no discretion | Hidden judgment such as entering when the chart feels right |
| 2. Validate | Backtest with commissions and slippage, then test on untouched data | Net results hold on the out-of-sample period | Tuning until one backtest looks good |
| 3. Paper test | Run alerts in test mode and log them without sending orders | Every alert is logged once with correct symbol, side and quantity | Alerts never arrive, or arrive twice |
| 4. Limited live | Go live at small size and check each fill against the log | Fills match the log and exits execute correctly | Scaling up before the first real fill is verified |
The order carries information. A backtest tells you a rule set is worth testing; it can't tell you whether an alert fires on a live realtime bar. Paper trading tells you the alert arrives and the payload parses; it can't tell you whether your broker accepts the size you asked for. Only small live orders tell you whether the fill you modelled is the fill you get.
Before stage one, get the plumbing straight. You need a TradingView plan that can send webhooks with two-factor authentication switched on, an active Robinhood connection, and enough buying power to cover the orders the strategy will send. You're also responsible for the terms of every service you connect, including Robinhood's rules for Agentic Trading, and for whatever local law applies to your trading.
Then mark the stage your strategy has passed, not the one it's at. If you have never seen a logged alert with a real fill attached to it, you're at stage three regardless of what the backtest says.
How to Build and Validate the Strategy
A backtest isn't a forecast. It's a description of how a rule set behaved on data you already know the answer to. The engineering job is to make that description honest enough to be worth acting on, which comes down to six steps in this order.
- Write the rules as fixed code. Entry, exit, position sizing and a maximum loss per trade or per day, each with a concrete value and no manual override. If a rule needs you to glance at the chart and decide, the bot can't trade it, because the bot has no chart.
- Model the costs that will hit you. Commissions, the bid-ask spread, slippage, partial fills and the fills you never get. Record gross and net results side by side, plus drawdown, trade frequency and exposure. If you want the mechanics in detail, this walkthrough on backtesting a trading strategy step by step covers the settings that matter most.
- Split the history by time, not by feel. Tune on older data and leave the most recent stretch untouched until the final evaluation. Reusing the same test period for every iteration turns your out-of-sample data into in-sample data without you noticing.
- Keep an experiment ledger. Every variant you try goes in it: indicator, threshold, timeframe, stop level, universe. The count matters as much as the results. Bailey's work on backtest overfitting gives a benchmark that should make anyone cautious: with five years of daily stock-market data, trying more than roughly 45 strategy variations can produce a Sharpe ratio of 1.0 or higher by chance alone even when the true Sharpe is zero or negative.
- Test sensitivity, not just the optimum. Nudge each parameter and rerun. A result that collapses when a stop moves from 2.0% to 2.5% isn't a finding, it's a coincidence with a nice chart. Bailey, Borwein, López de Prado and Zhu recommend combinatorially symmetric cross-validation to estimate the probability of backtest overfitting, precisely because ordinary holdouts mislead on investment backtests.
- Freeze a named version. The backtest, the alert and the logs should all point to the same rule set. Without a version label, you can't tell whether a live result came from the strategy you validated or something you edited on Tuesday.
Then set your expectations against the population you're trading in. Research summarised on day-trader profitability reports that more than 80% of Taiwanese day traders lost money after costs in a typical six-month period, and that a study of 1,551 individuals who day-traded mini-Ibovespa futures on at least 300 days between 2013 and 2017 found 97% lost money after fees.
Practical rule: automation makes execution consistent. It doesn't add predictive skill to a rule set that has none.
What a passing result looks like
Positive net results on the untouched period, and stable behaviour when neighbouring parameter values are used instead. Both conditions, not either. A strategy that only works at one setting has told you it doesn't work. If it passes, size positions and cap losses in the code rather than scaling up because the historical return was high.
Safety Controls Every Bot Needs Before Launch
The gap that trips people up is the one between simulated fills and real order state. TradingView's own documentation on alert behaviour notes that strategy alerts can be driven by script alert calls or by order-fill events, and that alert behaviour is restricted to realtime bars. The broker emulator will happily report a fill at a price that no live counterparty would have given you. Your controls have to assume that divergence rather than hope against it.

Split the controls by what they protect.
- Entry controls: every alert carries an event ID, and the same alert never trades twice. Submission is idempotent, so a duplicate or reordered delivery produces one order at most. Payloads missing a symbol, side or quantity get rejected rather than guessed at.
- Exposure controls: a maximum size per trade, a maximum loss per day, and a cap on open positions. When the daily loss limit trips, the bot stops opening anything new until you reset it.
- Exit controls: a global pause blocks new entries, cancels the entry orders the bot itself created, and leaves valid exits alive. This is the part most tutorials skip, and it's the part that matters when a position is open and something has gone wrong.
- Failure handling: timeouts on every broker call, a defined behaviour when prices, balances or acknowledgements are missing, a rapid shutdown switch, and a status on every event that moves from received to validated to submitted to accepted, rejected or filled. A control designed in advance is cheap. One improvised in the middle of a bad week is not.
A "fully automated" bot shouldn't maximise autonomy. It should preserve the ability to interrupt it and the ability to reconstruct what it did.
For a closer look at how order state and fills diverge from the emulator, this guide to automated trade execution goes deeper into the reconciliation side.
Before you go live, run one test. Open a position in test conditions, hit pause, and confirm the exit still reaches the broker. If it doesn't, the pause switch is a trap door rather than a safety net.
How to Route TradingView Alerts to Robinhood
Routing is the narrowest part of the build, and the easiest to get wrong in small ways. Robinhood reported 24.2 million funded customers in July 2024, up by more than 1 million on the same period a year earlier, per Finance Magnates, so the broker side is well trodden. The alert side is where people stumble.

- Confirm your plan and security settings. Webhooks need a paid TradingView plan, and two-factor authentication should be on before you connect anything. Check: the webhook URL field is available in the alert dialog.
- Connect your Robinhood account in Pineflows and confirm it shows as active. Live automations stay paused while the connection is broken, which is correct behaviour and also the reason people think their bot is dead. Check: the connection status reads active before you build the alert.
- Use TradingView's default alert message for strategy scripts. Scripts built on
alert()need a small rules adapter from Claude that maps their output onto the same fields, because the automation expects a defined payload, not free text. Check: you know which of the two your script is. - Create one alert and point it at the webhook URL Claude gives you. A single alert carries the whole automation. At this point the log should be empty, and if it isn't, you're looking at a previous alert.
- Stay in test mode and send a test alert. Placeholders stay blank in a test message, so it doesn't count as a real fill, but the log should show exactly one payload with an event ID attached.
- Read the logged entry field by field. Event ID, symbol, side, quantity, status. If any of them is blank or wrong, stop and fix the configuration rather than the strategy.
- Compare the configuration against your script. Check instrument, sizing, entries and exits against what the Pine Script intends. Generated configuration is convenient and occasionally wrong, which is why it gets verified before the switch, not after.
The verification point isn't the test alert. It's the first genuine signal that arrives while you're still in test mode: same symbol, same side, same quantity the strategy asked for, logged once, with a status you can read. Live mode waits for that verification, an active Robinhood connection and an active trial or plan.
If you'd rather see the sequence before building it, this covers the routing and the log checks end to end.
Alert Failures and How to Fix Them
Failures show up after launch, not before, and they cluster around one question: did the event that should have happened occur? The table below maps the symptoms to the cause and the fix.
| Symptom | Likely Cause | Fix |
|---|---|---|
| Alert fires but no order appears | Bot paused, duplicate event, test mode on, plan needed or Robinhood not connected | Read the signal log reason and fix that one condition |
| Same trade placed twice | Duplicate alert delivery without event-ID protection | Confirm each alert carries one event ID and that a repeated ID is ignored |
| Alert arrives late or out of order | Delivery delay or retry after a timeout | Check timestamps and reject signals older than your allowed window |
| Signals missing during fast bars | TradingView halted alerts after its rate limit | Reduce alert frequency and check alert status after volatile periods |
| Orders stop after a password change | Robinhood token expired or app access was revoked | Reconnect Robinhood; live automations stay paused until you do |
| Position differs from strategy | Rejected or partial fill not reconciled with the broker | Compare the log against broker order status and close the gap manually |
The distinction underneath all of this is that alert reliability is not strategy correctness. A strategy can be logically perfect and still go quiet during a volatile session, because TradingView runs alerts on its servers, triggers them only on realtime bars, and documents that more than 15 alerts in three minutes can cause further alerts to be halted, as explained in its Pine Script alerts reference. A backtest has no rate limit. That's the whole difference between the two environments, and it's why a silent bot during a fast market is a predictable outage rather than bad luck.
Treat every gap between a strategy event and a broker order as a bug until you have explained it. "The market moved" isn't an explanation. "The alert never fired because we hit the rate limit" is.
Build one daily habit: reconcile strategy events against broker orders at the same time each day, and read the log before you read the chart. When something looks wrong, the log answers the first question faster than the chart does. Also accept the operational reality that alerts can arrive late, arrive twice, or never arrive at all, markets move, and brokers reject orders. That's not a reason to avoid automation. It's the reason monitoring is part of the build rather than an optional extra.
Confirm the Test Results Before Going Live
One rule decides this: go live only when every item on the list below is ticked, and stay in test mode while any one of them isn't.
- Enough logged alerts. Several test alerts, or better, a genuine signal cycle, logged with no duplicates and no missing fields.
- Net results after costs positive on the untouched period from the validation step, not the tuned one.
- Limits fired on purpose. You triggered the size cap and the daily loss cap in test mode and watched the bot refuse to trade.
- A frozen strategy version with a name, so what runs live matches what you validated.
Cover more than one market condition before deciding. A quiet week proves the plumbing and very little about the rules.
The first live step is small size, one fill at a time, each one compared against the log. Review the alert log in test mode before you switch, because the configuration can contain mistakes even when the strategy doesn't. You can stop at any point by pausing or deleting the automation, disconnecting Robinhood, or cancelling the subscription.
Read the disclaimer plainly: a backtest is not a forecast, trading involves risk of loss, and a bot executes a strategy without making it profitable. Live mode shouldn't run until a real alert has been verified, Robinhood is connected and the plan is active. If you want to rehearse the middle stage properly, this guide to paper trading in TradingView shows how to run it without touching real capital.
Keep test mode on until the first real alert proves itself.
Pineflows turns TradingView strategy alerts into Robinhood orders with a test-first pipeline, so every alert is logged with an event ID and a readable payload before it ever reaches your broker. You can verify each signal, keep a global pause that blocks new entries while exits stay alive, and switch to live only after the log matches what your script intended. Visit Pineflows to connect a strategy and check the first real alert in test mode.