mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 12:38:06 +00:00
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: aider (openrouter/anthropic/claude-sonnet-4) <aider@aider.chat> Co-authored-by: Warp <agent@warp.dev>
105 lines
5.9 KiB
Markdown
105 lines
5.9 KiB
Markdown
# DC: Donchian Channels
|
||
|
||
## Overview and Purpose
|
||
|
||
Donchian Channels are a versatile technical analysis tool developed by Richard Donchian in the mid-20th century. This indicator creates a price channel consisting of three lines: an upper band tracking the highest high over a specified period, a lower band tracking the lowest low, and a middle band representing the average of these extremes. Donchian Channels effectively visualize price volatility and potential support/resistance levels by highlighting the range within which prices have fluctuated over the lookback period.
|
||
|
||
## Core Concepts
|
||
|
||
* **Range identification:** Donchian Channels excel at defining dynamic support and resistance levels based on actual price extremes rather than statistical measures
|
||
* **Market application:** Particularly effective for breakout trading strategies, trend identification, and volatility assessment across various market conditions
|
||
* **Timeframe suitability:** **Multiple timeframes** work well, with shorter periods (10-20) for short-term trading signals and longer periods (20-55) for identifying significant support/resistance zones
|
||
|
||
Donchian Channels differ from other volatility-based channels (like Bollinger Bands) by using actual price extremes rather than statistical deviations, making them especially useful for trend-following strategies and breakout systems.
|
||
|
||
## Common Settings and Parameters
|
||
|
||
| Parameter | Default | Function | When to Adjust |
|
||
| --------- | ------- | -------- | -------------- |
|
||
| Period | 20 | Controls the lookback window for calculation | Decrease for more sensitivity to recent price action, increase for more stable channels |
|
||
| High Source | High | Data point used for upper band calculation | Change to different price data only for specific, specialized strategies |
|
||
| Low Source | Low | Data point used for lower band calculation | Change to different price data only for specific, specialized strategies |
|
||
|
||
**Pro Tip:** The "Donchian Channel Breakout" strategy, popularized by the Turtle Traders, traditionally uses a 20-day breakout for entry signals and a 10-day breakout in the opposite direction for exits. This asymmetric application often yields better results than using the same period for both.
|
||
|
||
## Calculation and Mathematical Foundation
|
||
|
||
**Simplified explanation:**
|
||
Donchian Channels track the highest high and lowest low over a specified period. For each bar, the indicator identifies the highest high and lowest low over the lookback period, then calculates a middle line as the average of these two extremes.
|
||
|
||
**Technical formula:**
|
||
Upper Band = Highest High of last n periods
|
||
Lower Band = Lowest Low of last n periods
|
||
Middle Band = (Upper Band + Lower Band) / 2
|
||
|
||
Where:
|
||
* n is the specified lookback period
|
||
* Highest High is the maximum high price observed during the period
|
||
* Lowest Low is the minimum low price observed during the period
|
||
|
||
> 🔍 **Technical Note:** The implementation uses monotonic deques with circular buffers for efficient calculation, maintaining O(1) time complexity for each new bar rather than repeatedly scanning the entire lookback period.
|
||
|
||
## Performance Profile
|
||
|
||
### Operation Count (Streaming Mode, Scalar)
|
||
|
||
Per-bar cost using monotonic deque optimization:
|
||
|
||
| Operation | Count | Cost (cycles) | Subtotal |
|
||
| :--- | :---: | :---: | :---: |
|
||
| CMP | 4 | 1 | 4 |
|
||
| ADD | 1 | 1 | 1 |
|
||
| MUL | 1 | 3 | 3 |
|
||
| **Total** | **6** | — | **~8 cycles** |
|
||
|
||
**Complexity**: O(1) amortized per bar — monotonic deque maintains max/min efficiently.
|
||
|
||
### Batch Mode (SIMD/FMA Analysis)
|
||
|
||
Finding max/min over sliding windows has limited SIMD benefit due to sequential dependency:
|
||
|
||
| Operation | Scalar Ops | SIMD Benefit | Notes |
|
||
| :--- | :---: | :---: | :--- |
|
||
| Max/Min update | 4 | 1× | Deque-based, sequential |
|
||
| Middle band | 2 | 2× | ADD + MUL parallelizable |
|
||
|
||
**Batch efficiency (512 bars):**
|
||
|
||
| Mode | Cycles/bar | Total (512 bars) | Improvement |
|
||
| :--- | :---: | :---: | :---: |
|
||
| Scalar streaming | 8 | 4,096 | — |
|
||
| Partial SIMD | ~7 | ~3,584 | **~12%** |
|
||
|
||
Donchian Channels are already highly efficient due to the O(1) monotonic deque algorithm.
|
||
|
||
### Quality Metrics
|
||
|
||
| Metric | Score | Notes |
|
||
| :--- | :---: | :--- |
|
||
| **Accuracy** | 10/10 | Exact max/min calculation |
|
||
| **Timeliness** | 6/10 | Tracks past extremes, inherently lagging |
|
||
| **Overshoot** | 10/10 | No overshoot—bands are actual price levels |
|
||
| **Smoothness** | 5/10 | Bands move in discrete steps as extremes exit window |
|
||
|
||
## Interpretation Details
|
||
|
||
Donchian Channels provide multiple trading signals and insights:
|
||
|
||
* **Breakout trading:** Price breaking above the upper band signals potential bullish momentum, while breaking below the lower band indicates potential bearish momentum
|
||
* **Range identification:** The width of the channel represents market volatility—wider channels indicate higher volatility
|
||
* **Trend strength:** In strong trends, price tends to "walk" along either the upper or lower band
|
||
* **Mean reversion:** The middle band often acts as a magnet for price, especially after extended moves to the outer bands
|
||
|
||
Traders may also use channel width (difference between upper and lower bands) as a standalone volatility measure to adjust position sizing or identify potential market regime changes.
|
||
|
||
## Limitations and Considerations
|
||
|
||
* **Market conditions:** Less effective during sideways, choppy markets where repeated false breakouts may occur
|
||
* **Lag factor:** By definition, the indicator is backward-looking and may not adapt quickly to sudden market changes
|
||
* **False signals:** Brief price spikes can trigger false breakout signals, especially with shorter lookback periods
|
||
* **Complementary tools:** Best combined with volume analysis, momentum indicators, or other confirmation tools to filter potential false signals
|
||
|
||
## References
|
||
|
||
* Schwager, J. D. (1989). Market Wizards: Interviews with Top Traders. New York: Harper & Row.
|
||
* Faith, C. (2007). The Original Turtle Trading Rules. Original Turtles. |