Learn the process. Protect your capital.

Commissioning a machine you are still responsible for

How to Build a Trading Bot You Are Allowed to Switch On

It takes about 617 closed trades to tell a 55 per cent edge from a coin flip, and a system that healthy will still hand you a six trade losing run nine times out of ten. Build for both before you switch anything on.

REX Trading Signal logo
Rex · @REXTradingSignal · 11.9K followers

The request usually arrives after a bad week at work rather than a bad week in the market. Somebody has realised their job and the London session are not compatible, and the obvious fix is to hire a machine. So they ask how to build a trading bot, and almost every answer they find online is about code. The code is the easy part. What follows is the business version: what the bot has to prove before it is allowed near live money, and what has to be in place before you switch it on.

The motive is genuine and I want to be fair to it. One reader wrote: "yes i was busy with this job of mine and cant watch all signals." Another, more precisely: "I'm still yet to feel confident about scalping while at work. I end up missing signals or getting too distracted to properly manage positions. I'm still trying to find the best balance, maybe automate the management of positions once I enter trades." A third: "my day is very busy, sometimes I miss signals because I'm in a meeting or in a call." Roughly 286 messages in my inbox mention trading around a full time job, which is a keyword count rather than a survey. That is a real operational constraint, and automation is a reasonable response to it.

It is just not a cheap one, and the failure mode is specific. A bot does not lose money slowly while you think about it. It executes your worst assumption at full speed while you are in a meeting.

How to build a trading bot, as a project rather than a script

Treat it the way you would treat buying a machine for a workshop. You would not install it, switch it on and leave the building. You would specify it, test it, commission it under supervision, and keep the stop button where you can reach it. Same order here.

Stage one, the specification. Before any code exists, write down in plain language what the bot does and does not do. What it trades, what conditions open a position, what closes it, what size it takes, what it does when a position is already open, what it does at the weekend, and above all what it never does. If you cannot write that document, you do not have a strategy to automate. You have a habit, and habits do not translate into instructions.

This is the same document I describe in how to build a trading system, and the test is identical: a stranger should be able to follow it and produce your decisions. The difference is that with a bot, the stranger is a computer and it will follow the document exactly, including the parts you were planning to interpret generously.

Stage two, the data. Your bot will be tested on history, so the history has to be worth testing on. Know where it came from, what timezone its timestamps are in, whether spreads are included, and what happens at the weekly gap. Most beginner bots are not beaten by the market. They are beaten by a dataset that was cleaner than reality.

Stage three, the backtest, under suspicion. A backtest is a hypothesis, not a result. I have written separately about look ahead bias and overfitting, which are the two ways a backtest flatters you most convincingly. Read both before you trust a curve.

Stage four, forward testing on a live feed. Run the bot on current data, in real time, without money, for long enough that it meets conditions the backtest never contained. Weekends, rollovers, news prints, outages, a platform update. The purpose is not performance. It is to find out what the thing does when something unexpected happens, because something unexpected will happen on a Tuesday.

Stage five, commissioning. Live money, smallest size your broker allows, and a daily check. You are not evaluating profit at this stage. You are confirming that live behaviour matches test behaviour. Any difference between them is the whole ballgame, and the cause is usually execution rather than logic.

The number that decides how long stage four lasts

Here is the question nobody asks before they start, and it determines everything about the timeline.

Suppose your bot's true win rate is 55 per cent and you want to be reasonably confident it is better than a coin flip. How many closed trades do you need before the data can tell the difference?

Using a standard one sample test of proportions, a one sided significance level of 5 per cent and 80 per cent power, the answer is 617 closed trades. If the true edge is thinner, say 52 per cent, you need 3,863 trades. If it is a fat 60 per cent, 153 will do. That is my own arithmetic on those stated assumptions, and you can reproduce it with any sample size calculator.

Sit with the middle figure for a moment. If your bot takes two trades a day, 617 trades is well over a year of continuous operation. Which means the honest answer to "is my bot working" after six weeks and forty trades is that you do not know and cannot know yet. Most bots are abandoned or re optimised long before they have produced enough evidence to be judged, which is why most bot projects never resolve anything.

The losing runs your bot will hand you anyway

The second number is the one that gets people to switch a working system off.

