MCPcopy Index your code
hub / github.com/debut-js/Indicators

github.com/debut-js/Indicators @v2.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.1 ↗ · + Follow
1,004 symbols 2,219 edges 220 files 98 documented · 10% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

npm npm NPM

Streaming Technical Indicators

Sponsored by Backticks — a visual canvas to build, backtest and optimize trading strategies in your browser. Built on top of this library.

A streaming, allocation-light technical-analysis toolkit for JavaScript / TypeScript. Every indicator is a class with a nextValue(...) method that consumes one bar at a time, so the same code path drives both backtests and live trading without rebuilding state. A second method, momentValue(...), computes the indicator's value for a hypothetical bar without committing any state — useful for tick-by-tick recalculation inside an unfinished candle.

Features

  • Streaming-first. O(period) per bar; no full-array recomputation.
  • momentValue everywhere. Ask "what would the value be if this bar closed now?" without mutating state.
  • TypeScript. Strongly-typed across the public surface.
  • Cross-SDK validated. 130+ jest tests cross-check our output against external reference libraries (lwc and ti) with epsilon ≤ 1e-9. See the Test column in the indicator tables below for which oracle each one is verified against.
  • Tiny package. Ships only the prebuilt lib/ bundle — ~85 kB tarball.

Install

npm install @debut/indicators

Quick start

import { SMA, RSI, MACD, BollingerBands } from '@debut/indicators';

const sma = new SMA(20);
const rsi = new RSI(14);
const macd = new MACD(12, 26, 9);
const bb = new BollingerBands(20, 2);

for (const bar of bars) {
    const sm = sma.nextValue(bar.close);
    const r = rsi.nextValue(bar.close);
    const m = macd.nextValue(bar.close);   // → { macd, signal, histogram }
    const b = bb.nextValue(bar.close);     // → { lower, middle, upper }
    // ...indicator outputs are `undefined` until each one's warmup completes.
}

nextValue returns undefined until the indicator has seen enough bars to produce a result (its "warmup" — typically period bars). After that it returns the current value on every call.

Streaming model

nextValue(...) — close-of-bar

Call this once per closed bar. The method advances internal state and returns the new indicator value. Subsequent calls reflect the committed state.

momentValue(...) — intra-bar

Call this with the live (still-forming) candle's price/volume to read what the indicator would report if the bar closed now, without committing any state. Useful when you want to react inside the candle but recompute cleanly when the next real nextValue arrives.

const sma = new SMA(4);
[1, 2, 3].forEach((v) => sma.nextValue(v));   // warmup
sma.momentValue(8);   // 3.5  ← preview if close=8
sma.nextValue(4);     // 2.5  ← actual close=4 commits state
sma.momentValue(8);   // 4.75 ← preview based on committed state
sma.nextValue(8);     // 4.25 ← actual close=8 commits state

Available indicators

Below is the full catalog grouped by category. Names in code style are the exact named export from @debut/indicators. Linkable indicator names lead to a per-indicator doc page in docs/. The Test column marks which external library the cross-SDK validation runs against — `lwc` = lightweight-charts-indicators, `ti` = technicalindicators (see Cross-SDK validation for what that means).

Moving Averages

Indicator Export Test Description
Simple Moving Average SMA ti Arithmetic mean over a period.
Exponential Moving Average EMA ti Weighted average emphasizing recent prices.
Weighted Moving Average WMA ti Linearly increasing weights toward the latest bar.
Linearly Weighted MA LWMA Linear weighting variant.
Exponential Weighted MA EWMA Configurable α; lighter than EMA for tick smoothing.
Smoothed Moving Average SMMA Wilder smoothing (α = 1/period).
Wilder's Smoothed MA WEMA ti Same shape as RMA, included for compatibility.
Welles Wilder's Smoothing WWS Classic Wilder smoothing.
Adaptive Moving Average AMA Kaufman adaptive — speeds up in trend, slows in chop.
Running Moving Average RMA α = 1/period; SMA-seeded.
Hull Moving Average HMA lwc Reduced-lag MA via WMA chaining.
Double EMA DEMA lwc 2 × EMA − EMA(EMA).
Triple EMA TEMA Three-stage EMA reduction of lag.
Arnaud Legoux MA ALMA lwc Gaussian-weighted MA.
Volume Weighted MA VWMA lwc Each bar weighted by volume.
McGinley Dynamic McGinleyDynamic lwc Self-adjusting MA reacting to market speed.
Least Squares MA LSMA lwc Endpoint of rolling linear regression.

