fintech-algorithms

Wilder RMA

SMA-Seeded Alpha 1/n Smoothing

Install and import

bash
npm install fintech-algorithms
ts
import { calculateRma } from "fintech-algorithms/technical-indicators/trend-smoothing/wilder-rma";

Signature

calculateRma(values, period)

Wilder's smoothing — an exponential mean with decay 1 / period rather than 2 / (period + 1). This is the smoother RSI, ATR and ADX are defined against, and substituting a standard EMA changes their published values.

Parameters

NameTypeNotes
values(number | null)[]Observation series in chronological order, oldest first.
nulls: propagate
periodnumberWilder period; the decay factor is 1 / period.
min: 1 · integer: true

Returns

(number | null)[] · length same-as-input

Smoothed series, null until the seed window closes.

Warm-up

The first period - 1 positions are null. Warm-up positions are null rather than a partial result, so a consumer never mistakes an incomplete window for a real value.

Errors

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

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

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

values
[10, 13, 12, 15, 14, 18]
period
3

Call

calculateRma(values, period)

Returns

array of 6 nulls

[
  null,
  null,
  11.666666666666666,
  12.777777777777777,
  13.185185185185185,
  14.790123456790123
]

Diagrams

Wilder RMA — nasdaq composite rma example
Wilder RMA — rma step
Wilder RMA — rma vs ema

Calculation flow

Wilder RMA calculation flow
flowchart LR
    A["Validate ordered finite value"] --> B{"Count below period?"}
    B -- "Yes" --> C["Add to seed sum"]
    C --> D["Emit null: warming"]
    B -- "No" --> E{"Count equals period?"}
    E -- "Yes" --> F["Seed = sum / period"]
    E -- "No" --> G["RMA = prior + (value - prior) / period"]
    F --> H["Emit full-precision RMA"]
    G --> H
    H --> I["Persist state and provenance"]

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
  • TA-Lib classic RSI implementation — TA-Lib project; initial implementation credited to Mario Fortier
  • TC2000 RSI and Wilder's RSI methodology — TC2000 Software Company
  • TC2000 Average True Range methodology — TC2000 Software Company
  • TradingView Pine Script RMA reference — TradingView
  • Nasdaq Trader Daily Market Files — Nasdaq, Inc.; Nasdaq Trader
  • Evidence and design reconciliation