The Donchian channel indicator draws the highest high and the lowest low of a fixed lookback. Three lines come out of it: an upper rail, a lower rail and the midline. Breakout traders use the rails as a trigger. The midline works as a plain trend reference.
This build ships as donchian-channel-indicator-indicator-forexmt4systems.ex4 for MT4 and donchian-channel-indicator-indicator-forexmt4systems.ex5 for MT5; the screenshots below come from EURUSD H1.
| Platforms | MT4 (.ex4) + MT5 (.ex5) |
|---|---|
| Chart window | Main price chart |
| Plots | 3: Donchian Upper, Donchian Middle, Donchian Lower |
| Alerts | popup, push notification, email, sound |
| Inputs | 8 |
What the Donchian Channel Indicator draws on the chart
Donchian Upper follows the highest high of the window. Donchian Lower follows the lowest low. Both draw at double width so they stand clear of the candles.
Donchian Middle sits exactly halfway between the two rails. The code averages the same upper and lower values rather than smoothing price. The midline therefore steps instead of curving.
InpShift moves all three lines sideways without touching the maths. Leave it at zero unless you want the channel pushed forward.
- Donchian Upper: line, dodger blue, width 2
- Donchian Middle: line, goldenrod, width 1
- Donchian Lower: line, orange red, width 2

How the Donchian Channel Indicator calculates its values
Highest high and lowest low
The rule is short. For every bar the code asks for the highest high across InpChannelPeriod bars. It asks for the lowest low across the same span. Those two prices become the rails for that bar.
The window covers the bar it measures. A new high therefore lifts the upper rail on the same bar. The rail tracks price instead of leading it.
The midline
Averaging does the rest. Donchian Middle takes the upper rail plus the lower rail and halves the sum. No smoothing sits behind that value. It holds flat while both rails hold, then jumps when either moves.
The touch check
One test runs after the loop. The code compares the close of the last completed bar with both rails. A close at or above the upper rail counts as an upper touch. A close at or below the lower rail counts as a lower touch.
That test is strict. The window includes the bar itself. A close only reaches the upper rail when it also sets the window high. Wick touches happen far more often.
How to read the signals
A close on the upper rail says the market made a new window high. Trend followers read that as continuation. They use the lower rail or the midline as the exit reference.
Flat rails mean a range. Both lines sit level while the market makes no new extreme. Breakout entries taken inside that box tend to fade.
The midline gives a middle ground. Price above it with a rising upper rail suits long bias. The mirror reading suits short bias. That line only reacts when a rail moves.
Alert channels in this build: popup, push notification, email and sound, one message per closed bar.
InpEnableAlerts ships switched off. Turn it on and the build can raise a popup, a push notification, an email or a sound. The message fires on the closed bar that touches a rail, once per bar.
Every Donchian Channel Indicator input
Core settings
| Setting | What it does | Default |
|---|---|---|
InpChannelPeriod |
Donchian channel period (bars). Bars in the lookback window. Twenty suits swing charts, and a shorter span reports more touches. | 20 |
InpShift |
Horizontal shift (bars). Sideways offset for all three lines, counted in bars. Leave it at zero for a standard channel. | 0 |
Alert settings
| Setting | What it does | Default |
|---|---|---|
InpEnableAlerts |
Master alert toggle. | off |
InpEnablePopup |
Popup Alert(). | on |
InpEnablePush |
Push notification. | off |
InpEnableEmail |
Email. | off |
InpEnableSound |
Play sound. | off |
InpSoundFile |
(see inputs panel) | alert.wav |

Settings that fit your chart
Channels need swings. The shipped screenshots use EURUSD on H1 for that reason. On M5 the rails redraw constantly and the touches lose meaning. H4 and D1 suit position work, where twenty bars cover a month of daily trade. Gold and index CFDs work as well. Their wider ranges push the rails further apart than a major pair does.
When the Donchian Channel Indicator fails
The rails only look backward. A channel with no new extreme for fifty bars says nothing about pressure building underneath. The first move out often runs before the rail reacts.
Range markets generate false breaks. Price clips the upper rail, closes, then drops back inside. The channel widens just enough to make the next break look weaker.
Including the current bar costs you the classic signal. A new high lifts the rail immediately. Price cannot close above the upper rail on the bar that makes the high. The alert reports the touch and nothing more.
The midline trails both rails. It holds still through long stretches and then gaps. That makes it a poor trailing stop next to an average moving each bar.
Copy donchian-channel-indicator-indicator-forexmt4systems.ex4 into MQL4/Indicators and donchian-channel-indicator-indicator-forexmt4systems.ex5 into MQL5/Indicators, then restart the terminal and drag the Donchian Channel Indicator onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.
Download the Donchian Channel Indicator for MT4 and MT5
The zip donchian-channel-indicator-indicator-forexmt4systems.zip holds donchian-channel-indicator-indicator-forexmt4systems.ex4, donchian-channel-indicator-indicator-forexmt4systems.ex5 and a short README, compiled files only. Enter your email below and the download link arrives in your inbox.
Download this indicator free
Enter your email and the file is yours. You also get the full MT4 and MT5 library.
FAQ
Does InpChannelPeriod include the current bar in the window?
It does. The highest high and lowest low both scan back from the bar under test, and that bar counts. A fresh extreme therefore lands on the rail straight away. For the classic breakout reading, compare each close with the rail value from the previous bar.
What does the Donchian Middle line actually measure?
It measures the midpoint of the channel, nothing more. The code adds the upper rail to the lower rail and halves the result. No moving average sits behind it. The line only shifts when one of the two rails shifts. Long flat stretches are normal on quiet charts.
Why did no alert fire when price touched Donchian Upper?
Two things stop it. InpEnableAlerts ships off, so nothing fires until you switch it on. The test also uses the close of the completed bar rather than the wick. That close must sit at or above the rail. A long upper shadow leaves no message behind.
Can I run the channel shifted forward with InpShift?
Yes. It moves the three drawn lines sideways by the number of bars you enter. The calculation stays untouched. Some traders push the channel forward so today’s rails sit ahead of price as targets. Keep it at zero when you want the rails to match their own bars.
Are results guaranteed?
No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Donchian Channel Indicator as one input. Always backtest before trading live.
Category: this is part of our Volatility collection. Next, plainly, yet, browse more Volatility for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.
External references
- Learn more about the underlying method in Commodity channel index on Wikipedia.
- For wider market background, see Raff Regression Channel at StockCharts ChartSchool.