Take that same 55 per cent win rate, so a 45 per cent chance of losing each trade, and assume trades are independent. Across 500 trades, the probability of hitting at least one run of six consecutive losses is 90.3 per cent. At least one run of eight is 36.9 per cent. A run of ten is 8.8 per cent, and a run of twelve is 1.8 per cent.

How to build a trading bot, bar chart of the chance of at least one losing run inside 500 trades for a system with a true 55 per cent win rate, a run of 6 losses 90.3 per cent, a run of 8 losses 36.9 per cent, a run of 10 losses 8.8 per cent and a run of 12 losses 1.8 per cent
How to build a trading bot without switching it off at the wrong moment: the losing runs a healthy system produces across 500 trades.

Read that top bar again. A run of six losses is not evidence that your bot is broken. It is close to certain over a few hundred trades, on a system that is working exactly as designed. Independence is an assumption and real strategies cluster their losses, which makes long runs more likely rather than less.

The practical consequence is a rule about your own behaviour, written now. Decide before you switch on what losing run would make you intervene, pick a number the arithmetic says is genuinely unusual rather than merely unpleasant, and write it in the specification. A kill switch set at six consecutive losses will fire on a healthy system nine times out of ten and teach you nothing. One set at twelve means something.

The controls a regulated firm is required to have

Here is the part I find most useful, and almost nobody building a retail bot knows it exists.

Firms doing algorithmic trading in the European Union operate under a detailed rulebook, Commission Delegated Regulation (EU) 2017/589. It is public, free and specific, and the controls it mandates are a ready made checklist for a one person operation.

On the stop button, the regulation requires that a firm "should be able to withdraw all or some of its orders where this becomes necessary", which it names kill functionality. It adds that for such a withdrawal to be effective, the firm "should always be in a position to know which trading algorithms, traders or clients are responsible for an order". Translated to your desk: you need a way to flatten everything and cancel everything in one action, and you need to know which strategy opened which position without having to reason it out.

On pre-trade controls, Article 15 requires price collars that "automatically block or cancel orders that do not meet set price parameters", maximum order values that "prevent orders with an uncommonly large order value from entering the order book", and maximum order volumes. These are the limits that stop a bug becoming an event. A fat finger in code is not a single wrong trade, it is a loop.

On testing, the regulation requires firms to establish that an algorithm "does not behave in an unintended manner", that it "continues to work effectively in stressed market conditions" and that under those conditions it "allows for the switching off of the algorithmic trading system or trading algorithm". Note that stressed conditions are a required test case, not an optional one.

On continuity, firms must "review and test" their business continuity arrangements annually. And on governance, the regulation expects a regular self assessment covering the criteria in its Annex I, so the firm retains "a full understanding of the trading systems and trading algorithms it uses".

None of this applies to you legally. All of it applies to you practically, because the failure modes a regulator wrote rules about are the same failure modes that will visit your account. If a professional firm is required to have a kill switch, a maximum order size, a stressed market test and an annual review, a one person business running the same kind of software without any of them is not being lean. It is uninsured.

The minimum viable control set

Condensed into what you can actually build this month:

A kill switch you have tested. One action that cancels pending orders and closes open positions. Test it on the demo account with positions open, not in theory. An untested kill switch is a comfort blanket.

Hard caps the bot cannot exceed. Maximum position size, maximum open positions, maximum orders per minute, and a daily loss limit that stops it trading for the day. Put these in the code, not in your intentions. The orders per minute cap is the one that saves you from a loop.

A price sanity check. Refuse to act on a quote that is implausible or stale. Bad ticks exist and a bot does not find them surprising.

A heartbeat and an alert. If the bot stops, you must find out from the bot rather than from your balance. Silence is the most expensive state a running system can be in.

A log you can audit. Every decision, with timestamp, inputs and resulting order. Without it, diagnosing a bad day is guesswork, and you will have bad days.

A written review date. Put it in the calendar now, as part of your weekly review, so that the bot is inspected on a schedule rather than when it frightens you.

What this article does not say

It does not say a bot will make you money. The arithmetic above is about detecting an edge you already have, not conjuring one. If the manual version of your strategy does not work, the automated version will not work faster.

It does not say automation suits every method. Discretionary approaches that depend on context are genuinely hard to specify, and forcing them into rules often produces a worse strategy than the one you had.

It does not cost the project. That belongs in a separate conversation and I have had it in can I automate my trading strategy, which looks at the running costs and the decision of whether to build at all. Read that one first if you have not committed yet.