Oscillators

Indicator Export Test Description
Relative Strength Index RSI ti Classic 14-period momentum oscillator.
Stochastic Stochastic ti Close vs. high-low range.
Stochastic RSI StochasticRSI ti Stochastic applied to RSI.
Commodity Channel Index CCI ti Deviation-from-mean cyclic oscillator.
Williams %R Williams Inverse-stochastic momentum.
Awesome Oscillator AO ti Bill Williams 5/34 SMA difference of HL2.
Accelerator Oscillator AC Bill Williams AO derivative.
Chande Momentum Oscillator CMO Wilder-style CMO.
Chande MO (LWC) ChandeMO lwc LWC reference variant; raw rolling sums.
Detrended Price Oscillator DPO SMA-detrended price.
Relative Vigor Index RVI lwc SWMA-based vigor / signal pair.
SMI Ergodic SMIErgodic lwc Double-smoothed momentum (TSI without 100×).
True Strength Index TSI lwc Double-EMA momentum oscillator with signal.
Bollinger Bands %B BBPercentB lwc Price position relative to BB.
Fisher Transform FisherTransform lwc Gaussian-mapped price extremes.
Ultimate Oscillator UltimateOscillator Multi-timeframe weighted momentum.
Connor's RSI cRSI Composite RSI / streak / percent-rank.
Relative Volatility Index RelativeVolatilityIndex lwc RSI on stdev of close.

Momentum

Indicator Export Test Description
MACD MACD ti Difference of two EMAs with signal/histogram.
Momentum Momentum lwc close − close[length].
Rate of Change ROC ti Percentage change over a period.
Balance of Power BOP lwc (close − open) / (high − low).
Bull-Bear Power BullBearPower lwc Elder: high + low − 2·EMA(close).
Force Index ForceIndex Elder: signed price-volume impulse.
Elder Ray ElderRay Bull / bear power split.
Price Oscillator PriceOscillator lwc Percent-PPO with signal/histogram.
Coppock Curve CoppockCurve lwc WMA of summed long/short ROCs.
TRIX TRIX ti ROC of triple-smoothed EMA.
KST KST lwc "Know Sure Thing" weighted ROC sum + signal.

Trend

Indicator Export Test Description
Average Directional Index ADX ti Trend strength irrespective of direction.
Directional Movement Index DMI +DI, −DI, ADX.
Ichimoku Cloud Ichimoku Conversion / base / spans / lagging.
Parabolic SAR PSAR ti Welles Wilder's trailing stop.
Supertrend SuperTrend ATR-based dynamic support/resistance.
Aroon Aroon lwc Bars-since-extreme up/down lines.
Choppiness Choppiness lwc Range-vs-volatility chop measure.
Mass Index MassIndex lwc Reversal detection via H-L EMA ratio.
Vortex Vortex lwc VI+ / VI− directional pair.
Trend Strength Index TrendStrengthIndex lwc Pearson correlation of close vs. bar index.
Chande Kroll Stop ChandeKrollStop lwc Long / short ATR-based stop levels.

Volatility

Indicator Export Test Description
Average True Range ATR ti Wilder ATR with selectable smoothing.
Average Daily Range ADR lwc SMA of high − low.
Historical Volatility HistoricalVolatility lwc Annualized stdev of log returns.
Bollinger BandWidth BBBandWidth lwc (upper − lower) / basis × 100.
Standard Deviation StandardDeviation Streaming biased stdev provider.

Channels & Bands

Indicator Export Test Description
Bollinger Bands BollingerBands ti SMA ± k × stdev.
Donchian Channels DC Highest-high / lowest-low envelope.
Keltner Channel KeltnerChannel ti EMA / ATR envelope.
Envelopes Envelopes ti Fixed-percentage MA bands.
Median (with bands ready upstream) Median lwc Rolling median of HL2.

Volume

Indicator Export Test Description
On Balance Volume OBV lwc Cumulative signed volume.
Money Flow Index MFI ti Volume-weighted RSI.
Price Volume Trend PVT lwc Volume scaled by relative price change.
Volume Oscillator VolumeOscillator ti Difference between volume EMAs.
Chaikin Oscillator ChaikinOscillator EMA spread of A/D line.
Chaikin Money Flow ChaikinMF lwc A/D divided by volume over a window.
Ease of Movement EaseOfMovement lwc Price change vs. volume.
Klinger Oscillator Klinger lwc Long-term money-flow oscillator.
Net Volume NetVolume lwc Signed volume by candle direction.
Volume Profile VolumeProfile Session histogram with POC / VAH / VAL.

