Backtest Passed, Live Failed: Seven Checks That Catch What the Strategy Tester Misses
Introduction
Every trader who builds robots knows the same story. The backtest is beautiful. The equity curve climbs, the win rate looks healthy, and the report shows a profit you would be happy to take home. Then you attach the robot to a live or demo account, and the story changes. Trades appear in places the backtest never showed. The panel says one thing and the account says another. The same setup that made money on history loses money on the next ten trades.
I have lived this from the other side, as the person who writes the indicator. I build Expert Advisors and indicators for MetaTrader 5, and I test them in the Strategy Tester before they go anywhere near the Market. Over the last months I found defects in my own work that no backtest report showed me. A panel that displayed the values of the oldest bar while the indicator buffers were correct. A multi-timeframe signal that rewrote bars which had already closed. An input that divided by zero when a user typed 0. None of these appeared in the profit column. All of them would have misled a buyer.
This article is the checklist I now run on every indicator and robot before I trust it. Seven checks, each with a concrete method. You need the Strategy Tester, a demo account, and a text comparison tool. Nothing else.
Check 1. Closed bars must never change
This is the first and most important check. Once a bar has closed, the value your indicator calculated for that bar must never change. If it changes, the indicator repaints, and every backtest result it produced is unreliable, because the backtest judged trades on values that were not visible when the bar closed.
Before you test, define what counts as repainting, because three different things can change a past value and only one of them is a defect in the indicator logic. First, repainting by logic: the indicator reads the unfinished forming bar, bar 0, or it recalculates its buffers on every tick in a way that rewrites closed bars. That is a defect. Second, historical recalculation: the broker downloads older history, or corrects past prices, so the dataset itself changes. The indicator then calculates different values because its input changed, not because its logic is wrong. Third, a settings change: you change an input, and the indicator recalculates. That is expected. A snapshot comparison is only a repaint test when the dataset and the settings stay the same between the two exports. If either changed, you are measuring something else.
The procedure is exact. Attach the indicator to a chart and export its buffer values to a CSV file with a small script. The script reads the buffers with iCustom and writes one line per bar: the bar time, then the seven buffer values at fixed decimal precision. The forming bar, index 0, is excluded from the comparison, because its value is unfinished by definition. For every bar and every buffer, the EMPTY_VALUE status is compared as well, not merely counted, because a value that was empty in one export and filled in the other is a change. The chosen precision must be sufficient to detect a meaningful change in every exported buffer, and I state it in the test record. Then restart the terminal, attach the indicator again with the same inputs, and export a second CSV. Compare the two files byte for byte, header included. If they are identical, the closed bars are stable, because the exported values are the same numbers the indicator calculated, written at fixed precision. Identical files establish equality of the exported values at that precision, and since the signals are read from those same values, identical files mean identical signals for every compared bar, not just identical formatting. If the files differ, find the first line that changed and the buffer that moved. That tells you where the repaint lives.
I run this on every indicator I build, and I record the conditions so the test can be repeated. On two of my trend indicators, both on EURUSD H1 over the same 6,689 bars of cached history from 2 January 2023 to 21 August 2024, with no new history arriving between the snapshots, the results were these. The HalfTrend version, ATR period 6 and multiplier 1.0, produced 6,653 valid lines, with 272 buy arrows and 271 sell arrows. The SuperTrend version, ATR period 7 and multiplier 1.6, produced 6,680 valid lines, with 161 buy arrows and 160 sell arrows. Each export covered the same seven buffers: the trend line, the buy arrow buffer, the sell arrow buffer, the trend direction, the upper band, the lower band, and the colour index. After a terminal restart, a profile switch and a re-attach, the second exports were byte-identical to the first. That is the acceptance criterion: same symbol, same timeframe, same inputs, same history, forming bar excluded, full-file byte comparison, zero differences. Anything less is not a pass.
Two causes account for most failures, and each has its own fix. The indicator reads the forming bar and treats its unfinished value as a signal. The fix is to calculate signals only from closed bars, using the previous bar as the latest confirmed bar. Or the indicator recalculates its whole history whenever new history arrives, so early bars shift. The fix is to initialise averages once from the available history and update them incrementally, or to state the history boundary honestly, which is Check 2. A profit figure alone will never show either cause, because profitability statistics say nothing about whether a buffer value was available at the time the trade was supposed to happen.
Check 2. Know your history boundary
A backtest result is only valid for the exact dataset it ran on. When your history grows, the first bars of an indicator can change, because many indicators initialise their averages from the first available bar. That does not mean the indicator is broken. It means the guarantee has a boundary, and you should state it honestly.
When I publish an indicator, I say plainly that the no-repaint guarantee applies to an unchanged historical dataset. If the broker adds older history or you change the chart, re-run the check from Check 1. A seller who claims their indicator never changes under any conditions has either never tested it or is not telling you the whole story.
Check 3. Multi-timeframe signals must not rewrite closed bars
This is the defect that surprised me most, because it hides inside a feature traders love. A higher-timeframe signal, say from H4, is drawn on an H1 chart. The H4 candle closes, the signal is confirmed, and the arrow appears. The question is where it appears.
The correct behaviour follows from one rule: a confirmed signal can only exist after the higher-timeframe candle has completed. In code, that means you take the higher-timeframe candle opening time with iTime(), you read the higher-timeframe indicator value with CopyBuffer(), and you map that timestamp onto the chart timeframe with iBarShift(). The confirmation boundary is the higher-timeframe closing time, and iBarShift() must map that calculated boundary itself, not simply the higher-timeframe candle's opening timestamp. The confirmed signal belongs on the first available chart bar at or after that closing time, subject to the instrument's trading sessions. On instruments with session gaps or non-standard timeframe boundaries, the first available bar after the boundary is the correct one, and the rule must be read with that qualification. The last lower-timeframe bar inside the completed higher-timeframe interval is still part of the old candle, and putting a confirmed arrow there rewrites history.
If the arrow is painted onto the first H1 bars of that H4 candle, bars that closed hours ago, then your backtest is judging trades on information that was not available when those bars closed. That is repainting, even if the indicator never touches a single-timeframe bar, and it introduces look-ahead bias: the test knows the H4 outcome before the H1 bars that supposedly acted on it. Bars inside the forming interval may show a live preview, clearly marked as unconfirmed, but never a committed signal.
Test it directly. Put the indicator on an H1 chart with an H4 input. Export the buffer values just before an H4 candle closes, then export them again just after it closes. Every H1 bar that was already closed before the H4 close must be identical in both files. Only the bars after the close may change. If an old bar changed, the timestamp mapping is wrong, and the fix is in the mapping, not in the signal logic.
Check 4. Type 0 and negative numbers into every input
Users will do this. The Strategy Tester does it during optimisation. If your indicator divides by a period input, and the user types 0, you get a division by zero. Do not assume the platform will catch this for you. It is the developer's job to validate inputs in OnInit() and return INIT_PARAMETERS_INCORRECT for any invalid combination, so the indicator refuses to start instead of calculating with a nonsense value.
The validation procedure is straightforward. For every numeric input, check the value before any calculation. An ATR period must be 1 or more. A multiplier must be greater than 0. Check every division denominator before you divide. Guard against integer overflow and against unreasonable array and buffer allocations from huge period values. Handle missing data from indicator calculations, because iMA or iATR can return an invalid handle or empty values when history is short.
There is one distinction that matters. Rejecting an invalid input and clamping it are not the same thing. Rejecting tells the user the value is wrong and stops. Clamping silently replaces what the user asked for with something else, and the user trades on settings they never chose. I reject invalid values. If a value is merely unusual but valid, I accept it and let the user own the result.
Run this check by attaching the indicator with each numeric input set to 0, then to a negative number, then to an absurdly large number, and confirm it refuses cleanly with a clear message in each case. Then run the same values through the Strategy Tester optimisation, because the optimiser will try them too.
Check 5. Do not trust the panel. Trust the buffers.
The panel on the chart and the indicator are not the same thing. The panel reads values and draws text. The buffers hold the actual calculated values that an Expert Advisor reads with iCustom. These two can disagree, and when they do, the panel is usually the one that is wrong.
I learned this on my own indicators. The buffers were correct, the arrows were correct, and the panel showed the values of the oldest bar on the chart. The defect was in the panel code, which read the wrong end of an array. A buyer watching the panel would have seen stale numbers and thought the indicator was broken. A buyer reading the buffers would have seen the truth.
When you test an indicator, verify the buffers with a script, the way Check 1 does. Then look at the panel and confirm it shows the same values for the latest closed bar. If the panel disagrees, the indicator has a display defect, even if its signals are right. Both matter, because buyers watch the screen.
Check 6. Test the money on a demo account
A backtest gives you profit in the Strategy Tester. A live chart gives you something else, which is the money figure on the panel, calculated from the real account. Before I trust a trade planning tool, I check its money figures on a demo account, in both directions.
The calculation has a strict order, and I check it in that order. First, the tool should call OrderCalcProfit() with the actual symbol, the order type, the volume, the entry price and the exit price, and it must check the Boolean return value. If OrderCalcProfit() returns true, the figure is calculated from the current account environment and the symbol's trading specifications, and the result comes back in the account currency. A true return means the calculation succeeded. It does not guarantee the execution price or the realised result. That is what the panel should show. Only if it returns false does the tool fall back to a tick-value estimate. That fallback must use the symbol properties SYMBOL_TRADE_TICK_SIZE, SYMBOL_TRADE_TICK_VALUE_PROFIT and SYMBOL_TRADE_TICK_VALUE_LOSS, and it must treat the profit and loss tick values as separate figures, because on many instruments they are not the same. The calculation must also respect the contract specification, the volume constraints, and the conversion into the account currency. A pip-value shortcut is not enough, and on gold it is wrong, because the tick size, the tick value and the contract size of XAUUSD behave differently from a currency pair.
Attach the tool to EURUSD on H1. Set an entry, a stop loss and a take profit, first for a buy setup, then for a sell setup. Read the risk money and the reward money, and confirm the account currency is shown correctly. Then set up an invalid trade, where the stop loss sits on the wrong side of the entry, and confirm the tool rejects the geometry and shows that the setup is not valid, instead of showing an estimate. If you can, repeat the same test on gold, XAUUSD, because that is where money calculations most often go wrong.
None of this needs real money. A demo account is enough, and it is the only honest way to check these figures. A backtest cannot do it, because the backtest never shows you the panel.
Check 7. Count breaches honestly, then test the loss limit out of sample
A loss limit is not validated by counting how many times it was hit. That is the point of a recent article on this site, and it is correct. Counting breaches tells you the limit was reached. It does not tell you whether the limit protects the account, or whether the strategy only looks safe because the test period was kind to it.
First, define the loss limit precisely, because the words hide three different things. A daily loss limit stops trading after a fixed loss in one day. A balance drawdown limit measures the fall from the highest balance. An equity drawdown limit measures the fall from the highest equity, which includes open positions and floating losses. These are not interchangeable, and a test must say which one it uses, whether floating losses and transaction costs are included, and over what period it is measured.
Then test the limit the way you would test any rule, on data the strategy was not tuned on. Split your history in time order: tune on the first part, test on the second part. Do not split randomly, because a random split mixes future bars into the tuning set and introduces look-ahead bias. The out-of-sample period must not influence parameter selection in any way. If the limit only works on the data you used to choose it, it is not a limit, it is a description of the past.
The same honesty applies to the strategy itself. I tested a ten-indicator combination on Step Index, Crash and Boom. The non-repaint audit passed, the signals were clean, and the combination found no profitable edge on any of those three symbols. I say that plainly, because a developer who only reports wins is not giving you information. A strategy that loses in testing is not a failure of testing. It is testing doing its job.
What the Strategy Tester cannot tell you
Even a clean backtest has limits you should know before you risk money.
Slippage is real. I measured it on the Deriv demo account, on Crash 500 and Boom 500, with market orders at small size, counting the adverse move between the requested price and the fill price in dollars per fill. The observed range was 0.50 to 0.88 dollars per fill. That is the measurement from that account and those instruments, not a universal figure. A backtest that assumes perfect fills will overstate the profit of any fast strategy, and the faster the strategy, the larger the gap.
Broker minimum distances are real, and they come from SYMBOL_TRADE_STOPS_LEVEL, which is the broker's configured minimum distance for stop orders in points. On the Deriv demo account I measured about 1,264 points on Crash and about 1,699 points on Boom. Those are the minima for that broker and that account, and they can differ by instrument and by account conditions, so do not treat them as universal requirements. A stop loss of 1,000 points on Crash or 1,500 points on Boom sits below the minimum, and the platform will not place the order at the requested distance. It rejects it or requires a wider stop, depending on the order type. Your backtest used the numbers you typed, not the numbers the broker enforced.
Spreads also change with conditions. They widen when news is released and when liquidity thins out at the edges of the session. The Strategy Tester works from historical spread data, and the spread is floating. In the "Every Tick Based on Real Ticks" mode, the spread changes as it did in real trading, and it can move inside a single minute. In generated-tick modes such as "Every Tick", the spread is modelled from the history, which is an approximation, so a strategy tested only on generated ticks has not been tested on real spread behaviour. A strategy that only works on a fixed spread is a strategy that has not been tested on real execution conditions.
None of this means backtesting is useless. It means a backtest is a filter, not a promise. It removes the ideas that cannot work. It does not prove the ideas that remain will work.
The checklist
Run these seven checks on any robot or indicator before you trust it with real money.
- Export the buffers, restart, export again. Closed bars must be byte-identical under identical inputs and history, forming bar excluded.
- State the history boundary. Re-run the check when the dataset changes.
- Test multi-timeframe mapping around a higher-timeframe close. No closed bar may change, and the confirmed signal belongs on the first bar after the close.
- Validate every input in OnInit and return INIT_PARAMETERS_INCORRECT for invalid values. Never divide by an unchecked denominator, and reject bad values instead of silently changing them.
- Verify the buffers with a script, then confirm the panel shows the same latest values.
- Check the money figures on a demo account, buy and sell, valid and invalid setups, and on gold if you trade it. OrderCalcProfit first, tick-value fallback second, with profit and loss tick values kept separate.
- Test the loss limit out of sample on a chronological split, with the limit precisely defined, and report losing results as honestly as winning ones.
If a product passes all seven, it is worth a demo run. If it fails one, you know exactly what to fix, and you have not paid for the lesson with real money.
Conclusion
A backtest that passes and a live account that fails are not a mystery. They are the gap between what the Strategy Tester measures and what trading actually is. The Tester measures history. Trading happens on live data, with slippage, broker limits, panels that can disagree with buffers, and signals that can be painted onto bars that already closed.
Close that gap with method, not with hope. That means reproducible tests, so another trader can repeat your snapshot comparison and get the same result. It means respecting execution constraints, so slippage, stop levels and spread behaviour are measured rather than assumed. And it means independent validation, so the demo account and the out-of-sample period confirm what the backtest claimed, instead of the backtest confirming itself. Export the buffers. Test the extremes. Check the money on a demo account. Say plainly when a strategy loses. The traders who do this stop buying pretty equity curves, and the developers who do it stop shipping defects they never saw.