And it does not recommend buying somebody else's bot. A system you cannot read is a system you cannot specify, test, or honestly review, which removes every control described above.

Free one page trading business plan

Get the free REX one page trading business plan, the document where limits like these get written down before the market asks you about them. One email, no spam, unsubscribe anytime.

Get the free business plan →

Frequently asked questions

How do I build a trading bot if I cannot code?

Write the specification anyway, in plain language, because that document is the hard part and it is language independent. Whether you then learn to code it or pay somebody, you will need a strategy precise enough that a computer can follow it without interpreting anything.

How long should I forward test before going live?

Long enough to cover weekends, rollovers, news prints and at least one platform problem, and long enough that the trade count is heading towards a number that could settle the question. For a 55 per cent edge, that number is around 617 closed trades, so expect commissioning to start well before you have statistical proof.

My bot just lost six trades in a row. Is it broken?

Probably not. For a system with a true 55 per cent win rate, the chance of at least one six trade losing run somewhere inside 500 trades is about 90 per cent. Decide in advance what run length would be genuinely unusual, and judge it against that rather than against your mood.

What is the single most important control?

A kill switch you have actually tested with live positions open. Every other control limits damage. That one ends it.

Do EU algorithmic trading rules apply to me?

Almost certainly not as law. They are included here because they are a free, specific and well thought out checklist of the controls a professional operation is required to have, and the risks behind them do not care whether you are regulated.

Is a bot a good idea if I have a full time job?

It can be, because the constraint it addresses is real. Just be clear that a bot replaces the execution burden and adds a monitoring and maintenance burden. It is a different job, not the absence of one.

Where REX Trading Signal fits

REX Trading Signal is a free channel about running a trading account the way you would run a small business, with a risk ceiling, a cost line and a review you actually do. There is nothing sold here on a promise of returns. The free business plan template is one page, and its job is to make you write the limits down before the market asks you about them. The piece everything else hangs off is the one page trading business plan template.

About the author. Rex writes REX Trading Signal. He once watched a script with no orders per minute cap submit the same order forty times in nine seconds because of a mis-signed comparison, and he has never since built anything that could not be stopped with one keystroke. He writes about operations because the parts of this business that end accounts are rarely the parts that look interesting.

Sources and method. The requirements for kill functionality, for knowing which algorithms, traders or clients are responsible for an order, for price collars and maximum order values and volumes under Article 15, for testing that an algorithm does not behave in an unintended manner and continues to work in stressed market conditions while allowing it to be switched off, for annual review and testing of business continuity arrangements, and for a regular self assessment against the criteria in Annex I, are all quoted from Commission Delegated Regulation (EU) 2017/589, linked above and checked live before publication. The sample sizes of 617 closed trades for a 55 per cent win rate, 3,863 for 52 per cent and 153 for 60 per cent are my own arithmetic using a one sample test of proportions at a one sided 5 per cent significance level with 80 per cent power. The losing run probabilities of 90.3, 36.9, 8.8 and 1.8 per cent for runs of six, eight, ten and twelve losses across 500 trades are my own arithmetic assuming independent trades with a 45 per cent chance of losing each one, an assumption that makes long runs less likely than they are in practice. Reader quotations are real messages, anonymised and lightly edited, with occupations removed, and the count of roughly 286 is a keyword count of my inbox rather than a survey.

This article is educational and is not financial advice. Trading gold and other leveraged products carries a high risk of losing money rapidly, and no entry, stop or target discussed should be treated as a signal. Nothing here claims that automation improves returns, and no strategy, win rate or trade frequency used in the arithmetic is a representation of any real system's results. Decide your own risk, and never trade money you cannot afford to lose.

Build the stop button before you build the strategy.

Follow along on Telegram for the daily record, with the reasoning written down before the trade rather than explained after it.

Follow REX Trading Signal → Free to follow. No pressure, no countdown, stay as long as it earns your trust.

More from the journal

Browse the full article library →

Risk disclosure. Trading gold (XAUUSD) and other leveraged products involves substantial risk of loss and is not suitable for every investor. Past performance, including any results shared on this site or on Telegram, does not guarantee future results. Nothing here is financial advice; it is personal experience shared for education. Never trade money you cannot afford to lose.

© 2026 REX Trading Signal · Telegram: @REXTradingSignal · Personal views, for reference only.