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

Stochastic RSI

Install and import#

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

Signature#

stochasticRsi(close, rp, sp, sk, sd)

The stochastic formula applied to RSI rather than to price — a second-order indicator that measures where RSI sits within its own recent range, and therefore moves far faster than either input.

Parameters#

NameTypeNotes
closenumber[]Per-bar closing prices, chronological.
rpnumberRSI period computed first.
min: 1 · integer: true
spnumberStochastic lookback applied over the RSI series.
min: 1 · integer: true
sknumberSmoothing applied to raw %K.
min: 1 · integer: true
sdnumberSmoothing applied to %K to produce %D.
min: 1 · integer: true

Returns#

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

Parallel series: rsi, raw_k, k and d.

Warm-up#

The first rp + sp − 1, plus each smoothing stage positions are null. Warm-ups accumulate across both stages, so this is defined much later than plain RSI.

Errors#

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

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

stochasticRsi(close, rp, sp, sk, sd)

Returns#

object with 4 fields: rsi, raw_k, k, d

{
  "rsi": [null, null, null, null, null, null],
  "raw_k": [null, null, null, null, null, null],
  "k": [null, null, null, null, null, null],
  "d": [null, null, null, null, null, null]
}

Other exports#

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

Stochastic RSI — stochastic rsi mechanism

Calculation flow#

Calculation flow
flowchart LR
  A["Finalized finalized close"] --> B["Validate order, alignment, and finite values"]
  B --> C["Wilder RSI"]
  C --> D["RSI range"]
  D --> E["Raw StochRSI"]
  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["Smoothed %K / %D"]
  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#

  • Stochastic RSI (STOCHRSI) — TA-Lib
  • 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#