Backtesting basics

Backtest Look-Ahead Bias: Examples and Prevention Steps

Published ForeXpert team日本語で読む

Backtest look-ahead bias occurs when a historical decision uses information that was unavailable at its supposed decision time. Looking at future candles is one example. Substituting a completed hourly candle for its earlier unfinished state, or using a swing label before it could be confirmed, can create the same problem.

Three habits help: align information timestamps, write the decision before the outcome and preserve the original record. This guide develops those habits for discretionary chart practice and explains what to do if you accidentally reveal the future.

What backtest look-ahead bias means

A completed historical chart contains information the trader could not yet know during its formation. A turning point may look obvious afterwards even though it was uncertain at the time. Counting a trade because you can now see that price rose adds a decision that may never have been possible under the written rules.

TradingView's official strategy documentation describes look-ahead bias as future information leaking into historical evaluation. The issue is relevant to automated code, but a person choosing discretionary entries can introduce it too.

Removing look-ahead does not make a backtest complete. Costs, missing data and repeated rule selection remain separate concerns. Treat this check as a way to establish whether the historical decision used information that actually existed then.

Problem Where the distortion enters Review question
Seeing later prices Entry or skip decisions Would the decision be the same with the future hidden?
Adding outcome-led conditions Rule development Was the condition written before seeing results?
Selecting attractive scenes Test coverage Were candidates across the full period considered?

These problems can overlap without being identical. Look-ahead concerns information timing; overfitting primarily concerns how rules are selected; selective scenes concern what is included in the test. The overfitting guide explains why an honest replay still needs a disciplined development process.

Four examples in manual chart practice

Finding an entry after seeing the move

You first inspect a large rally, then mark a pullback before it as an entry you “could have taken.” This can be a useful chart-study exercise, but it is different from making a decision without knowing the outcome. Label it as outcome-informed practice rather than adding it to an unseen-data result.

The distinction also applies when you remember a familiar period. Hiding the right edge of the chart does not erase information already learned. Keep a note of that familiarity and use another period when the question requires fresh decisions.

Using an unfinished higher candle's final values

Suppose an H1 candle runs from 10:00 to 11:00. At a 10:15 decision point, its 11:00 close is unavailable. A closed-bar rule can use the preceding completed H1 candle, while a developing-bar rule needs the actual state at 10:15.

Using a developing candle is not inherently future leakage. The error is substituting the completed candle when its intermediate state has not been reconstructed. Our guide to multiple timeframe practice shows how to align those decision times.

Using a swing label before confirmation

Imagine defining a swing high as a candle whose high exceeds the highs of two candles on each side. The two candles to its right must finish before that definition can be confirmed. A marker drawn back on the original candle does not mean the signal was available there.

Separate the location being labeled from the time the label became knowable. TradingView's repainting documentation discusses how plotting into the past can create misleading impressions. Check the behavior of the specific indicator you use rather than assuming all markers share the same timing.

Choosing a favorable order inside one candle

If a candle's high reaches a target and its low reaches a stop, its open, high, low and close may not reveal which exit came first. Choosing the winning sequence invents information about the intrabar path.

Strictly, that is an unresolved execution sequence rather than necessarily the use of future data. It still deserves a separate flag. Check whether finer data resolves it; otherwise record the uncertainty and use a predefined convention. If different plausible sequences change the conclusion, report that dependence instead of silently choosing the favorable case.

Four steps to prevent look-ahead in practice

Four checks: hide future prices, verify confirmation times, record decisions before outcomes and use a fresh period without rewriting the original result
Diagram: Keep historical decisions within available information

1. Keep future prices out of view

Choose the period and decision timeframe before stepping through the chart. Advance one candle at a time and avoid surveying the complete test period first. Save the reason for choosing the dates so that convenient period selection remains visible during the review.

ForeXpert supports bar-by-bar practice on historical charts. That helps structure the exercise, but it cannot stop a trader from checking another chart or changing a rule after an outcome. Combine the controls with your own decision record.

2. Identify when each input becomes available

For the decision candle, higher-timeframe inputs and indicators, write when the value is confirmed. If a condition uses economic releases, you need records of the release time and the information available then. A later revision should not be substituted for what was originally known.

Do not fill gaps by assuming the answer you needed was available. If the missing input is essential, record the limitation. A version that omits that input can be studied separately, but it is a different rule and should be labeled accordingly.

Also check timezone and candle-label conventions. A label can refer to the opening time while your note refers to a closing time. Resolve that mismatch before treating a timestamp as proof that information was known.

The same timing check applies to economic releases. Our guide to backtesting a forex news filter shows how to distinguish the schedule you could have known from the time a report actually came out.

3. Record the decision before revealing the outcome

At minimum, save the decision time, the inputs consulted and the reason for acting, waiting or skipping. If you capture a screenshot, save the view available at that moment. A completed chart captured later is not evidence of what you saw before the trade.

Field Save at decision time Keep separately afterwards
Timestamp Date, time and timezone Exit time
Inputs Available bars and conditions Later completed candle shapes
Response Act, wait or skip, with a reason Outcome-led improvement ideas

Use a predefined rule for logging skipped candidates too. If you save only the missed moves that later became spectacular, the skip record becomes selective. A short consistent note is more useful than a detailed explanation written only for memorable outcomes.

4. Preserve the record and test revisions elsewhere

After the test, put review comments in a separate field. If you think you should have waited, translate that thought into a condition that can actually be observed before the outcome. “Enter only before the large move” is not an executable rule because the large move is the unknown part.

Give any revised condition a new version and evaluate it on data you have not inspected. Retain the original result, reason for the change and fresh evaluation separately. The trading-journal review guide explains how to turn a record into a specific next practice question.

What to do after accidentally seeing the future

Write down when it happened and which part of the exercise might be affected. Do not selectively delete only an inconvenient trade. Separate outcome-informed practice from the part that was completed without revealing future information.

You can still use the contaminated segment to learn controls or clarify a rule's meaning. Waiting until you think you have forgotten it does not establish that the data is unseen again. If the question requires an unfamiliar decision, choose a fresh period.

Keep the affected record rather than replacing it with a cleaned-up story. The note explains why a result has limits and what changed in the next test. That is more useful than joining together only the attractive sections and presenting them as one uninterrupted evaluation.

Summary

Execution review has its own information limits: a bar's high and low may not establish which exit happened first. Our guide to a stop loss and take profit in the same bar explains how to check order activation times and record unresolved outcomes.

Audit the timing of the inputs and the timing of your own notes, as well as the chart's right edge. Before each decision, ask whether every input was knowable at that moment, then preserve a one-line reason before advancing.

Backtest results do not guarantee future performance. Even a test without look-ahead still faces costs, execution differences and the risk of loss in live trading. Keep outcome review distinct from decisions made before the outcome so that each exercise answers an honest question.