npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cesarvarela/indicators

v1.0.2

Published

Technical indicators for financial and time series analysis

Downloads

21

Readme

@cesarvarela/indicators

Technical indicators for financial and time series analysis, built with a functional, composable philosophy.

Features

  • 🎯 Type-safe - Full TypeScript support with generics
  • 🔧 Flexible - Works with any data structure
  • 📦 Tree-shakeable - Import only what you need
  • 🚀 Fast - Optimized calculations
  • 🧩 Composable - Built on the compute pattern for consistent transformations
  • 0️⃣ Zero dependencies - No external packages

Installation

npm install @cesarvarela/indicators

Usage

import { rsi, macd, bollingerBands, atr, obv } from '@cesarvarela/indicators';

// Your data can be any structure with numeric fields
const bars = [
  { open: 100, high: 105, low: 95, close: 102, volume: 1000, timestamp: new Date() },
  { open: 102, high: 108, low: 100, close: 106, volume: 1200, timestamp: new Date() },
  // ... more bars
];

// Most indicators work on any numeric field
const withRSI = rsi(bars, 14, 'close');           // RSI with period 14
const withMACD = macd(bars, 'close');             // MACD with default periods
const withBB = bollingerBands(bars, 'close');     // Bollinger Bands

// Some indicators need specific fields (TypeScript enforces this)
const withATR = atr(bars);  // Requires open, high, low, close
const withOBV = obv(bars);  // Requires volume field

The Compute Philosophy

All indicators are built using the compute function, which enables:

  • Immutable transformations (original data is never modified)
  • Access to previously computed values during calculation
  • Type-safe property additions
  • Consistent, predictable API
import { compute } from '@cesarvarela/indicators';

// Create your own indicators using compute
const withCustom = compute(bars, 'myIndicator', (bar, index, allBars, params) => {
    if (index < params.period - 1) return undefined;
    // Your calculation here
    return bar.close * params.multiplier;
}, { period: 10, multiplier: 2 });

Available Indicators

Momentum Indicators

  • RSI (Relative Strength Index)
  • MACD (Moving Average Convergence Divergence)

Moving Averages

  • SMA (Simple Moving Average)
  • EMA (Exponential Moving Average)

Volatility Indicators

  • Bollinger Bands
  • ATR (Average True Range)
  • Donchian Channel

Volume Indicators

  • OBV (On-Balance Volume)
  • OBV MA (OBV Moving Average)

Utility Functions

  • slope - Linear regression slope
  • relativeChange - Percentage change between values
  • crossover/crossunder - Detect line crossings
  • zscore - Statistical z-score

Type Requirements

Most indicators work with any object structure. Some require specific fields:

// Minimal interfaces for specific indicators
interface OHLCBar {
    open: number;
    high: number;
    low: number;
    close: number;
}

interface VolumeBar {
    volume: number;
}

// ATR requires OHLC data
const withATR = atr(ohlcBars);

// OBV requires volume data
const withOBV = obv(volumeBars);

// Most indicators work on any field
const withRSI = rsi(anyDataArray, 14, 'anyNumericField');

Examples

Chaining Multiple Indicators

// Each indicator preserves all previous fields
const data = bollingerBands(
    macd(
        rsi(bars, 14, 'close'),
        'close'
    ),
    'close'
);
// Result has RSI, MACD, and Bollinger Bands fields

Custom Indicators

import { compute } from '@cesarvarela/indicators';

// Create a custom momentum indicator
const momentum = <T>(data: T[], field: keyof T, period: number = 10) => {
    return compute(data, 'momentum', (item, index, allItems) => {
        if (index < period) return undefined;
        const oldValue = allItems[index - period][field] as number;
        const currentValue = item[field] as number;
        return ((currentValue - oldValue) / oldValue) * 100;
    }, { period });
};

License

MIT © Cesar Varela