fintech-algorithms
Using a coding agent? Give it the skill: npx skills add IslamBaraka90/Fintech-Algorithms-Library What it does →

Traditional McClellan Oscillator

Compare Fast and Slow Raw Breadth

Install and import#

bash
npm install fintech-algorithms
ts
import { calculateMcClellanValues } from "fintech-algorithms/market-breadth-and-internals/mcclellan-family/traditional-mcclellan-oscillator";

Signature#

calculateMcClellanValues(netAdvances)

The difference between a 19-day and a 39-day EMA of net advances. Because both averages are taken over raw counts, values are not comparable across eras in which the number of listed issues changed — which is exactly what the ratio-adjusted variant fixes.

Parameters#

NameTypeNotes
netAdvancesnumber[]Net advances per session, chronological.

Returns#

{ ema19, ema39, oscillator }

Both EMAs alongside the oscillator, so a reading can be traced to its components.

Errors#

  • When fewer sessions are supplied than the longer EMA needs — returns nulls during warm-up rather than throwing

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

Worked example#

verified This is the worked example published in the article, replayed by the test suite on every run. The output cannot drift.

Input#

netAdvances
[0, 0, 0, 0, 0, 0]

Showing 6 of 44 elements.

Call#

calculateMcClellanValues(netAdvances)

Returns#

object with 6 fields: 38, 39, 40, 41, 42, 43

{
  "38": {
    "observation": 39,
    "fast_ema": 0,
    "slow_ema": 0,
    "oscillator": 0,
    "status": "ready"
  },
  "39": {
    "observation": 40,
    "fast_ema": 10,
    "slow_ema": 5,
    "oscillator": 5,
    "status": "ready"
  },
  "40": {
    "observation": 41,
    "fast_ema": 19,
    "slow_ema": 9.75,
    "oscillator": 9.25,
    "status": "ready"
  },
  "41": {
    "observation": 42,
    "fast_ema": 7.1,
    "slow_ema": 4.2625,
    "oscillator": 2.8375,
    "status": "ready"
  },
  "42": {
    "observation": 43,
    "fast_ema": 6.39,
    "slow_ema": 4.049375,
    "oscillator": 2.340625,
    "status": "ready"
  },
  "43": {
    "observation": 44,
    "fast_ema": -4.249,
    "slow_ema": -1.15309375,
    "oscillator": -3.09590625,
    "status": "ready"
  }
}

Other exports#

This module also exports calculateMcClellan. Every module additionally exports run as an alias of its primary function, and a meta object carrying its catalog id, domain, family, shape and article URL.

Diagrams#

Traditional McClellan Oscillator — ema update
Traditional McClellan Oscillator — worked path

Calculation flow#

Traditional McClellan Oscillator calculation flow
flowchart LR
    A["Source revisions"] --> B["Keep available-at or before cutoff"]
    B --> C["Resolve one head per expected session"]
    C --> D{"All evidence ready, complete, and coherent?"}
    D -- "No" --> E["Emit non-resolved result with no points"]
    D -- "Yes" --> F["Net Advances = A - D"]
    F --> G["Seed or update fast 10% trend"]
    F --> H["Seed or update slow 5% trend"]
    G --> I{"Both states ready?"}
    H --> I
    I -- "No" --> J["Emit resolved warm-up point"]
    I -- "Yes" --> K["Oscillator = fast - slow"]
    K --> L["Emit point with revision and diagnostics"]

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#

  • Calculating the McClellan Oscillator — McClellan Financial Publications; explanation by Tom McClellan
  • The McClellan Oscillator and Summation Index — McClellan Financial Publications
  • 2004 MTA Lifetime Achievement Award booklet — Sherman and Marian McClellan / McClellan Financial Publications
  • StockCharts ChartSchool methodology — StockCharts.com
  • Schwab thinkorswim McClellanOscillator — Charles Schwab / thinkorswim
  • Nasdaq A-D definition — Nasdaq, Inc.
  • Nasdaq Trader Daily Market Files — Nasdaq, Inc.
  • Daily Market Summary Data Fields and Definitions — Nasdaq, Inc.
  • Evidence and design reconciliation

The rest of the McClellan Family family#