fintech-algorithms

Donchian Channels

Install and import

bash
npm install fintech-algorithms
ts
import { donchian_channels } from "fintech-algorithms/technical-indicators/volatility-and-channels/donchian-channels";

Signature

donchian_channels(high, low, p)

The highest high and lowest low of the lookback. The oldest channel in use, and the only one here with no smoothing at all — the bands step rather than glide.

Parameters

NameTypeNotes
highnumber[]Per-bar high prices, chronological.
lownumber[]Per-bar low prices, chronological.
pnumberLookback in bars for both extremes.
min: 1 · integer: true

Returns

Record<string, (number | null)[]> · length same-as-input

Parallel series: upper, lower, middle and width.

Warm-up

The first p − 1 positions are null.

Errors

  • When p < 1 or is not an integer — throws RangeError
  • When the input series are not all the same length — throws RangeError

Complexity: time O(n × p), space O(n).

Worked example

executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.

Input

high
[101.08, 101.6243955, 102.13058177, 102.56507653, 102.90321818, 103.1320792]

Showing 6 of 240 elements.

low
[98.92, 99.39457765, 99.83203556, 100.19996391, 100.47473988, 100.64442473]

Showing 6 of 240 elements.

p
20

Call

donchian_channels(high, low, p)

Returns

object with 4 fields: upper, lower, middle, width

{
  "upper": [null, null, null, null, null, null],
  "lower": [null, null, null, null, null, null],
  "middle": [null, null, null, null, null, null],
  "width": [null, null, null, null, null, null]
}

Diagrams

Donchian Channels — canonical trace
Donchian Channels — failure boundary
Donchian Channels — mechanism map
Donchian Channels — memory comparison

How it works

This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.

Read the article →

References

  • Donchian Channels (DC) — TradingView
  • A Century of Profitable Trends — CMT Association
  • Public evidence boundary