דלגו לתוכן
פתיחת RaamTrade

DonchianHigh — Donchian High

תוכן זה אינו זמין עדיין בשפה שלך.

The highest close of the last N bars — the upper rail of a close-based Donchian channel, and the classic breakout level.

DonchianHigh is the identifier a strategy writes; Donchian High is the label the chart’s indicator picker shows. Single value — .value is the only accessor.

Signature

DonchianHigh(period, on=<source>)
Argument Type Required Notes
period int Param or literal Yes Lookback window. Default 20, bounds 2–200.
on= symbol, OHLCV field, or indicator No Source. Defaults to the trade symbol’s close.

Formula

$$ \text{DonchianHigh}t = \max(\text{close}{t-N+1}, \dots, \text{close}_t) $$

Note the window includes the current bar. self.trade.close >= high.value is therefore true exactly on the bar that sets a new N-bar closing high — it can never be “above” the line. To test a break of the level as it stood before this bar, read high.value_at(1).

Warmup

period bars — that is when the buffer is full and execute() starts.

The value itself has no dead zone: both branches of the seeded source return max(buffer), so from the very first bar the chart plots the maximum of however many closes have arrived. That is a real high over a short window, not a placeholder — but it can only rise as the window fills, which makes the leading edge of the plot look artificially flat.

Reading the value

high.value # highest close including this bar
high.value_at(1) # the level as it stood before this bar — the breakout test
high > 100

Example

class DonchianBreakout(Strategy):
"""Buy a new N-bar closing high, exit on the shorter channel's low."""
period = Param(20, min=2, max=200)
exit_period = Param(10, min=2, max=200)
trade = Symbol()
sizing = FixedCapital()
def execute(self):
upper = DonchianHigh(self.period, on=self.trade)
lower = DonchianLow(self.exit_period, on=self.trade)
self.stop_loss(3.0)
breakout_level = upper.value_at(1)
channel_stop = lower.value_at(1)
if self.trade.close > breakout_level and self.trade.is_flat:
self.buy(self.trade, reason=f"Breakout above {breakout_level:.2f}")
if self.trade.close < channel_stop and self.trade.is_long:
self.sell(self.trade, self.trade.position, reason="Lost the lower channel")

Notes

  • Use value_at(1) for breakout tests. Comparing against .value compares the close to a window that already contains it, which turns every new high into a trivially true condition and can never be false in the interesting direction.
  • Close-based, not high-based. An intraday spike that closes back inside the range does not move this level — that is usually what you want for a signal, and usually not what you want for a stop.
  • Pair with DonchianLow for the exit rail and DonchianMid for the midpoint; PriceChannelWidth is high − low of the same window.
  • A longer entry channel with a shorter exit channel is the classic turtle shape — two instances, two periods, as in the example above.