Repainting
An indicator that needs bars after the one it draws on will move what it has already drawn, and the move is not noise. It runs in your favour, by construction. A rule that marks a bar as a low because the following bars are higher cannot be revised against you, because the condition that creates the signal is the condition that makes the later price better: the displacement has one possible sign and the rule itself fixes it. On the module’s sixty closes a two-bar pivot rule marks seven round trips. Taken where the finished chart shows them they win seven times out of seven, never trade a tick against the entry, and total 20.40 points. Taken at the first moment each one was knowable they win four times out of seven and total 3.90. Four fifths of that backtest was the chart moving after the fact. And while the bars are live the same rule puts markers on the chart that do not survive: four of its thirteen at two bars, four of eight at three, three of six at five.
Prerequisites: Lesson 48, whose closing test — does the value drawn at a bar depend on any bar after it — is the whole subject here, lesson 17, because the quantity repainting inflates is expectancy and you need to be able to state it before you can watch it move, and lesson 19, whose arithmetic on how many observations a claim needs is what prices the detection test at the end.
A signal that is still provisional
Repainting is one narrow thing, and it is worth stating narrowly before the examples widen it. A signal repaints when the value drawn at a bar changes after that bar has closed. It moves to a different price, or it moves to a different bar, or it disappears. The chart you are looking at now and the chart you will look at in a month are not the same chart, and only one of them was ever tradeable.
The mechanism is rarely deceit and usually arithmetic. Take the commonest swing rule on any platform: a bar is a pivot low if it is lower than the k bars before it and lower than the k bars after it. The left-hand condition is knowable at the bar. The right-hand condition is not knowable for k more bars. So the marker cannot honestly be drawn until bar t+k, and any chart that draws it at bar t is drawing a conclusion from bars that have not printed.
What that produces on a live chart is a flicker. As soon as one bar closes higher, the bar behind it satisfies part of the right-hand condition and a provisional marker appears. If a later bar within the window undercuts it, the marker is wrong and vanishes. On this module’s sixty closes the two-bar rule puts a marker on thirteen different bars at some point and only nine of them survive; the three-bar rule marks eight and keeps four; the five-bar rule marks six and keeps three. Between three in ten and one in two of what you see while the bars are live is not there afterwards.
The duration is exact and worth carrying: a marker first appears at t+1 and is final at t+k, so a rule that looks k bars ahead leaves every signal provisional for k-1 bars beyond its first appearance. Five-bar pivots flicker for four bars. That is not a defect in the implementation. It is what the definition asks for.
The displacement cannot have the other sign
The interesting part is not that the signal moves. It is that the move is one-directional, and the reason is logical rather than statistical.
Write the pivot-low condition out: bar t is a signal because the closes at t+1 through t+k are all above it. Then the price at t+k is above the price at t, necessarily, because that is one of the clauses that made t a signal in the first place. The gap between the price the chart shows you and the price you could actually have paid is positive every single time, and no sample is large or small enough to change that. It is a property of the rule, not of the market it was run on.
The size is the empirical part, and the table separates it from what an unselected bar does over the same span. The unconditional column is the same k-bar change measured on every bar a signal could have sat on, which means every bar from k in to k from the end, and it is what you would expect the displacement to look like if it really were noise. The set matters more than it sounds: average over all sixty bars instead and the three figures come out at 0.19, 0.30 and 0.48, which changes the last ratio in the paragraph below from 6.0 to 3.9.
| Bars of lookahead | Signals | Mean displacement | Smallest | Same span, any bar |
|---|---|---|---|---|
| Two | 9 | +1.00 | +0.50 | +0.18 |
| Three | 4 | +0.80 | +0.20 | +0.21 |
| Five | 3 | +1.87 | +0.70 | +0.31 |
Read the mean displacement against the last column. Noise would straddle zero and would come out at roughly what any bar does over the same span. This does neither: the smallest displacement is positive at every window length, not merely the average, and the average is 5.4, 3.9 and 6.0 times the unselected figure reading down the rows. The three rows are not really comparable with each other, because four signals is four signals, but each is comparable with the column beside it, and all three say the same thing.
The same argument runs the other way at the exit. A pivot high is a bar the following closes are all below, so selling it in hindsight sells above what you could have got. On the seven round trips below, the entry is displaced 1.03 points in your favour on average and the exit 1.33, and those two together across the seven trades account for the whole 16.50-point gap between the two versions, with nothing left over.
What that does to the backtest statistics
A displaced entry does not just shift the result. It reshapes every statistic you would use to judge it, and it reshapes them in the directions people find most persuasive.
The win rate is distorted first. Entering at a bar that is by definition lower than the two bars on either side means the trade starts at a local minimum, so trades that would have been small losers become small winners. On the seven trades below, the repainted version wins all seven and the honest version wins four. A hundred per cent hit rate is not evidence of an extraordinary rule here; it is evidence of an entry chosen after the fact.
The profit factor is distorted next, and further. Gross profit over gross loss has no denominator when there are no losing trades, so the repainted version does not have a large profit factor, it has an undefined one. The honest version comes in at 2.39, which is a respectable number that a person might reasonably act on. The difference between those two readings is not a difference of degree.
The tell most people quote is the win rate, and the tell is actually the drawdown. Measure how far each trade goes against the entry in its first two bars: on the repainted entries that figure is exactly zero on all seven, because a pivot low is the lowest close in its neighbourhood and there is nothing below it to trade to. The honest entries average 0.33 against them and reach 1.40 at worst. An equity curve with no adverse excursion in it at all has usually not found a way to avoid pain; it has usually chosen its entries from the far side of the outcome.
The other way it gets in: a higher timeframe read too early
The pivot case is visible because the marker jumps. The other common route is silent, and it is worth working because nothing on the chart flickers at all.
Aggregate this module’s sixty closes into twelve blocks of five, the way a five-minute chart aggregates into a twenty-five-minute one. Each block has a close, which is the last of its five bars. A request for that value that is not told to wait will hand it to you at the block’s first bar rather than its last, so on every bar inside the block your chart already knows where the block finishes.
Price that. The blocks move 1.675 points on average from first bar to close, and the direction is known four bars early on all twelve. A rule that goes with the block’s own direction from the block’s first bar therefore books 20.10 points across the series with a hundred per cent hit rate. The whole series only travels 71.00 points gross and 5.80 net, so the leak is worth 28.3 per cent of every movement the series contains, and it accrues without a single marker moving anywhere on the screen.
This is why the fix in the platform documentation is two changes rather than one: request the higher-timeframe value with lookahead disabled, and then take the previous completed value rather than the current one. The first stops the request returning a bar that has not finished. The second stops it returning a bar that is still open. A tool that does one and not the other still leaks, and it leaks quietly.
The same rule, priced twice
Here is the whole argument in one strategy, run two ways on the same sixty numbers, with the same rule and the same exits. Enter long on a two-bar pivot low, exit on the next two-bar pivot high. The only thing that differs between the two columns is when the signal is allowed to be known.
The repainting version does what a chart does: it puts the entry on the pivot bar, at the pivot price, because that is where the finished chart shows the marker. The honest version puts it two bars later at that bar’s close, which is the first moment the pivot could be identified without consulting bars that had not printed. Nothing else changes. Same rule, same series, same seven round trips.
| Entry bar | Exit bar | As drawn | As knowable |
|---|---|---|---|
| 2 | 5 | +3.70 | +0.60 |
| 7 | 10 | +4.60 | −0.70 |
| 18 | 25 | +0.10 | −1.30 |
| 26 | 29 | +1.20 | +0.30 |
| 30 | 36 | +3.90 | +2.10 |
| 39 | 52 | +5.60 | +3.70 |
| 54 | 55 | +1.30 | −0.80 |
The repainting column totals 20.40 points across seven trades, an average of 2.91, with seven winners and no losers at all. The honest column totals 3.90, an average of 0.56, with four winners and three losers. The strategy is not destroyed by the correction, and 3.90 points at a profit factor of 2.39 is a real result rather than a ruin — though at seven round trips for 3.90 points the costs of lesson 10 have stopped being a rounding error against it. What is gone is the part that made it look remarkable, and that part was the two-bar shift: a fifth of the advertised total survives.
Notice which trades carry the damage. The second trade goes from 4.60 points to a 0.70-point loss and the third from 0.10 to a loss of 1.30, because both were marginal trades whose apparent profit was smaller than the displacement. The two large winners survive in reduced form. That is the general shape: repainting does not scale a result down uniformly, it converts the marginal trades from losers into winners, which is exactly the population that decides whether a rule has an edge.
One honest caveat. Seven trades is an illustration and not an estimate, and the module series is sixty numbers rather than a market. What transfers is not 80.9 per cent. What transfers is that the displacement had a fixed sign on every trade, that its size was the move over exactly the bars the rule looked ahead at, and that the two columns reconcile completely — the 1.03 at the entries and the 1.33 at the exits account for the 16.50 points of difference and leave nothing unexplained.
How many signals you have to watch
The test everybody recommends is the right test: note where a signal sits while the bar is live, look again after it closes, and see whether it is still there. What nobody attaches to it is a number of observations, and without one the test can mislead in the reassuring direction.
Treat each signal as an independent trial with some unknown chance of moving. Watching five signals catches a tool that moves half of them with probability 0.97, which is why the usual advice to watch three to five is sound for the badly broken case. It is not sound for the mild one. Catching a tool that moves one signal in ten even 95 times in a hundred takes twenty-nine signals, and one in twenty takes fifty-nine.
Run it backwards and it becomes more useful, because the interesting case is the tool that passes. Five clean observations rule out a repaint rate above 45.1 per cent and nothing more. Ten rule out 25.9 per cent, twenty rule out 13.9 per cent, and fifty rule out 5.8 per cent. So a tool you watched for an afternoon and found clean is a tool you have shown is not catastrophically broken, which is worth knowing and is not the same as having shown it is deterministic.
Two things make that cheaper than it sounds. The first is that bar replay compresses the waiting: you can step three days of a five-minute chart through in an evening and collect thirty observations rather than five. The second is that source code, where you have it, settles the question outright instead of sampling it — a rule that references a bar offset forward, or a higher-timeframe request without the wait, repaints for every signal rather than some proportion of them, and one reading answers what fifty observations only bound.
What this does not settle
That a repainting indicator is a dishonest one. Most of it is default behaviour rather than intent. The convenient way to read a higher timeframe returns an unfinished bar unless told otherwise, and the standard swing function is defined in terms of bars on both sides, so an author who writes the obvious thing ships a repainting tool without deciding to. That matters for how you respond: the question to put to a tool is what it does, not what its author meant, and the test above answers the first question without needing an answer to the second.
That waiting is the only thing the correction costs. The honest column is genuinely tradeable, because two bars after the pivot you know whether the pivot confirmed, and it is not what the chart invites you to do. The chart invites you to act on the marker while it is on the screen. Do that on the same sixty closes — buy at the close after each of the thirteen provisional low markers, sell at the close after the next provisional high — and the same rule gives ten round trips totalling minus 5.50 points, three winners in ten, and a profit factor of 0.59. So the 16.50 points between the drawn column and the knowable one is what repainting takes out of the record, and the 9.40 between the knowable column and that one is what it takes out of a trader who does what the screen is asking. This lesson measures the first gap. The second is larger and it is not measured here.
That a centred or forward-looking rule is therefore useless. A pivot that needs two bars on the right is a perfectly good description of the past and a perfectly good input to a study. It becomes repainting only when it is drawn at a bar it cannot yet be known at. Delay it by its own lookahead and it stops repainting entirely and stays exactly as informative — the honest column above is that same rule, still profitable. The defect is in the timestamp, not the formula.
That the 80.9 per cent transfers to your instrument. It does not, and neither does the 20.40. Seven round trips on sixty constructed closes is a demonstration built to be recomputable, not an estimate of anything. What transfers is the structure: the sign of the displacement is fixed by the rule, its magnitude is the move over exactly the bars the rule conditioned on, and the marginal trades are where the damage concentrates. Measure your own instrument the way the table does and you will get your own number.
That passing the visual test makes a tool deterministic. It bounds the repaint rate and nothing stronger, and the bound from a short run is loose: five clean signals leave rates up to 45.1 per cent live, and twenty leave 13.9 per cent. A tool can also repaint only under conditions you did not sample — only on the higher timeframe, only across a session boundary, only when two conditions coincide. Sampling cannot rule that out. Reading the code can.
That this settles whether the strategy is any good. It settles whether you are looking at the strategy at all. A tool that does not repaint gives you a backtest whose entries were available, which is the precondition for the question rather than an answer to it — and the honest number may well say the rule is bad. Lesson 17’s expectancy and lesson 19’s arithmetic on how long a result takes to establish are what judge it. This lesson only makes sure the record being judged is a record of something that happened.
Problems
- Price the displacement on the tool you trust most. Keep three columns. While a bar is live, write down each signal and the price it sits at. After the bar closes, write down where that same signal now sits. In the third column put the difference multiplied by your instrument’s value per point. Do it until you have twenty observations rather than three: twenty clean ones bound the repaint rate below 13.9 per cent, while three still leave anything under 63 per cent possible. The total of the third column is what the tool costs you before the strategy has been judged at all.
- Find the lookahead in the definition, then delay it by exactly that much. For each indicator on your chart, write down how many bars after the marked bar its formula refers to. Zero means it cannot repaint by this route. Anything above zero is the number of bars the signal stays provisional and the span over which the displacement accumulates. Then re-run the rule with every signal delayed by that many bars and compare the two equity curves. The difference is not a bug you have found; it is the part of the original that was never available.
- Check the drawdown before you check the win rate. Take any backtest you are considering and measure how far each trade went against the entry in its first few bars. If that figure is near zero across a long run of trades, ask what selects the entries, because an entry chosen without reference to later bars will sometimes be badly timed and the record should show it. A curve with no adverse excursion in it is the strongest single symptom of a rule that has seen the outcome, and it is visible without knowing anything about how the indicator works.
Sources. Athanasios Orphanides, “Monetary Policy Rules Based on Real-Time Data” (American Economic Review, 2001), for the same failure outside trading: policy prescriptions that look sound on revised data and reverse when recomputed on the numbers that were actually published at the time. Dean Croushore and Tom Stark, “A Real-Time Data Set for Macroeconomists” (Journal of Econometrics, 2001), for the practice of keeping every vintage of a series so that a study can be run on what was known rather than on what is known now. Halbert White, “A Reality Check for Data Snooping” (Econometrica, 2000), for why a result selected with knowledge of the outcome needs a different standard of evidence than one that was not. David H. Bailey, Jonathan M. Borwein, Marcos López de Prado and Qiji Jim Zhu, “Pseudo-Mathematics and Financial Charlatanism” (Notices of the American Mathematical Society, 2014), for how far an in-sample record can be inflated before anyone has done anything that looks like cheating. TradingView, Pine Script v5 User Manual, the repainting section, for the primary statement of which constructs return unfinished bars and what the two corrections are.
The test is one question asked of every line on the chart: does the value drawn here depend on anything that had not happened yet. Where the answer is no, the record in front of you is a record of decisions that were available, and you can go on to the harder question of whether they were good ones. Where the answer is yes, the record is not weak evidence about a strategy, it is evidence about a different strategy — one that entered at prices chosen after the outcome was known — and no amount of it accumulates into knowledge about the one you would actually trade. Lesson 50 takes the most-used line on any chart and counts the touches: 3 of them on this module’s sixty closes, or 22, depending on a tolerance no platform prints, and a hold rate of 53 per cent against the 45 the tape gives you with no line drawn at all.
What an Indicator Is
The revision test this lesson takes up, and the arithmetic of what a filter must discard.
Read Lesson →Market Structure
Where the swing rule comes from, and why its right-hand side is the part that has not happened.
Read Lesson →Divergence
A whole category whose lines redraw, and the settings that decide whether one exists at all.
Read Lesson →Moving Averages
The most-used line on any chart, and what it is entitled to say about a level.
Read Lesson →Educational only. Trading involves substantial risk of loss. Not financial advice. Past performance does not guarantee future results.
💬 Discussion (0 comments)
Loading comments...
Ready to Trade with Signal Pilot?
Apply your trading education with professional indicators and real-time market analysis tools.
Back to Signal Pilot →