Personalizados e da comunidade BreakoutTrendNot MT5 Built-in Disponível no Builder

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
Donchian (20) — highest high / lowest low, forming bar excludedNever negative — the floor is a flat range, not a zero lineChannel width (upper − lower)

Ilustrativo — dados sintéticos, não uma cotação em tempo real.

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. 1 Upper = the highest high of the last N bars
  2. 2 Lower = the lowest low of the last N bars
  3. 3 The forming bar is left out, so price can actually clear the line
Mostrar a fórmula e detalhes de cálculo

A Donchian channel is two lines and no arithmetic:

  1. Upper = the highest high of the last N bars
  2. Lower = the lowest low of the last N bars
  3. 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.

Sinais

Os sinais distintos e testáveis que Donchian oferece — e o regime adequado para cada um.

N-Bar Break

Pronto no Builder
Condição
Price clears the upper line, or breaks the lower one
Melhor regime
Trending
Uso típico
The template's entry — a twenty-bar high is a twenty-bar high

Opposite-Channel Exit

Pronto no Builder
Condição
Price crosses back through a shorter channel on the other side
Melhor regime
Trending
Uso típico
The template's exit — leaves on a ten-bar low rather than a fixed distance

Position Inside the Channel

Pronto no Builder
Condição
Price sits in the upper or lower part of the range
Melhor regime
Either regime
Uso típico
A direction bias for some other entry rule

Channel Squeeze

Lógica avançada
Condição
The gap between the two lines contracts to a multi-week low
Melhor regime
Range
Uso típico
A discretionary setup — the width has to be compared against its own history across bars

Implementação no MT5

O que o MetaTrader 5 realmente calcula e desenha — a referência para cada regra desta página.

Notas da plataforma

Funciona melhor / use com cuidado

Nenhum indicador tem vantagem universal. Veja onde Donchian ajuda — e onde ele engana.

Funciona melhor

  • 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

Use com cuidado

  • 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

Criar uma estratégia Donchian

Conecte o sinal às regras de entrada e saída, depois exporte um EA MT5 compilável — sem código.

  1. Four channel nodes — two at 20 bars for entry, two at 10 for the way out
  2. One price node, crossed against each of them
  3. Price clears the 20-bar high → Open Buy · SL 80 / TP 240
  4. Price breaks the 20-bar low → Open Sell
  5. Price falls back through the 10-bar low → Close the long
  6. Price rises back through the 10-bar high → Close the short

Combinar Donchian com outros indicadores

Um indicador raramente funciona sozinho. Essas combinações cobrem os pontos cegos do Donchian.

Donchian + Bollinger Bands

  1. Price above the upper deviation edge
  2. Price clears the 20-bar high
  3. Buy
Por quê
The other channel on this site, and the pairing is instructive rather than additive. Bollinger's edges are a mean plus and minus a multiple of deviation, so they move every bar and widen as volatility rises; Donchian's are the extremes themselves, so they hold flat and step. A break of both at once is price leaving a statistical envelope and setting a new N-bar record in the same move, which is a stricter statement than either alone
Melhor regime
Trending

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.

Abrir o Builder →

Donchian + ADX

  1. ADX above 25
  2. Price clears the 20-bar high
  3. Buy
Por quê
A channel break says a new extreme was reached; it says nothing about whether anything is trending. That is precisely the gap a trend-strength reading fills, and it is the direct answer to this indicator's known failure mode — the break that happens inside a range and re-enters it on the next bar
Melhor regime
Trending

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.

Abrir o Builder →

Donchian + ATR

  1. ATR expanding
  2. Price clears the 20-bar high
  3. Buy
Por quê
The channel's width and the true range measure the same market from two directions: one is how far price actually travelled over N bars, the other how far a single bar typically moves. Reading them together separates a narrow channel that is quiet from a narrow channel that is coiled, and it gives the stop a size drawn from the same market the entry came from
Melhor regime
Either regime

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.

Abrir o Builder →

Donchian + Opening Range Breakout

  1. Opening range signal above zero
  2. Price clears the 20-bar high
  3. Buy
Por quê
Two breakout setups that disagree about where a level comes from. This channel is anchored to the last N bars and re-steps whenever the window rolls, so its edges are always the most recent extremes; the opening range is anchored to a clock and stops moving entirely once frozen. That makes them a genuine cross-check rather than two copies of the same idea: a break that clears both is price setting an N-bar record and leaving today's range in the same move. It also throws the difference in trade frequency into relief, because the time-anchored version fires at most once a day
Melhor regime
Trending

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.

Abrir o Builder →

Parâmetros

Valores iniciais para validar no seu próprio par e timeframe — não são configurações garantidas.

Parâmetro Padrão Faixa de teste sugerida O que faz
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.

Predefinições iniciais

Classic 20 / 10 The published Turtle pair, and the template's setting
Slower 55 / 20 The Turtles' longer system — far fewer breaks, each one bigger
Faster 10 / 5 Trades intraday structure; expect many more breaks that fail

Exemplos de mercado

Onde Donchian funciona, onde falha e como um filtro muda o resultado.

Funciona

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.

Falha

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.

Filtrado

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

Termos-chave