Multi timeframe filter in my EA and the repainting bug that fooled my backtest
I added a higher timeframe filter to my M5 EA, using an M15 moving average to decide the direction. The backtest improved a lot, which should have made me suspicious. It turned out I'd made a classic mistake.
When the EA read the M15 value on the current bar, it was reading a value that wasn't final yet. In the tester, depending on how it's set up, that could include information from the future within the bar. The M15 candle was still forming, but the test was using values that only exist after it closed. Live, the EA only sees what's actually available at that moment, so the results didn't match.
The fix was to read the M15 values from the last closed bar, not the current one. That means the filter reacts one bar later, but it's what actually happens in real time. After that change, the backtest improvement mostly disappeared, which told me it wasn't real.
Whenever a result looks too good after a small change, I go looking for a mistake like this before I celebrate. Using only closed bar data for anything that comes from another timeframe is a rule I follow now.
Multi timeframe filter in my EA and the repainting bug that fooled my backtest
Re: Multi timeframe filter in my EA and the repainting bug that fooled my backtest
Reading from the last closed bar is the fix, and I would add that it applies to anything from a higher timeframe, not just moving averages. Highs, lows and candle patterns on M15 all have the same problem if you read the forming bar. I made it a habit to always use shift one for any higher timeframe value unless I specifically want the live one, and if I do, I make sure the tester is set to model it correctly.
It’s Fairman 
Re: Multi timeframe filter in my EA and the repainting bug that fooled my backtest
Another thing worth checking is whether the higher timeframe data is actually available in the tester for the dates you test. If the M15 history is missing or incomplete, some testers quietly build it from M5 or return zero, and the filter behaves strangely. I check the history before testing and print the filter value on a few bars to make sure it matches what I see on a normal chart. That caught a problem once where the filter was reading empty values.
It’s Fairman 
Re: Multi timeframe filter in my EA and the repainting bug that fooled my backtest
The suspicious improvement point is the real lesson here. When a simple filter makes a backtest dramatically better, I now assume a bug first and an edge second. A real filter usually helps a bit, by cutting some bad trades and some good ones. A filter that removes nearly all losers is almost always reading information it should not have. Running the EA on demo for a couple of weeks next to the tester for the same period is the quickest way to confirm.
It’s Fairman 
-
FXS Prop Desk
- Posts: 1689
- Joined: Wed Oct 07, 2026 9:52 am
Re: Multi timeframe filter in my EA and the repainting bug that fooled my backtest
A big improvement from adding a higher timeframe filter is almost always worth checking for this bug. Using the current, unfinished M15 bar in the test means the EA knew where that bar would close.
Reading the M15 value with shift 1, the last completed bar, removes the problem. The backtest usually gets worse afterwards, but the result is the one live trading will actually produce.
Reading the M15 value with shift 1, the last completed bar, removes the problem. The backtest usually gets worse afterwards, but the result is the one live trading will actually produce.
FXS Official Team | The Idea Lab & Strategy
-
Shadow Trader
- Posts: 5594
- Joined: Wed Sep 09, 2026 5:19 pm
Re: Multi timeframe filter in my EA and the repainting bug that fooled my backtest
A quick way to tell a real filter from a leaking one is to look at what it removed. Say the unfiltered EA takes 500 trades at a 48 percent win rate and the filter removes 200 of them.
A filter with no real information keeps the win rate near 48 percent on the 300 trades left, and an honest one might lift it to 52 or 53. If the kept trades jump to 70 percent, that is 210 winners, which leaves only 30 of the original 240 winners among the 200 removed.
A removed group that wins 15 percent of the time is the giveaway. Very few honest rules can sort trades that well before the bar has closed.
There is one more trap with shift one at the start of a new M15 bar. On the first tick of the new M5 bar, the M15 series may not have updated yet, so shift one can still point at the bar before.
Checking that the open time of the M15 bar at shift one matches the expected quarter hour, and skipping the tick if not, closes that gap. It rarely shows in the tester but can appear live after a reconnect.
A filter with no real information keeps the win rate near 48 percent on the 300 trades left, and an honest one might lift it to 52 or 53. If the kept trades jump to 70 percent, that is 210 winners, which leaves only 30 of the original 240 winners among the 200 removed.
A removed group that wins 15 percent of the time is the giveaway. Very few honest rules can sort trades that well before the bar has closed.
There is one more trap with shift one at the start of a new M15 bar. On the first tick of the new M5 bar, the M15 series may not have updated yet, so shift one can still point at the bar before.
Checking that the open time of the M15 bar at shift one matches the expected quarter hour, and skipping the tick if not, closes that gap. It rarely shows in the tester but can appear live after a reconnect.
-
Shadow Trader
- Posts: 5594
- Joined: Wed Sep 09, 2026 5:19 pm
Re: Multi timeframe filter in my EA and the repainting bug that fooled my backtest
A repainting indicator changes values it has already displayed. On a historical chart it appears to have called turning points with remarkable accuracy, yet in real time those same signals shift, vanish or arrive late. The gap between the two is not bad luck but a structural property of how the code uses data.
Common causes include logic that references bars not yet closed, so the current bar's value changes with every tick, and calculations that look forward to confirm a swing point. Zigzag and fractal-based tools are typical, since a swing high can only be confirmed after later bars have printed lower highs. Higher-timeframe data requested without proper handling can also leak future information into earlier bars of a lower timeframe chart.
Detection is straightforward. Leaving the chart open and watching whether a signal on the forming bar disappears before the close is the simplest test. Another is to record screenshots or log signals as they appear and compare them against the finished chart later. Signals tied strictly to closed bars, which can still lag, are repeatable, while forming-bar signals often are not. Any backtest built on a repainting tool overstates performance, because it measures knowledge that was not available at the time. Verifying behaviour in real time before trusting a tool is a basic form of due diligence.
Common causes include logic that references bars not yet closed, so the current bar's value changes with every tick, and calculations that look forward to confirm a swing point. Zigzag and fractal-based tools are typical, since a swing high can only be confirmed after later bars have printed lower highs. Higher-timeframe data requested without proper handling can also leak future information into earlier bars of a lower timeframe chart.
Detection is straightforward. Leaving the chart open and watching whether a signal on the forming bar disappears before the close is the simplest test. Another is to record screenshots or log signals as they appear and compare them against the finished chart later. Signals tied strictly to closed bars, which can still lag, are repeatable, while forming-bar signals often are not. Any backtest built on a repainting tool overstates performance, because it measures knowledge that was not available at the time. Verifying behaviour in real time before trusting a tool is a basic form of due diligence.