What is look-ahead bias in backtesting?
Look-ahead bias is when a backtest uses information that did not exist yet at the moment a simulated trade was decided, such as a bar's closing price before that bar has closed. The test then shows results no live strategy could reach. In our EUR/USD test, trading one bar too early turned a rule that made 555 pips before costs into one that made 10,782.
What is look-ahead bias?
Look-ahead bias is a backtest error in which a simulated decision uses data that was not available at the time of that decision. Nobody puts it there on purpose. The future value sits in the same table as everything else, one row down or one column across, and the code reads it.
It differs from overfitting, where a strategy is tuned until it fits past noise. An overfitted strategy uses only information it could have had but learns the wrong lessons from it. A strategy with look-ahead bias uses information it could not have had. Overfitting tends to show up gradually once a strategy trades live. Look-ahead bias tends to show up straight away, because the future data the test relied on is not there any more.
How much difference can one bar make?
We tested one simple rule on Fintrix Markets MT5 EUR/USD hourly data: 4,980 bars from 13 January to 29 October 2026.
- If the hourly close is above its 20-bar simple moving average, be long. If it is below, be short.
We ran the rule twice. The only difference was which bar each position was applied to.
The leaky version knows how bar N closed before it trades bar N. A bar that closed high is more likely to close above its average, so the rule goes long on a bar that has already risen. It describes the past well, but nobody could have traded it.
Is the fixed result an edge, then?
No, and the arithmetic shows why. Hourly EUR/USD moves in this sample had a standard deviation of 8.51 pips. Over 4,980 bars, a rule with no edge at all would land somewhere within about ±600 pips of zero roughly two times in three (8.51 × √4,980 ≈ 600). A total of +555 pips is inside that band, so chance alone could produce it.
Costs settle it. The rule switched direction 557 times. Each switch means closing one position and opening another, and every round turn pays the spread. At 0.5 pips per switch the total falls to about +277 pips. At 1 pip per switch it is about −2 pips. The fixed test is the honest one, and the honest answer is that this rule did not make money over these ten months once costs were included.
Where does look-ahead bias come from?
The most common sources in retail backtests and EAs:
How does the high and low of one bar mislead a test?
On 14 October 2026, the 12:00 UTC hourly bar for EUR/USD opened at 1.11926, rose to 1.11986 and fell to 1.11271. That was the hour of the US CPI release.
Take a short position at the open, 1.11926, with a stop-loss at 1.11980 (5.4 pips) and a take-profit at 1.11826 (10 pips). The hourly bar shows that price touched both levels. A test that only sees hourly bars has to guess which came first, and a test that guesses in the trade's favour books a 10-pip gain.
The 15-minute bars show what happened. Price rose to 1.11986 in the 12:15 bar and hit the stop. The drop came in the 12:30 bar, after the position had been closed. The real result was a 5.4-pip loss. The MQL5 reference makes the same point about the MT5 strategy tester: if results in the faster "1 minute OHLC" or "Open prices only" modes look too good, test again in "Every tick" mode. Tick data, and real ticks where available, are the only way to know the order of events inside a bar.
Why does revised data cause look-ahead bias?
Because the number in today's database is often not the number traders saw on the day. The US Bureau of Labor Statistics publishes its first estimate of non-farm payrolls about three weeks after the month ends, then revises it twice over the next two months. Since 2003, the average absolute change between the first and third seasonally adjusted estimate has been 51,000 jobs.
May 2026 is a clear example. The first estimate showed 172,000 jobs added, the second 129,000 and the third 63,000: a cut of 109,000. A backtest that reads 63,000 from today's database for the June release is trading on a number nobody had at the time. Archives that store each release as it was first published (the St. Louis Fed's ALFRED is one) exist for exactly this reason.
Why is it a bigger risk for AI and machine learning strategies?
Machine learning models are very good at finding any input that predicts the target, including one that should not be there. A person reading the code might notice that a feature is built from tomorrow's close. A model will simply use it, and the test results will look excellent.
Four traps to know:
- Random train and test splits. Standard cross-validation shuffles rows, so a model can train on Wednesday and be tested on Tuesday. The scikit-learn documentation describes ordinary cross-validation as inappropriate for time-ordered data for this reason, and provides
TimeSeriesSplit, which always trains on earlier data and tests on later data. Itsgapsetting leaves a buffer between the two. - Labels that overlap features. If the target is "price change over the next 10 bars" and a feature includes any of those 10 bars, the model sees part of the answer.
- Data prepared once for the whole set. Scaling, filling gaps or choosing features with the whole dataset leaks the test period's statistics into training.
- Language models that already know the outcome. A large language model is trained on text up to a cut-off date. Ask it about an earnings call or a market move from before that date and it may be recalling what happened next rather than reasoning from what was known. Sarkar and Vafa (2024) built direct tests for this and found evidence of it in forecasts made from corporate earnings calls. Didisheim, Fraschini and Somoza (Economics Letters, 2025) measured how much LLMs remember about past stock returns and found the bias is larger for bigger models, for lower-frequency data and for indices, and negligible for small models on high-frequency data.
The warning sign is the same in each case: results much better than anything comparable, which fall apart on the first data the model has not seen.
How do you check an EA or backtest for look-ahead bias?
- Shift every signal one bar later. A strategy without look-ahead should change only a little. If the result collapses, as ours did from 10,782 to 555 pips, the original test was using future data.
- Check which bar the EA reads. In MQL4/5, timeseries are indexed from newest to oldest, so index 0 is the bar still forming and index 1 is the last closed bar, as the MQL5 reference explains. A signal read from index 0 in a test that only models bar closes is a common cause.
- Use the right tester mode. The MT4/5 strategy tester can model every tick or only bar opens. A strategy that places stops and targets inside a bar needs tick data, or it is guessing the order of the high and the low.
- Recalculate anything statistical on past data only. Averages, ranges, z-scores and machine learning scalers should use a rolling window that ends at the current bar.
- Forward test on a demo account. Run the strategy for a few weeks and compare its trades with what the backtest says it would have done on the same days. A trade the backtest takes that the live version could not have taken points to a leak.
- Be suspicious of a high hit rate on a simple rule. Our leaky test was on the right side of 59% of hourly bars using a 20-period moving average. A simple rule on a pair as liquid as EUR/USD rarely gets close to that once the leak is removed: the fixed version managed 48.4%.
Key takeaways
- Look-ahead bias is any use of information in a backtest that was not available when the simulated trade was decided.
- In our EUR/USD test, applying the position to the bar the signal was measured on, instead of the next bar, lifted the result from +555 to +10,782 pips before costs.
- The fixed result was within the range chance produces, and at 1 pip per switch it fell to about −2 pips.
- Hourly bars hid the true order of the stop and target on 14 October 2026: a recorded 10-pip gain was really a 5.4-pip loss.
- Machine learning models and LLMs are especially prone to it: split data by time, prepare it from the past only, and remember what a language model may already know.
Related lessons
- What is a martingale EA, and why does it fail?
- What is drawdown in trading?
- How do you calculate pip value in forex?
- Demo trading: practise without real money
Sources
- US Bureau of Labor Statistics, "Nonfarm payroll employment: revisions between over-the-month estimates, 1979 to present", Current Employment Statistics: https://www.bls.gov/web/empsit/cesnaicsrev.htm
- Federal Reserve Bank of St. Louis, ALFRED (Archival FRED), vintage economic data: https://alfred.stlouisfed.org/
- scikit-learn documentation, "TimeSeriesSplit": https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.TimeSeriesSplit.html
- MQL5 Reference, "Indexing direction in arrays, buffers and timeseries": https://www.mql5.com/en/docs/series/bufferdirection
- MQL5 Reference, "Testing trading strategies" (tick generation modes): https://www.mql5.com/en/docs/runtime/testing
- Sarkar, S. K. and Vafa, K., "Lookahead bias in pretrained language models", SSRN working paper, 2024: https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4754678
- Didisheim, A., Fraschini, M. and Somoza, L., "AI's predictable memory in financial analysis", Economics Letters 256, 2025: https://www.sciencedirect.com/science/article/pii/S0165176525004392
- Fintrix Markets trading desk test on MT5 EUR/USD data: hourly bars 13 January to 29 October 2026 (4,980 bars), 20-bar simple moving average of closes, long above and short below, each bar measured open to close, no costs; 15-minute bars for 14 October 2026.
Put your knowledge to work
Open a Fintrix Markets account, or log in and trade CFDs on forex, gold, indices and more.



