Skip to content
All library documents

Donchian Channel Breakouts with a 200-Period Trend Filter

Article Strategy library · Author: Jesse community

Summary

This simple long-only trend-following method uses Donchian Channels to enter on a close above the upper band and to liquidate on a close below the lower band. It calculates the channels from prior candles, excluding the current candle, and requires price to be above a 200-period simple moving average before opening a position. It does not open short positions.

The source sizes an entry using the available balance after accounting for fees. The wide channel exit is intended to keep a position through an uptrend, but can also give back gains before closing; no separate stop, profit target, or performance evidence is provided. The description states the goal of capturing long-term uptrends, while the code specifies the trend filter and entry and exit rules. Results would depend on channel defaults, market, timeframe, and execution assumptions.

Key ideas

  • A close above the prior upper Donchian band triggers a potential long entry.
  • The close must also be above the 200-period simple moving average.
  • The strategy exits when price closes below the prior lower Donchian band and does not short.
  • The source specifies balance-based position sizing but provides no backtest results or separate risk exit.

Tags

Full text
# Donchian


# Donchian









Simple Donchian Strategy
Repo: https://github.com/gabrielweich/jesse-strategies
Uses Donchian Channels to capture long term uptrends, the idea is to buy
when price closes above the upperband and only exit the position when
prices closes below the lowerband.

## Source (MIT)

```python
"""
Simple Donchian Strategy
Repo: https://github.com/gabrielweich/jesse-strategies
Uses Donchian Channels to capture long term uptrends, the idea is to buy
when price closes above the upperband and only exit the position when
prices closes below the lowerband.
"""

from jesse.strategies import Strategy
import jesse.indicators as ta
from jesse import utils


class Donchian(Strategy):
    @property
    def donchian(self):
        # Previous Donchian Channels with default parameters
        return ta.donchian(self.candles[:-1])

    @property
    def ma_trend(self):
        return ta.sma(self.candles, period=200)

    def filter_trend(self):
        # Only opens a long position when close is above 200 SMA
        return self.close > self.ma_trend

    def filters(self):
        return [self.filter_trend]

    def should_long(self) -> bool:
        # Go long if candle closes above upperband
        return self.close > self.donchian.upperband

    def should_short(self) -> bool:
        return False

    def should_cancel_entry(self) -> bool:
        return True

    def go_long(self):
        # Open long position using entire balance
        qty = utils.size_to_qty(self.balance, self.price, fee_rate=self.fee_rate)
        self.buy = qty, self.price

    def go_short(self):
        pass

    def update_position(self):
        # Close the position when candle closes below lowerband
        if self.close < self.donchian.lowerband:
            self.liquidate()

```

Shown in full with attribution under the source's licence. Licence: MIT

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.