Donchian trends
Highest and lowest close over the last N bars, drawn as a channel around price.
A Donchian channel: the lowest and highest close over the last window bars, drawn as two lines around price. The window includes the current bar, so price always stays between the two lines. The slope outputs show the percent change of each line over the last slope_window bars.
How to read it
- The two price lines are the channel: the lower is the lowest close of the window, the upper the highest close.
- A line drops or jumps at once when price makes a new extreme, and moves back only when an old extreme leaves the window.
- Price touching the upper line is a new high for the window; touching the lower line is a new low for it.
- Nothing draws for the first window - 1 bars, and the slope pane waits for window + slope_window - 1 bars. On the SPY sample the slope pane stayed between about -0.7% and +0.5%.
What it outputs
- Lower channel (lowest close)
- Lowest close over the last window bars, including the current bar. Falls at once on a new low and steps up when an old low leaves the window.
- Upper channel (highest close)
- Highest close over the last window bars, including the current bar. Jumps up at once on a new high and steps down when an old high leaves the window.
- Lower line slope
- Percent change of the lower line over the last slope_window bars. Above 0 the floor is rising, below 0 it is falling.
- Upper line slope
- Percent change of the upper line over the last slope_window bars. Above 0 the ceiling is rising, below 0 it is falling.
Settings
- window
- How many bars the channel looks back over. Lowering it tightens the channel so the lines move with every swing; raising it widens the channel and moves the lines only at major extremes.
- slope_window
- How many bars each slope line looks back over. Only the slope pane changes, not the channel. Lowering it reacts within minutes but is noisy; raising it smooths the slope and it stays flat for longer.
Pitfalls
- It uses closes, not lows and highs. The source docstring says lowest low and highest high, but the code takes the min and max of close, so wicks never set the lines.
- The slope lines are percent change over slope_window bars, not per bar as the module header says. Their median is exactly 0 on the SPY sample, so they often lie flat.
- The window includes the current bar, so price cannot leave the channel. A touch marks a new N-bar extreme, not a confirmed support or resistance level.