@debut/indicators Documentation

repository·master·Indexed 19 days ago

https://github.com/debut-js/indicators

A streaming, allocation-light technical analysis toolkit for JavaScript and TypeScript. It provides a wide range of technical stock indicators—including moving averages, oscillators, momentum, trend, volatility, volume, and candlestick patterns—designed for both backtesting and live trading. The library features a streaming model with nextValue() for closed bars and momentValue() for intra-bar calculations, as well as state snapshotting via dumpState() and restoreState() for persisting indicator progress.

Tokens
25.2K
Snippets
72
Records
138
Agent score
16%

What's inside @debut/indicators

  1. Trend Lines indicator overview

    master

    The Trend Lines indicator is a technical analysis tool designed to discover support and resistance lines by analyzing price movement extremes. Unlike traditional methods that require large historical datasets of extremes to project future lines, this indicator uses a more efficient method based on three specific actions: change incline, fork, and break.

    Key advantages include:

    • Low Memory Footprint: It does not require keeping extensive historical candle data for future calculations. It only maintains one candle of history and metadata for up to 60 non-deleted lines.
    • Simultaneous Detection: It searches for both support and resistance lines at the same time by squeezing toward the center of price movement.
  2. Linearly Weighted Moving Average (LWMA) concept

    master

    The Linearly Weighted Moving Average (LWMA) is a moving average that assigns weights to data points based on their distance from the current point. Unlike a Simple Moving Average (SMA) where all points have equal weight, LWMA gives more importance to recent data by increasing the weight of points closer to the current time step.

    It is calculated using the formula: LWMA = (Sum of (Close * Weight)) / (Sum of Weights)

  3. Understand the Stochastic Oscillator (KD) indicator

    master

    The Stochastic Oscillator (KD) is a momentum indicator that compares a security's closing price to its price range over a specific period. It consists of two components:

    • %K: The main oscillator line, calculated as the ratio of the current close to the range between the highest high and lowest low over the period.
    • %D: A signal line, which is a 3-period Simple Moving Average (SMA) of the %K line.

    Formula:

    • %K = (Current Close - Lowest Low) / (Highest High - Lowest Low) * 100
    • %D = 3-period SMA of %K
  4. Understand the Chaikin Oscillator indicator

    master
    The Chaikin Oscillator is a momentum indicator designed to measure the accumulation-distribution line (ADL). It works by comparing the current ADL to a moving average of the ADL over a specified period. This helps identify shifts in momentum by highlighting the relationship between the current accumulation/distribution and its historical average.
  5. Understanding the Money Flow Index (MFI)

    master

    The Money Flow Index (MFI) is a technical movement indicator used to measure trading pressure (buying or selling) by incorporating both price and volume data. It is often referred to as a 'volume-weighted Relative Strength Index (RSI)' because, unlike the standard RSI which only uses price, MFI includes volume to provide a more comprehensive view of market activity.

    Key Usage Patterns:

    • Overbought/Oversold Signals:
      • An MFI reading above 80 is typically considered overbought.
      • An MFI reading below 20 is typically considered oversold.
      • Some traders use more extreme thresholds of 90 and 10.
    • Divergence: Watch for discrepancies between the indicator and price. For example, if the MFI is rising while the price is falling or flat, it may signal a potential upward price reversal.
  6. Concept: Accelerator Oscillator (AO)

    master

    The Accelerator Oscillator (AO) is an oscillator indicator developed by Bill Williams. It measures the acceleration or deceleration of price movement.

    It is based on the principle that when price movement reverses, the speed of that movement slows down before the trend actually changes. The AO helps traders recognize these changes in the rate of price movement to identify potential entry and exit points.

  7. How the streaming model works: nextValue vs momentValue

    master

    The library uses a streaming model designed for both backtesting and live trading. It provides two primary methods for consuming data:

    1. nextValue(...) (Close-of-bar): Call this once per closed bar. It advances the indicator's internal state and returns the new value. This is used to commit data to the indicator.
    2. momentValue(...) (Intra-bar): Call this with the price/volume of a live, still-forming candle. It calculates what the indicator value would be if the bar closed at that price, without mutating the internal state. This allows for tick-by-tick recalculation without corrupting the indicator's history.

    Use momentValue to preview values during a candle and nextValue to finalize the state when the candle closes.

    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
  8. Calculate Triple Exponential Moving Average (TEMA)

    master

    TEMA is a moving average designed to reduce lag by combining a single, double, and triple Exponential Moving Average (EMA). It is more responsive to price changes than a traditional EMA.

    Formula: TEMA = 3 × EMA1 − 3 × EMA2 + EMA3

    • EMA1: EMA of price
    • EMA2: EMA of EMA1
    • EMA3: EMA of EMA2
  9. Understand the SuperTrend MTF (ST MTF) indicator

    master

    The SuperTrend MTF (ST MTF) is a trend-following indicator used to identify the direction of a market trend. It is calculated based on the average of the high and low prices of a given period.

    Calculation Formula: ST MTF = (High + Low) / 2

  10. Understand the Smoothed Moving Average (SMMA) calculation

    master

    The Smoothed Moving Average (SMMA) is a moving average that prioritizes recent data points by assigning them more weight. It is calculated using the current close price and the previous SMMA value over a period of n.

    SMMA = (Close + (n - 1) * Previous SMMA) / n