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

Williams %R

Install and import#

bash
npm install fintech-algorithms
ts
import { williamsR } from "fintech-algorithms/technical-indicators/momentum/williams-r";

Signature#

williamsR(high, low, close, p)

Where the close sits within the lookback's high–low range, on a −100…0 scale. Arithmetically the inverse of fast %K.

Parameters#

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

Returns#

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

A single parallel series, williams_r, ranging from −100 to 0.

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, 101.992465, 103.28276, 104.655405, 105.856544, 106.661472]

Showing 6 of 120 elements.

low
[99.08, 99.149664, 100.233798, 101.654978, 103.180913, 104.534685]

Showing 6 of 120 elements.

close
[100, 100.999214, 102.324548, 103.755998, 105.030823, 105.911843]

Showing 6 of 120 elements.

Call#

williamsR(high, low, close, p)

Returns#

object with 1 field: williams_r

{
  "williams_r": [null, null, null, null, null, null]
}

Other exports#

This module also exports rsi, stochastic, stochasticRsi, cci, ultimateOscillator, tsi, connorsRsi. 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#

Williams %R — williams r mechanism

Calculation flow#

Calculation flow
flowchart LR
  A["Finalized finalized high, low, close"] --> B["Validate order, alignment, and finite values"]
  B --> C["Trailing range"]
  C --> D["Distance from high"]
  D --> E["Normalize by range"]
  E --> F{"History and denominator valid?"}
  F -- "No · short history" --> G["warming-up + reason"]
  F -- "No · no finite scale" --> H["undefined + reason"]
  F -- "Yes" --> I["Williams %R"]
  I --> J["ready + aligned component trace"]

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#

  • Williams %R (WILLR) — TA-Lib
  • Stochastic Oscillator Slow (STOCH) — TA-Lib
  • TA-Lib Technical Analysis Documentation — TA-Lib
  • Claim-role ledger
  • Evidence boundary

The rest of the Momentum family#