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

Relative Strength Index (RSI)

Install and import#

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

Signature#

rsi(close, p)

Relative strength index: Wilder-smoothed average gain over average loss, mapped to 0–100. In a strong trend a high reading means strength persisting, not exhaustion — which is the most common misreading of this indicator.

Parameters#

NameTypeNotes
closenumber[]Per-bar closing prices, chronological.
pnumberWilder smoothing period. 14 is the conventional default.
min: 1 · integer: true

Returns#

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

A single parallel series, rsi.

Warm-up#

The first p positions are null. Wilder smoothing seeds on the first full window of gains and losses.

Errors#

  • When p < 1 or is not an integer — throws RangeError

Complexity: time O(n), 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#

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

Showing 6 of 120 elements.

Call#

rsi(close, p)

Returns#

object with 1 field: rsi

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

Other exports#

This module also exports stochastic, stochasticRsi, williamsR, 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#

Relative Strength Index (RSI) — rsi mechanism

Calculation flow#

Calculation flow
flowchart LR
  A["Finalized finalized close"] --> B["Validate order, alignment, and finite values"]
  B --> C["Close change"]
  C --> D["Gain / loss split"]
  D --> E["Wilder smoothing"]
  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["RSI ratio"]
  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#

  • New Concepts in Technical Trading Systems — J. Welles Wilder / Windsor Books
  • TA-Lib Technical Analysis Documentation — TA-Lib
  • Claim-role ledger
  • Evidence boundary

The rest of the Momentum family#