Donchian Channel
The Donchian Channel shows the highest high and the lowest low over a specified number of bars.
Role in the strategy
| Slot | Available | Role |
|---|---|---|
| Entry Point | Yes | Enters at the upper or lower channel level. |
| Entry Rule | Yes | Filters entries by the bar open or proposed entry price relative to the channel. |
| Exit Point | Yes | Exits at the upper or lower channel level. |
| Exit Rule | Yes | Triggers exits by the bar open position relative to the channel. |
As a point indicator the channel levels are the pending order levels; as a rule the indicator filters entries (AND) or triggers exits (OR). See Indicators for the slot semantics.
As an exit point it places a resting order the bar reaches, so it allows no exit rules: Exit Rules are available only behind Bar Open or Bar Close.
Logic rules
- Entry Point: Enter long at Upper Band, Enter long at Lower Band.
- Exit Point: Exit long at Upper Band, Exit long at Lower Band.
- Rule slots:
| Rule | Long order price | Short order price |
|---|---|---|
| Enter/Exit long at Upper Band | Upper Band | Lower Band |
| Enter/Exit long at Lower Band | Lower Band | Upper Band |
- Entry Rule / Exit Rule:
| Rule | Long signal is 1 when | Short signal is 1 when |
|---|---|---|
| The bar opens above Upper Band | bar open is above the upper band | bar open is below the lower band |
| The bar opens below Lower Band | bar open is below the lower band | bar open is above the upper band |
| The bar opens below Upper Band after opening above it | bar open fell back below the upper band | bar open rose back above the lower band |
| The bar opens above Upper Band after opening below it | bar open rose above the upper band | bar open fell below the lower band |
| The bar opens below Lower Band after opening above it | bar open fell below the lower band | bar open rose above the upper band |
| The bar opens above Lower Band after opening below it | bar open rose above the lower band | bar open fell below the upper band |
| The bar closes above Upper Band | bar close is above the upper band | bar close is below the lower band |
| The bar closes below Lower Band | bar close is below the lower band | bar close is above the upper band |
| The bar closes below Upper Band after closing above it | bar close fell back below the upper band | bar close rose back above the lower band |
| The bar closes above Upper Band after closing below it | bar close rose above the upper band | bar close fell below the lower band |
| The bar closes below Lower Band after closing above it | bar close fell below the lower band | bar close rose above the upper band |
| The bar closes above Lower Band after closing below it | bar close rose above the lower band | bar close fell below the upper band |
The six The bar closes rules are exit-only (Exit Rules). A close outside the channel can only be judged against a channel that excludes the bar itself, so these rules read the channel of the bars that produced the close (one bar older than the price) and then honour the slot binding like every other rule: the last completed bar behind a Bar Open exit, the bar being closed behind a Bar Close exit.
Band comparisons for the bar-open family read the previous bar's channel in every slot: a “bar opens …” rule always compares the bar's open with the channel of the last Period completed bars, whatever execution time the entry or exit point has. The rule's meaning is a property of the rule, not of when the strategy trades — the same text behaves identically in the Entry Rule and the Exit Rule slots.
Entry-only rules add The position opens above/below Upper Band and The position opens above/below Lower Band. They compare the proposed Entry Point price with a completed-bars channel: short comparisons reverse the inequality and use the opposite band. The relation is strict, with a half-point dead zone.
Parameters
| Parameter | Type | Default | Range | Purpose |
|---|---|---|---|---|
| Period | number | 10 | 1 to 1000 | Bars over which the high and low are tracked |
Calculation
tech.Donchian in engine/indicator-engine/tech.ts computes the two channel lines:
- Upper Band: highest high of the last Period bars, including the current bar.
- Lower Band: lowest low of the last Period bars, including the current bar.
The lines are drawn as dots on the main price chart; a middle line is computed internally but not displayed. The channel includes the current bar because that is the ported EA Studio calculation, and it is what the plotted lines and the order levels use.
The “bar opens …” rules deliberately do not use that same-bar channel: a rule about the bar's open is compared with the channel of the last Period completed bars, i.e. the channel that existed when the open happened. Otherwise the comparison would be one-sided — the bar's open can never be above the Upper Band or below the Lower Band of a channel that contains that bar's high and low — and the rule would be a silent no-op in any slot whose execution time reads the current bar. This holds for both rule slots, so a Donchian band-open rule in an Exit Rule slot now triggers exits (it previously never could). Strategies saved before this change keep their rules but may exit more often, so their backtest statistics change — re-run them and re-save the baseline. engine/tests/indicator-engine-donchian-rules.test.ts pins both halves of the contract: the rule signals are identical under both slot bindings, and the order levels still follow the execution time. The MQL export mirrors it by building the channel loops from the read shift and clamping the anchor to 1 for these six rules (honoursReadShift plus an emitter-internal anchor), so the EA reads the same completed bars the backtester does — including in the Bar Close exit re-evaluation.
Backtesting
- Rules are evaluated on the bar the exit point names: the previous (closed) bar behind a Bar Open exit (
prev = 1), the bar being closed behind a Bar Close exit (prev = 0). An open-price line reads the current bar in both cases; a The bar closes rule never does behind a Bar Open exit. The Donchian “bar opens …” rules additionally read the channel of the completed bars in both rule slots; the six “bar closes …” rules read the channel one bar older than the price and follow the slot binding. - As an entry point, the pending orders sit at the channel levels; the long and short levels differ, so both orders can be placed and the intrabar interpolation decides which side fills first when both levels are inside the bar.
- Scenario selection follows the entry/exit pairing in the Indicators index.
- As a rule the indicator contributes only long/short signals — it never changes the order price.