Candles & Pivots

Indicator Export Test Description
Heiken Ashi HeikenAshi Smoothed candle stream.
Fractal Fractal Bill Williams 5-bar fractals.
Pivot Levels Pivot Classic / Woodie / Camarilla / Fibonacci.
Trend Lines TrendLines Pivot-derived trend line detection.
Extremums Extremums Fractal-style local extrema provider.

Move / Wave (custom)

Indicator Export Description
Move Move Direction move with minimum power p.
Wave Wave Bullish/bearish candle series with power p.

Runtime state save & restore

Every stateful indicator exposes two methods:

  • dumpState() returns a JSON-safe snapshot of all internal runtime state.
  • restoreState(state) restores that snapshot into a new indicator instance and returns the instance.

The snapshot includes nested providers and rolling buffers such as CircularBuffer, so an indicator can continue after a process restart without replaying the full history. Constructor parameters are still part of the indicator configuration: restore state into an instance created with the same period/options that produced the snapshot.

import { EMA } from '@debut/indicators';

const ema = new EMA(20);

for (const close of history) {
    ema.nextValue(close);
}

// Persist this string in your own runtime storage: database, file, Redis, etc.
const serialized = JSON.stringify(ema.dumpState());

// Later, after a restart:
const restored = new EMA(20).restoreState(JSON.parse(serialized));

const liveValue = restored.nextValue(nextClose);

For live systems, save the state after committing each closed bar, together with the indicator configuration and stream identity. On startup, recreate each indicator with the same constructor arguments, call restoreState(...), then continue feeding new bars through nextValue(...).

Candlestick Patterns

Each is a streaming class:

import { Doji, BullishEngulfingPattern, HammerPattern } from '@debut/indicators';

const doji = new Doji();
const engulfing = new BullishEngulfingPattern();
const hammer = new HammerPattern();   // 5-bar with confirmation candle

for (const bar of bars) {
    if (doji.nextValue(bar.open, bar.high, bar.low, bar.close)) console.log('Doji', bar.time);
    if (engulfing.nextValue(bar.open, bar.high, bar.low, bar.close)) console.log('Bull Engulfing', bar.time);
    if (hammer.nextValue(bar.open, bar.high, bar.low, bar.close)) console.log('Hammer', bar.time);
}

nextValue returns true when the pattern fires, false if not, and undefined while it's still warming

Extension points exported contracts — how you extend this code

StatefulIndicator (Interface)
(no doc) [92 implementers]
src/stateful-indicator.ts
PatternLike (Interface)
(no doc) [89 implementers]
src/candlestick/all-patterns.ts
Pair (Interface)
* Cross-SDK tests against the `technicalindicators` reference. For * each pattern we walk synthetic OHLCV bars through
tests/candlestick/candlestick.spec.ts
RSIState (Interface)
(no doc)
src/rsi.ts
PivotValue (Interface)
(no doc)
src/pivot.ts
WMAState (Interface)
(no doc)
src/wma.ts
EMAState (Interface)
(no doc)
src/ema.ts
RMAState (Interface)
(no doc)
src/rma.ts

Core symbols most depended-on inside this repo

nextValue
called by 424
src/candlestick/all-patterns.ts
push
called by 179
src/providers/circular-buffer.ts
momentValue
called by 142
src/candlestick/all-patterns.ts
open
called by 95
src/candlestick/helpers.ts
forEach
called by 90
src/providers/circular-buffer.ts
close
called by 88
src/candlestick/helpers.ts
dumpObjectState
called by 81
src/stateful-indicator.ts
restoreObjectState
called by 81
src/stateful-indicator.ts

Shape

Method 644
Class 277
Function 52
Interface 30
Enum 1

Languages

TypeScript100%

Modules by API surface

src/candlestick/patterns.ts152 symbols
src/volume-profile.ts32 symbols
src/candlestick/all-patterns.ts25 symbols
src/candlestick/helpers.ts19 symbols
src/providers/circular-buffer.ts17 symbols
src/stateful-indicator.ts16 symbols
src/providers/levels.ts14 symbols
tests/all-indicators-state.spec.ts13 symbols
src/pivot.ts12 symbols
src/providers/mean-deviation.ts11 symbols
src/providers/extremum.ts11 symbols
src/bands.ts10 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add Indicators \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact