ti-engine
    Preparing search index...

    Interface MomentumIndicatorsSingle

    Single-value momentum indicators. These compute a single value from a full window (the entire array passed in).

    interface MomentumIndicatorsSingle {
        chaikinOscillator(
            highs: number[],
            lows: number[],
            close: number[],
            volume: number[],
            shortPeriod: number,
            previousAccumulationDistribution: number,
            shortPeriodModel: ConstantModelType,
            longPeriodModel: ConstantModelType,
        ): [number, number];
        chandeMomentumOscillator(prices: number[]): number;
        commodityChannelIndex(
            prices: number[],
            constantModelType: ConstantModelType,
            deviationModel: DeviationModel,
            constantMultiplier: number,
        ): number;
        macdLine(
            prices: number[],
            shortPeriod: number,
            shortPeriodModel: ConstantModelType,
            longPeriodModel: ConstantModelType,
        ): number;
        mcginleyDynamicCommodityChannelIndex(
            prices: number[],
            previousMcginleyDynamic: number,
            deviationModel: DeviationModel,
            constantMultiplier: number,
        ): [number, number];
        mcginleyDynamicMacdLine(
            prices: number[],
            shortPeriod: number,
            previousShortMcginley: number,
            previousLongMcginley: number,
        ): [number, number, number];
        moneyFlowIndex(prices: number[], volume: number[]): number;
        onBalanceVolume(
            currentPrice: number,
            previousPrice: number,
            currentVolume: number,
            previousOnBalanceVolume: number,
        ): number;
        percentagePriceOscillator(
            prices: number[],
            shortPeriod: number,
            constantModelType: ConstantModelType,
        ): number;
        rateOfChange(currentPrice: number, previousPrice: number): number;
        relativeStrengthIndex(
            prices: number[],
            constantModelType: ConstantModelType,
        ): number;
        signalLine(macds: number[], constantModelType: ConstantModelType): number;
        slowestStochastic(
            slowStochastics: number[],
            constantModelType: ConstantModelType,
        ): number;
        slowStochastic(
            stochastics: number[],
            constantModelType: ConstantModelType,
        ): number;
        stochasticOscillator(prices: number[]): number;
        williamsPercentR(high: number[], low: number[], close: number): number;
    }
    Index

    Methods

    • Calculates the Chaikin Oscillator (CO) for the full window.

      Steps:

      • Builds Accumulation/Distribution (AD) series with provided previous seed.
      • Short-period average from last shortPeriod AD values using short model.
      • Long-period average over all AD values using long model.
      • Returns (short - long, lastAD).

      Parameters

      • highs: number[]

        Slice of highs.

      • lows: number[]

        Slice of lows.

      • close: number[]

        Slice of closes.

      • volume: number[]

        Slice of volumes.

      • shortPeriod: number

        Short AD period length.

      • previousAccumulationDistribution: number

        Previous AD seed (0.0 if none).

      • shortPeriodModel: ConstantModelType

        Model for the short AD average.

      • longPeriodModel: ConstantModelType

        Model for the long AD average.

      Returns [number, number]

      [oscillatorValue, lastAD].

      If input lengths differ or highs.length <= shortPeriod.

    • Calculates the Chande Momentum Oscillator (CMO) for the full window.

      Uses sums of positive/negative price differences to produce a value in [-100, 100]. Special cases:

      • If no gains => -100
      • If no losses => 100

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      Returns number

      CMO value in [-100, 100].

      If prices is empty.

    • Calculates the Commodity Channel Index (CCI) for the full window.

      Formula:

      • (lastPrice - movingConstant) / (constantMultiplier * deviation)
      • Typically, constantMultiplier = 0.015

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • constantModelType: ConstantModelType

        Central model (SMA, EMA, median, etc.).

      • deviationModel: DeviationModel

        Deviation model (StdDev, MAD, etc.).

      • constantMultiplier: number

        Scale factor (normally 0.015).

      Returns number

      CCI value (unitless).

      If prices is empty.

    • Calculates the MACD line for the full window.

      Short-period average is computed over the last shortPeriod values, while the long-period average uses the entire series, each with the respective model.

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • shortPeriod: number

        Length of the short period (must be < prices.length).

      • shortPeriodModel: ConstantModelType

        Model for short average.

      • longPeriodModel: ConstantModelType

        Model for long average (over full series).

      Returns number

      MACD value (short - long).

      If prices is empty or shortPeriod >= prices.length.

    • Calculates the McGinley Dynamic CCI for the full window.

      Uses the McGinley Dynamic of the last price as the center and scales by the chosen deviation model. Returns both the CCI and the computed McGinley value.

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • previousMcginleyDynamic: number

        Previous McGinley value (use 0.0 if none).

      • deviationModel: DeviationModel

        Deviation model (StdDev, MAD, etc.).

      • constantMultiplier: number

        Scale factor (normally 0.015).

      Returns [number, number]

      [cci, mcginleyDynamic].

      If prices is empty.

    • Calculates the McGinley Dynamic MACD for the full window.

      Returns a tuple:

      • [macd, shortMcginley, longMcginley]
      • If both previous short/long McGinley are 0.0, returns (0.0, lastPrice, lastPrice)

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • shortPeriod: number

        Short period length (must be < prices.length).

      • previousShortMcginley: number

        Previous short McGinley (0.0 if none).

      • previousLongMcginley: number

        Previous long McGinley (0.0 if none).

      Returns [number, number, number]

      [macd, shortMcginley, longMcginley].

      If prices is empty or shortPeriod >= prices.length.

    • Calculates the Money Flow Index (MFI) for the full window.

      Notes:

      • Uses raw money flow (price * volume) to accumulate positive/negative flows.
      • Returns 100 if there are no negative flows, 0 if no positive flows.

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • volume: number[]

        Slice of volumes (same length as prices).

      Returns number

      MFI value in [0, 100].

      If arrays are empty or lengths mismatch.

    • Calculates the On-Balance Volume (OBV) update.

      Adds/subtracts current volume if price up/down vs previous price, and accumulates with previous OBV.

      Parameters

      • currentPrice: number

        Current price.

      • previousPrice: number

        Previous price.

      • currentVolume: number

        Current volume.

      • previousOnBalanceVolume: number

        Previous OBV seed (use 0 if none).

      Returns number

      Updated OBV value.

    • Calculates the Percentage Price Oscillator (PPO) for the full window (%).

      Uses chosen central model for both short (applied to the trailing short slice) and long (applied to the full window), then scales the difference by long.

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • shortPeriod: number

        Length of the short period (must be <= prices.length).

      • constantModelType: ConstantModelType

        Central model for both averages.

      Returns number

      PPO percentage.

      If prices is empty or shortPeriod > prices.length.

    • Calculates the Rate of Change (RoC) between two prices.

      Parameters

      • currentPrice: number

        Current price.

      • previousPrice: number

        Previous price.

      Returns number

      Percentage change: ((current - previous)/previous) * 100.

    • Calculates the Relative Strength Index (RSI).

      Computes average gains and losses from consecutive price differences and forms the RSI using the selected central model to smooth/aggregate:

      • SimpleMovingAverage, SmoothedMovingAverage, ExponentialMovingAverage, SimpleMovingMedian, SimpleMovingMode.

      Special cases:

      • If there are no previous gains => 0.0
      • If there are no previous losses => 100.0

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      • constantModelType: ConstantModelType

        Central model used to aggregate gains/losses.

      Returns number

      RSI value in [0, 100].

      If prices is empty.

      const rsi = momentumIndicators.single.relativeStrengthIndex(
      prices,
      ConstantModelType.SmoothedMovingAverage
      );
    • Calculates the MACD signal line for the full window.

      Applies the chosen central model to the provided MACD values.

      Parameters

      • macds: number[]

        Slice of MACD values (length >= 1).

      • constantModelType: ConstantModelType

        Central model (SMA, EMA, median, etc.).

      Returns number

      Signal value.

      If macds is empty.

    • Calculates the Slowest Stochastic as a smoothing of Slow Stochastic values.

      Uses the provided central model to aggregate the given slow stochastics.

      Parameters

      • slowStochastics: number[]

        Slice of Slow Stochastic values (length >= 1).

      • constantModelType: ConstantModelType

        Central model (SMA, EMA, median, etc.).

      Returns number

      Slowest stochastic value.

      If slowStochastics is empty.

    • Calculates the Slow Stochastic as a smoothing of Stochastic Oscillator values.

      Uses the provided central model to aggregate the given stochastics.

      Parameters

      • stochastics: number[]

        Slice of Stochastic Oscillator values (length >= 1).

      • constantModelType: ConstantModelType

        Central model (SMA, EMA, median, etc.).

      Returns number

      Smoothed stochastic value.

      If stochastics is empty.

    • Calculates the Stochastic Oscillator for the full window.

      Interpretation:

      • Returns 100 * ((last - min) / (max - min)) over the entire input.

      Parameters

      • prices: number[]

        Slice of prices (length >= 1).

      Returns number

      Percent value in [0, 100].

      If prices is empty.

    • Calculates the Williams %R for the full window.

      Parameters

      • high: number[]

        Slice of highs.

      • low: number[]

        Slice of lows.

      • close: number

        Close price for the observed period (last bar’s close).

      Returns number

      %R value in [-100, 0].

      If high/low are empty or their lengths differ.