Donchian channel: if the band includes the current bar, a close can never break it
A common slip with a 20 period Donchian channel. If the highest high is taken over the last 20 bars including the current one, the current bar's high is part of that maximum. A bar's close can never be above its own high, so a close above the upper band is impossible by construction, and a breakout rule written as close above upper band never fires.
Example. The highest high of the previous bars is 1.0850, made 3 bars ago. The current bar has a high of 1.0853 and closes at 1.0851.
Band including the current bar: 1.0853. The close of 1.0851 is below it, so no signal.
Band from the previous 20 bars, shifted by one: 1.0850. The close of 1.0851 is above it, so there's a signal.
The classic Turtle rule is the break of the prior 20 day high, which is the shifted version. In MT5, iHighest with a start index of 1 begins counting at the last closed bar. In TradingView's Pine, ta.highest(high, 20)[1] reads the value from the previous bar. Evaluate on the closed bar, and enter at the open of the next one.
A quick check: run the signal on 1,000 bars. If the count is zero, the band probably includes the current bar.
Donchian channel: if the band includes the current bar, a close can never break it
-
FXS HongKong Scalper
- Posts: 407
- Joined: Sat Oct 24, 2026 10:15 pm
Re: Donchian channel: if the band includes the current bar, a close can never break it
This one bites people in Pine and MQL alike. Using the highest high of the previous N bars, excluding the current one, is the fix, so in Pine it is ta.highest(high, 20)[1]. Worth also checking how the band is drawn on the chart compared with how it is used in the rule. Many built in Donchian indicators include the current bar in the plot, so the line you see is not the line your code should compare against.
FXS Official Team | Hong Kong Session Desk
Re: Donchian channel: if the band includes the current bar, a close can never break it
How many signals should you expect? For a rough random series, the chance that a bar makes a high above the previous 20 bars' highs is about 1 in 21, so close to 48 bars out of 1,000, and a smaller number of those would also close above the band. A few dozen breakout signals in 1,000 bars is plausible. Zero is a bug, almost always the unshifted band. A visual check helps too: with the current bar included, the upper line sits exactly on top of every new high, so price looks as if it's riding the line, touching it again and again without ever closing above. The shifted band sits one step behind and gets crossed.
It’s Fairman 
Re: Donchian channel: if the band includes the current bar, a close can never break it
There's a second way to do it, which is to enter intrabar. Place a buy stop at the shifted band plus the spread, so the order triggers as soon as price trades through the prior 20 bar high, rather than waiting for a close above it. With a band of 1.0850 and a 1 pip spread, the stop goes at 1.0851, since a buy stop triggers on the ask. This gets you in earlier than waiting for the close and also takes more false breaks, since many bars poke through and close back inside. It's the same trade off as the first touch against the close in any breakout rule.
It’s Fairman 
-
Amanhasnoname
- Posts: 1506
- Joined: Fri Oct 30, 2026 9:45 am
Re: Donchian channel: if the band includes the current bar, a close can never break it
I made exactly this mistake in my first MQL5 EA. I used iHighest starting at index 0 and spent an evening wondering why the backtest showed no trades at all over two years of M15 data. I assumed something was wrong with the tester and even reinstalled the terminal before I finally printed the band value next to the bar high and saw they were identical.
The zero signal check you mention would have saved me hours. These days I always run a quick count of signals per thousand bars on any new breakout code before looking at results. If the count is wildly off what I'd expect from eyeballing the chart, the logic is wrong somewhere, and it usually turns out to be an indexing issue like this one.
On the intrabar version, I've used both. The buy stop above the shifted band gets in earlier but in my testing on EURUSD it produced around 40% more trades with a lower win rate, so overall results were similar but much noisier.
The zero signal check you mention would have saved me hours. These days I always run a quick count of signals per thousand bars on any new breakout code before looking at results. If the count is wildly off what I'd expect from eyeballing the chart, the logic is wrong somewhere, and it usually turns out to be an indexing issue like this one.
On the intrabar version, I've used both. The buy stop above the shifted band gets in earlier but in my testing on EURUSD it produced around 40% more trades with a lower win rate, so overall results were similar but much noisier.
Re: Donchian channel: if the band includes the current bar, a close can never break it
The exit channel has the same offset. The Turtles used a shorter channel for exits: the low of the previous 10 days to exit a long. If that low includes the current bar, a close below it can't happen for the same reason, so the exit never triggers and the trade rides far beyond where the rule said to leave. When a trend following test shows suspiciously large winners and a very small number of exits, check that both channels are shifted. Mistakes like this often make a backtest look better in some respects and worse in others.
It’s Fairman 
Re: Donchian channel: if the band includes the current bar, a close can never break it
For reference, the original Turtle System 1 used a 20 day breakout for entries and a 10 day low for exits, while System 2 used 55 days for entries and 20 days for exits. Those were daily bars. On M5 or M15, a 20 bar channel covers 100 minutes or 5 hours, which is a different idea, and nobody should expect the results of the daily rules to carry over to it. If you're borrowing the channel idea for intraday, choose the length by how long the move you want to catch takes, not by copying the numbers from daily charts.
It’s Fairman 