Limiting Strategy Backtests to a Fixed Number of Recent Bars
Summary
This indicator creates a time-based window intended to limit which chart bars a strategy uses for a backtest. The user selects a bar count; the script estimates the corresponding elapsed duration from the chart timeframe, subtracts it from the current time, and marks bars at or after the resulting start timestamp. A strategy can use that plotted condition to restrict its calculations to the recent window.
The accompanying explanation frames this as useful when a data source provides a chosen number of bars rather than a start date, and suggests comparing the resulting TradingView test window with the intended sample. The calculation approximates daily, weekly, and monthly bars using fixed durations, so it may not align exactly with calendar periods or exchange sessions. It is a windowing utility rather than a backtest engine and does not provide performance results or address other sources of bias.
Key ideas
- The script converts a selected bar count into an estimated elapsed time based on the chart timeframe.
- It marks bars whose timestamps fall within the resulting recent-date window.
- A strategy can use the marker condition to restrict calculations to a chosen sample length.
- Fixed duration estimates for calendar periods may not match actual trading sessions or calendar boundaries.
- The document explains sample-window control but gives no strategy performance evidence.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.