Computing Indicator Values

Alongside the rendered technical indicators, ApexStock exposes the underlying calculation methods directly on the instance. Use them when you need the raw values, for example to drive a custom readout, trigger alerts, or export a computed dataset, without adding a pane to the chart.

All methods take a series of OHLC candles (the same { x, y: [o, h, l, c], v } shape as your chart data) and return either a plain number[] aligned to the input, or an array of indicator points.

Point shape and warm-up

Methods that return indicator points use this shape:

{ x: 1706745600000, y: 42.7 }

During an indicator's warm-up period (before it has seen enough bars), y is null. Guard for it when you read the values:

const rsi = apexStock.calculateRSI(series, 14)
const ready = rsi.filter((p) => p.y !== null)

Moving averages

const ma = apexStock.calculateMovingAverage(series, period)   // number[]
const ema = apexStock.calculateEMA(series, period)            // number[]

Oscillators

const rsi = apexStock.calculateRSI(series, period)            // number[]

const macd = apexStock.calculateMACD(series, fastPeriod, slowPeriod, signalPeriod)
// -> { macd: (number|null)[], signal: (number|null)[], histogram: (number|null)[] }

const stochastic = apexStock.calculateStochastic(series, period, smoothPeriod)
// -> { k: IndicatorPoint[], d: IndicatorPoint[] }

Volatility

const bb = apexStock.calculateBollingerBands(series, period, stdDev)
// -> { middle: (number|null)[], upper: (number|null)[], lower: (number|null)[] }

const std = apexStock.calculateStdDevIndicator(series, period)  // IndicatorPoint[]

// Bollinger derivatives
const bbPercent = apexStock.calculateBBPercent(series, lower, upper) // IndicatorPoint[]
const bbWidth = apexStock.calculateBBWidth(series, middle, upper, lower) // IndicatorPoint[]

Volume

const pvt = apexStock.calculatePVT(series)                       // IndicatorPoint[]
const chaikin = apexStock.calculateChaikinOsc(series, shortPeriod, longPeriod) // IndicatorPoint[]

Volume methods read the v field on each candle, so make sure your data includes it.

Trend and momentum

const adx = apexStock.calculateADX(series, period)               // IndicatorPoint[]
const cci = apexStock.calculateCCI(series, period)               // IndicatorPoint[]
const accel = apexStock.calculateAcceleratorOsc(series, period)  // IndicatorPoint[]

const tsi = apexStock.calculateTSI(series, longPeriod, shortPeriod)
// -> { tsi: IndicatorPoint[], signal: IndicatorPoint[] }

Advanced

const ichimoku = apexStock.calculateIchimoku(series)
// -> { tenkan, kijun, senkouA, senkouB, chikou } (each IndicatorPoint[])

const fib = apexStock.calculateFibonacciRetracements(series)     // number[]
const fibRange = apexStock.calculateFibonacciRetracementsForRange(series, startIndex, endIndex) // number[]

const linreg = apexStock.calculateLinearRegression(series, period) // IndicatorPoint[]

Array helpers

When you already have a plain numeric array (not OHLC candles), the SMA/EMA helpers work on it directly:

const sma = apexStock.calculateSMAFromArray(values, period)  // number[]
const ema = apexStock.calculateEMAFromArray(values, period)  // number[]

Method summary

MethodReturns
calculateMovingAverage(series, period)number[]
calculateEMA(series, period)number[]
calculateRSI(series, period)number[]
calculateMACD(series, fast, slow, signal){ macd, signal, histogram }
calculateStochastic(series, period, smooth){ k, d }
calculateBollingerBands(series, period, stdDev){ middle, upper, lower }
calculateStdDevIndicator(series, period)IndicatorPoint[]
calculateBBPercent(series, lower, upper)IndicatorPoint[]
calculateBBWidth(series, middle, upper, lower)IndicatorPoint[]
calculatePVT(series)IndicatorPoint[]
calculateChaikinOsc(series, short, long)IndicatorPoint[]
calculateADX(series, period)IndicatorPoint[]
calculateCCI(series, period)IndicatorPoint[]
calculateAcceleratorOsc(series, period)IndicatorPoint[]
calculateTSI(series, long, short){ tsi, signal }
calculateIchimoku(series){ tenkan, kijun, senkouA, senkouB, chikou }
calculateFibonacciRetracements(series)number[]
calculateFibonacciRetracementsForRange(series, start, end)number[]
calculateLinearRegression(series, period)IndicatorPoint[]
calculateSMAFromArray(arr, period)number[]
calculateEMAFromArray(arr, period)number[]