Donchian Channel
The Donchian channel is the highest high and the lowest low of the last N bars, drawn as two lines. MetaTrader 5 does not ship it, and unlike most missing indicators it does not need to be written — the values are already on the chart. The Builder creates no indicator handle at all and reads the extremes directly, which is why this page is about a window rather than a formula.
- Entry window
- 20
- Exit window
- 10
- Handles created
- 0
توضيحي — بيانات اصطناعية، ليست تسعيرة مباشرة.
What the Donchian channel tells you
Take the last twenty bars, find the highest high among them and the lowest low, and draw both. That is the entire indicator. There is no average, no smoothing constant and no weighting — which means there is also nothing to disagree about: two Donchian channels with the same period are the same channel. The upper line holds perfectly flat until a higher high enters the window or the old high drops out of it, then steps. Because the lines sit still, price clearing one of them is unambiguous in a way that crossing a moving average never is.
- The output is a price, not a reading — it lives on the chart's own scale
- The lines step rather than slope; a flat stretch is the normal state
- The distance between them is the recent range, and it narrows before it breaks
- 1 Upper = the highest high of the last N bars
- 2 Lower = the lowest low of the last N bars
- 3 The forming bar is left out, so price can actually clear the line
عرض الصيغة وتفاصيل الحساب
A Donchian channel is two lines and no arithmetic:
- Upper = the highest high of the last N bars
- Lower = the lowest low of the last N bars
- The window ends one bar back, so the bar still forming is not in it
There is no third step. No average is taken, nothing is smoothed, and no constant is chosen — which is why, alone among the indicators on this site, two correct implementations cannot disagree. A 20-period Donchian channel is a 20-period Donchian channel.
MetaTrader 5 does not ship it, and it does not need to. There is no iDonchian in MQL5. But where a missing indicator normally has to be reimplemented — and the implementations then differ, as they do for Supertrend — this one is already on the chart. iHighest and iLowest are timeseries functions: they search the bars for the index of an extreme. The generated EA calls them directly:
iHigh(symbol, timeframe, iHighest(symbol, timeframe, MODE_HIGH, 20, 1))
No indicator handle is created at all. The node sits in the codegen’s no-handle list next to Price and OHLC. That is why the buffer table above is empty rather than short, and it removes an entire class of problem in one stroke: nothing to warm up, no handle that can come back invalid, no CopyBuffer that can return fewer bars than asked for.
Two things follow for anyone building with it.
The default shift of 1 is load-bearing. The window ends that many bars back. Set it to 0 and the forming bar joins the window, so the upper line is at least as high as the current bar’s own high — and price cannot exceed its own bar high. The crossover the rule waits for becomes impossible. Nothing errors; the EA compiles, runs, and quietly never trades.
A position filter would disable the exit. The Builder’s maximum-positions filter compiles to an early return at the top of OnTick, before the close conditions are reached. On a template whose exit is a condition — leave on the opposite ten-bar channel — that filter would mean the position never leaves except on its stop or target. The template therefore omits it, and relies instead on the per-direction guard the codegen emits with every entry, which caps it at one long and one short.
The two windows are deliberately different lengths. Twenty bars of evidence are required to commit; ten are enough to give up. That asymmetry is the strategy — not a pair of numbers that happened to test well.
الإشارات
الإشارات المتميزة والقابلة للاختبار التي يوفرها Donchian — والنظام الملائم لكل منها.
Opposite-Channel Exit
جاهز في المنشئPosition Inside the Channel
جاهز في المنشئChannel Squeeze
منطق متقدمتنفيذ MT5
ما يحسبه ويرسمه ميتاتريدر 5 فعليًا — وهو المرجع الذي كُتبت وفقه كل قاعدة في هذه الصفحة.
ملاحظات المنصة
يعمل بشكل أفضل / استخدم بحذر
لا يوجد مؤشر ذو ميزة شاملة. إليك أين يساعد Donchian — وأين يضلل.
يعمل بشكل أفضل
- Markets that make sustained directional moves, where one break covers many bars
- Higher timeframes, where a twenty-bar extreme is a meaningful level rather than an hour of noise
- As an exit rule, where the flat lines make a give-back limit that adapts to the recent range
- Anywhere a level needs to be objective — there is no parameter beyond the count of bars
استخدم بحذر
- Ranges, where price clears a twenty-bar high only to re-enter the range on the next bar
- Very short windows, where the channel tracks price so closely that everything is a break
- Assuming the upper line is resistance — it is a record of the past, not a barrier
- Reading it on an illiquid instrument, where one bad tick sets the extreme for the next N bars
بناء استراتيجية Donchian
اربط الإشارة بقواعد الدخول والخروج، ثم صدّر EA MT5 قابلاً للترجمة — بدون كود.
- Four channel nodes — two at 20 bars for entry, two at 10 for the way out
- One price node, crossed against each of them
- Price clears the 20-bar high → Open Buy · SL 80 / TP 240
- Price breaks the 20-bar low → Open Sell
- Price falls back through the 10-bar low → Close the long
- Price rises back through the 10-bar high → Close the short
دمج Donchian مع مؤشرات أخرى
نادراً ما يقف مؤشر واحد وحده. هذه التوليفات تغطي النقاط العمياء لـ Donchian.
Donchian + Bollinger Bands
- Price above the upper deviation edge
- Price clears the 20-bar high
- Buy
No single-flow template combines them. Start from Donchian 20-Bar Break, add a Bollinger node set to the upper output and a Price node into a Compare, then join that to the existing Cross with an And gate.
افتح المنشئ →Donchian + ADX
- ADX above 25
- Price clears the 20-bar high
- Buy
No single-flow template pairs them. Add an ADX node with a Compare at 25 to Donchian 20-Bar Break and join it to the Cross with an And gate — the same filter the Parabolic SAR template already uses.
افتح المنشئ →Donchian + ATR
- ATR expanding
- Price clears the 20-bar high
- Buy
No single-flow template pairs them. Add two ATR nodes at different shifts with a Compare between them to require the range to be expanding, then join that to the Cross with an And gate.
افتح المنشئ →Donchian + Opening Range Breakout
- Opening range signal above zero
- Price clears the 20-bar high
- Buy
No single-flow template combines them. Add an Opening Range Breakout node with a Compare against 0 to Donchian 20-Bar Break and join it to the Cross with an And gate — note that node pins its own timeframe, so set it deliberately.
افتح المنشئ →المعاملات
قيم أولية للتحقق على زوجك الخاص وإطارك الزمني — ليست إعدادات مضمونة.
| المعامل | الافتراضي | نطاق الاختبار المقترح | ما يفعله |
|---|---|---|---|
| Period | 20 | 1–999 | How many bars the window covers. This is the only setting that changes what the indicator is: at 5 the channel is glued to price and nearly every bar is a break, at 100 it marks levels that hold for months. The template uses 20 for entries and 10 for exits, and the asymmetry is the point rather than an oversight. |
| Band | Upper | Upper / Lower | Which side to read. It is a property of one node rather than two separate nodes, so a flow that needs both edges uses two nodes with this set differently — which is exactly what the template does, twice. |
| Shift | 1 | 0–100 | How many bars back the window ends. Leave it at 1. The default is load-bearing: it excludes the bar still forming, and that exclusion is what makes a break detectable at all. See the caveat below — at 0 the rule cannot fire. |
| Timeframe | Current | Current / M1–MN1 | Which timeframe's bars the extremes come from. Set to something higher than the chart and the channel becomes a slower structure the entry timing sits inside, which is the usual way to use it as a filter rather than a trigger. |
الإعدادات المسبقة الأولية
أمثلة السوق
أين يعمل Donchian، وأين يفشل، وكيف يغير الفلتر النتيجة.
A break that kept going
After ten bars of a flat upper line, price closes through it and the line steps up on each of the next several bars. The ten-bar low trails well behind and is never touched until the move has run its course.
The break that went straight back
Price clears a twenty-bar high on one wide bar in an otherwise sideways week, then closes back inside the range. The ten-bar low is hit three bars later for a small loss — the failure mode the trend filter above exists for.
Squeeze, then break
The two lines converge to their narrowest gap in weeks before the break happens. The width panel shows the contraction; the channel itself only shows the break, which is why the width is worth watching separately.
FAQ
- Is the Donchian channel built into MetaTrader 5?
- No. There is no iDonchian function in MQL5 and no Donchian entry in the Navigator. It differs from other missing indicators in that nothing has to be invented: the highest high and lowest low of the last N bars are already in the chart data, and MQL5's iHighest / iLowest find them. The Builder therefore creates no indicator handle at all — the generated EA reads the bars directly.
- What does the node return?
- A price — the extreme itself, on the chart's own scale. That makes it directly comparable against a Price node, which is how a break is detected. Which side you get is a property on the node rather than a separate node type, so a flow that needs both edges uses two nodes.
- Why is the shift set to 1, and can I change it?
- Leave it. The window ends that many bars back, so 1 excludes the bar currently forming. At 0 that bar joins the window and its own high becomes part of the upper line — price cannot exceed its own bar high, so the break can never trigger. The EA still compiles and runs; it just never trades, which is a much harder thing to notice than an error.
- Why does the template enter on 20 bars but leave on 10?
- So that leaving is easier than entering. A twenty-bar extreme is required to commit, but only a ten-bar move against the position is needed to give up, which keeps a position through ordinary pullbacks while still ending it once the move has clearly turned. Making both windows the same length would mean the exit needs as much evidence as the entry did, and positions would be held far longer than the move that justified them.
- Why is there no maximum-positions filter on the template?
- Because it would silently disable the exit. In the generated code that filter becomes an early return at the very top of OnTick, so once a position is open the EA returns before it ever evaluates the close conditions — and the channel exit, the whole point of the template, would never run. Exposure is still bounded: the code emits its own per-direction guard, so there is at most one long and one short at a time.
- Can I build a Donchian breakout EA without coding?
- Yes. The Donchian 20-Bar Break template uses four channel nodes and one price node: crossing the twenty-bar high opens a long, crossing the twenty-bar low opens a short, and the ten-bar channel on the opposite side closes each of them. The windows, the shift, the stop distances, the lot and the spread limit are all EA inputs.
- How should I validate settings before going live?
- Backtest on quality tick data, then demo. Two cautions are specific to this indicator. Because the channel is made of extremes rather than averages, poor history hurts it more than most — a single bad print sets a level that stands for the whole window, so check the data quality before concluding a period is wrong. And because the period is the only real parameter, it is unusually easy to scan every value and keep the best one; that number will not survive out of sample. Choose the window from how long the moves you are trying to hold actually last.
مقالات ذات صلة
Glossary