How to Test a Trading Bot on a Demo Account Before Risking Money

7 min read

A bot that works in a backtest is not a bot that works with real money. Between the two sit imperfect data, different execution, coding errors and the emotions that show up once the money is yours. This guide describes a phased process for testing an automated strategy carefully, and it starts with an honest warning: most retail bots are not profitable, and this information is educational, not a promise of results or a recommendation.

A warning first: most bots do not work

Automation does not create an edge that was not there. A bot runs a rule quickly and without emotion, but if the rule has no statistical edge after costs, it will lose money with the same discipline a person would. Bots sold with promises of guaranteed returns deserve suspicion, and backtest results shown in ads rarely include realistic costs.

The goal of the phases below is not to “prove” your bot wins, but to give it many chances to fail with fake or minimal money, so you find the defects before they get expensive. If the bot survives an honest process, you will have reasonable confidence; if it does not, you will have saved money.

Phase 1: backtest with realistic data and costs

A backtest simulates the strategy on historical data. To be useful, include spread, commission, swap and a prudent slippage assumption; use quality data with the same time conventions as your broker; set aside a stretch of data you did not use for optimization (out-of-sample); and avoid tuning so many parameters that the result is just luck. We have a dedicated guide on overfitting, the most common mistake in this phase.

A backtest result is a hypothesis, not proof. Write down its key metrics (expectancy per trade, win rate, maximum drawdown, number of trades), because they become the benchmark for the next phases.

Phase 2: forward test on demo

A forward test means letting the bot trade in real time on a demo account, with the same rules, the same size and the same conditions you would use live. Do not change parameters during the test: every change restarts the clock, because earlier data no longer belongs to the same strategy.

You need enough trades for the average to mean something. With 30 trades, the standard error of the win rate is about 9 percentage points (√(0.5 × 0.5 ÷ 30) ≈ 9.1%); with 100 it falls to 5%, and with 200 to about 3.5%. A reasonable criterion is to require at least 100 trades and several weeks covering different market regimes (trend, range and news).

Phase 3: live at minimum size

If the forward test meets your criteria, move to a real account at the smallest possible size (for example, 0.01 lots or one micro contract) with capital you are prepared to lose entirely. The aim of this phase is not to make money but to measure the gap between demo and live: execution, costs and the bot’s behavior.

Only after a period without surprises (another stretch of trades and weeks) do you scale the size gradually, for example doubling at most once the criteria are met again. Scaling suddenly after a good streak is the automated version of overconfidence.

Differences between demo and live

A demo often fills with unlimited liquidity, no slippage and low latency; live, orders can be filled at a different price (slippage), rejected or repeated at a new price (requote), arrive late because of latency and meet wider spreads during volatile moments. Large orders can also be partially filled.

The demo also does not reproduce psychological pressure, even though the bot feels none: you are the one who decides to switch it off after three losses in a row. That is why you should fix the shutdown rules before you begin. Assume live results will be somewhat worse than demo results, and design your criteria with that margin.

What to record during the test

Record each trade with its time, instrument, expected price and actual fill price, the spread at that moment, the commission, the result in R and the reason for entry and exit. Also record system events: reconnections, rejected orders, API errors, response times and any manual intervention.

Compare weekly with the backtest: number of trades, expectancy, win rate and drawdown. A small gap is normal; a large and persistent one points to a data, cost or logic failure. Our trading journal lets you store and review this data in your own browser.

Pass criteria set in advance

Before you start, write down what “passed” means. For example: at least 100 demo trades; positive net expectancy after costs; expectancy no lower than half of the backtest’s; maximum drawdown no greater than 1.5 times the backtest’s; no serious technical errors; and execution deviation (slippage and spread) within what you assumed. The exact thresholds are yours, but they must be set before you see the results.

Setting them late is the easiest way to fool yourself: if you decide the criterion after seeing the curve, you will always find a reason to pass. If the bot does not meet the criteria, the right decision is to fix it and restart the test, or to discard it.

Kill switches and loss limits

A kill switch is a rule that shuts the bot down without human intervention when something goes wrong. It should include: a maximum daily loss (for example, 2% of equity), a maximum total loss since the start of the phase (for example, a drawdown above 1.5 times the backtest’s: if that was 10%, stop at 15%), a maximum number of trades per day, a maximum number of consecutive losses, and a maximum position size independent of the strategy logic.

Add safety limits in the code itself and also on the broker side if the option exists. A programming error, such as a loop that opens repeated orders or an order with a miscalculated size, can empty an account in minutes; external limits are the last barrier when the code fails.

Common bot failures and monitoring

The most typical failures are not strategic but technical: data with gaps or bad prices; mishandled time zones (a server on GMT+2 or GMT+3 with daylight saving changes the daily candle close and the session hours); a mismatch between the bot’s clock and the broker’s; weekends and holidays with price gaps; reconnections that duplicate orders or lose the state of open positions; and restarts that forget existing positions.

Monitor the bot as if it were a service: raise an alert if it stops receiving data, if there is no activity within an expected time, or if the real position does not match what the bot believes it holds. Review the logs daily at first. A bot that runs “by itself” is not a bot you can ignore.

Basic API key security

If the bot connects through an API, treat the keys like passwords. Create the key with read and trade permissions only, without withdrawal permission. If the provider lets you restrict the key to specific IP addresses (IP whitelisting), turn it on. Do not store the key in your code or push it to public repositories: use environment variables or a secrets manager, and rotate keys if you suspect exposure.

Enable two-factor authentication on the account, do not share keys with third parties and be wary of bots or services that ask for withdrawal permissions. Handing a broadly permissioned key to unknown software is one of the most serious and least visible risks of this practice.

Summary: a checklist

First, a backtest with costs and out-of-sample data. Second, a demo forward test with fixed rules, at least 100 trades and varied conditions. Third, pass criteria written before you start. Fourth, live at minimum size with kill switches active. Fifth, scale only gradually and only when the numbers match expectations.

Keep API keys at minimum permissions, monitor the bot and review the logs regularly. Even so, a bot can lose money after passing every test, because markets change; trade only with capital you can afford to lose.

Educational content, not financial advice. Risk disclosure

Related tool

Trading journalLog entry, SL, TP and exit to get your R, equity curve, return and statistics by pair, weekday and session.

More guides