centaur-technical-indicators
    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 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].

    • 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 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
      );