Avoiding Look-Ahead Bias When Backtesting with OHLC Data
Summary
The document discusses how to use open, high, low, and close prices in a bar-based strategy simulation. Its central rule is to make simulated decisions only with information that would have been available at the time. For an order evaluated on the current candle, the answer recommends using the current open for trade decisions while allowing indicators to use completed, historical candles. Current-candle high and low can be formed from streaming tick data as the candle develops.
The reason is that a completed bar does not reveal whether its high or low occurred first, or the path price took between them. A backtest that assumes a strategy could trade at a particular intrabar extreme may therefore rely on information unavailable in real time and report unrealistic results. This guidance is aimed at OHLC-based simulations; it does not specify order-fill rules, slippage, or how to reconstruct intrabar paths when tick data is unavailable.
Key ideas
- Backtests should use only information that would have been available when each trade decision was made.
- A completed candle does not reveal the order in which its high and low occurred.
- For decisions made on a current bar, the answer recommends using its open and completed historical bars.
- Current-bar highs and lows can support real-time decisions when built from incoming tick data.
- The guidance does not define execution costs or fill assumptions.
Tags
Full text
# backtesting with open, close, high and low # backtesting with open, close, high and low I am quite notice at the business of backtesting for an automated strategy. I was wondering, can I/should I use High and Low for this purpose? On one hand, the algorithm will see these prices, but on the other, the order in which they are seen is not defined, so there is a potential ambiguity there. Also, buying at "High" is not realistic since the algorithm will never know that's it is the highest price for the day. What do you think or advise? ## Answer by Svisstack (score 2, accepted) https://quant.stackexchange.com/a/9082 No you certainly should not use in simulation any data that you don't know in real environment because simply results will be much different. Simulation should be created in environment as much possible similar to real environment. You basically should use only Open values for making trades, High/Close/Low you can use for indicator calculation of past candles. High/Close states are not usable because you don't know in what order they appear, this can be: ``` - Open, High, Low, Close - Open, Low, High, Close - Open, High - 2, Low, High - 1, High, Close ``` If you are using OHLC data and you are calculating operation OnCandle appears then you can use OHLC from past candles and only Open from current. In general you can use OHLC in current candle for making trades but current candle High/Low should be created online using TickData stream.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.