Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@junduck/trading-indi

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@junduck/trading-indi

A TypeScript library providing 80+ technical indicators for trading, designed for incremental, stateful calculation perfect for intraday and realtime trading applications

latest
Source
npmnpm
Version
0.999.0
Version published
Maintainers
1
Created
Source

trading-indi

A comprehensive TypeScript library for incremental trading computations, featuring 80+ technical indicators, candlestick pattern recognition, composable computation primitives, and a powerful DAG-based flow system for building complex trading algorithms.

Why trading-indi?

Traditional technical indicator libraries recalculate entire datasets on each new data point. trading-indi is a complete framework for building sophisticated trading algorithms:

  • 80+ Technical Indicators: Foundation, Statistics, Volatility, Momentum, Oscillators, Stochastic, Trend, and Volume indicators
  • Pattern Recognition: 10+ candlestick pattern heuristics (Doji, Hammer, Marubozu, etc.)
  • Computation Primitives: 40+ arithmetic and logical operators for custom calculations
  • DAG Flow System: Build complex multi-indicator strategies with topological execution
  • Incremental Calculation: Stateful, online algorithms that update efficiently with each tick
  • Perfect for Realtime Trading: Designed for WebSocket streams, tick data, and intraday strategies
  • Memory Efficient: Uses sliding windows and online algorithms
  • Consistent API: Every operator follows the same class/hook pattern
  • Zero Dependencies: Clean, modern TypeScript

Performance

trading-indi is built for speed and efficiency, making it ideal for real-time trading applications:

Benchmark Results

  • Processing Speed: 2+ million indicator calculations per second
  • Latency: ~0.03ms to process a single bar with all 64 indicators
  • Memory Efficiency: ~2.5KB per indicator instance
  • Real-time Capability: Can handle tick data (1000+ bars/second) with ease

Real-time Trading Suitability

All trading strategies tested are feasible for real-time trading:

StrategyIndicatorsTime per BarMax Bars/secStatus
Scalping50.0017ms590,935✅ FEASIBLE
Swing Trading60.0020ms502,162✅ FEASIBLE
Trend Following60.0017ms597,488✅ FEASIBLE
Mean Reversion60.0020ms488,757✅ FEASIBLE
Volume Analysis60.0005ms1,840,082✅ FEASIBLE
Multi-Timeframe110.0028ms358,709✅ FEASIBLE

The library can easily handle real-time trading scenarios, including tick data processing, with minimal memory footprint and excellent performance characteristics.

Installation

Install the package from npm:

npm install @junduck/trading-indi
# or
yarn add @junduck/trading-indi
# or
pnpm add @junduck/trading-indi

Library Capabilities

trading-indi is more than just an indicator library - it's a complete framework for building trading algorithms:

CapabilityComponentsUse Case
Technical Indicators80+ indicators across 8 categoriesCalculate standard technical indicators incrementally
Pattern Recognition10+ candlestick patternsDetect chart patterns in realtime
Computation Primitives40+ arithmetic & logical operatorsBuild custom calculations and trading logic
DAG Flow SystemGraphExec, OpRegistry, Schema validationCompose complex multi-indicator strategies with automatic dependency resolution

Architecture Overview

┌─────────────────────────────────────────────────────┐
│                   Your Strategy                     │
├─────────────────────────────────────────────────────┤
│  DAG Flow System (GraphExec + OpRegistry)               │
│  ├─ Topological execution                           │
│  ├─ JSON serialization                              │
│  └─ Forward reference resolution                    │
├─────────────────────────────────────────────────────┤
│  Operators (Stateful, Incremental)                  │
│  ├─ Technical Indicators (80+)                      │
│  ├─ Pattern Recognition (10+)                       │
│  └─ Computation Primitives (40+)                    │
├─────────────────────────────────────────────────────┤
│  Foundation (from @junduck/trading-core)            │
│  └─ Sliding windows, online algorithms              │
└─────────────────────────────────────────────────────┘

Quick Start

Class-Based Usage (Stateful)

import { RSI, EMA, MACD, ATR, BBANDS, ADX } from '@junduck/trading-indi';

const rsi = new RSI({ period: 14 });
const ema = new EMA({ period: 20 });
const macd = new MACD({
  period_fast: 12,
  period_slow: 26,
  period_signal: 9
});
const atr = new ATR({ period: 14 });
const bbands = new BBANDS({ period: 20, stddev: 2 });
const adx = new ADX({ period: 14 });

// Process streaming data
priceStream.on('data', (bar) => {
  const rsiValue = rsi.onData(bar);
  const emaValue = ema.onData(bar.close);
  const { macd: macdLine, signal, histogram } = macd.onData(bar);
  const atrValue = atr.onData(bar);
  const { upper, middle, lower } = bbands.onData(bar.close);
  const adxValue = adx.onData(bar);

  console.log({ rsiValue, emaValue, macdLine, atrValue, bbands: { upper, middle, lower }, adxValue });
});

Functional Usage (Hooks)

import { useRSI, useEMA, useMACD, useATR, useBBANDS, useADX } from '@junduck/trading-indi';

const getRSI = useRSI({ period: 14 });
const getEMA = useEMA({ period: 20 });
const getMACD = useMACD({
  period_fast: 12,
  period_slow: 26,
  period_signal: 9
});
const getATR = useATR({ period: 14 });
const getBBANDS = useBBANDS({ period: 20, stddev: 2 });
const getADX = useADX({ period: 14 });

for (const bar of historicalData) {
  const rsiValue = getRSI(bar);
  const emaValue = getEMA(bar.close);
  const { macd, signal, histogram } = getMACD(bar);
  const atrValue = getATR(bar);
  const { upper, middle, lower } = getBBANDS(bar.close);
  const adxValue = getADX(bar);
}

Available Indicators

Foundation

IndicatorParametersOutput
EMAperiod or alphanumber
EWMAperiodnumber
SMAperiodnumber
Varianceperiod, ddof?{mean: number, variance: number}
Stddevperiod, ddof?{mean: number, stddev: number}
Minperiodnumber
Maxperiodnumber
Sumperiodnumber
MinMaxperiod{min: number, max: number}

Statistics

IndicatorParametersOutput
VarianceEWperiod or alpha, ddof?{mean: number, variance: number}
Covperiod, ddof?{meanX: number, meanY: number, covariance: number}
Corrperiod, ddof?{meanX: number, meanY: number, covariance: number, correlation: number}
Betaperiod, ddof?{meanX: number, meanY: number, covariance: number, beta: number}
ZSCOREperiodnumber
CORRELATIONperiodnumber
BETAperiodnumber

Volatility

IndicatorParametersOutput
VOLATILITYperiod, annualizedDays?number
CVIperiodnumber
MASSperiodnumber
TRnonenumber
ATRperiodnumber
NATRperiodnumber
PriceChannelperiod{upper, lower}
BBANDSperiod, stddev?{upper, middle, lower}
KCperiod, multiplier?{upper, middle, lower}
DCperiod{upper, middle, lower}

Momentum

IndicatorParametersOutput
BOPnonenumber
MOMperiodnumber
ROCperiodnumber
ROCRperiodnumber
RSIperiodnumber
CMOperiodnumber
WADnonenumber
RVIperiod{rvi, signal}
TSIlong_period?, short_period?, signal_period?{tsi, signal}
BBPOWERperiod{bull_power, bear_power}

Oscillators

IndicatorParametersOutput
AOnonenumber
APOperiod_fast, period_slownumber
DPOperiodnumber
Fisherperiodnumber
MACDperiod_fast, period_slow, period_signal{macd, signal, histogram}
PPOperiod_fast, period_slownumber
QSTICKperiodnumber
TRIXperiodnumber
ULTOSCperiod_fast, period_med, period_slownumber

Stochastic

IndicatorParametersOutput
STOCHk_period?, k_slowing?, d_period?{k, d}
STOCHRSIperiodnumber
WILLRperiodnumber

Trend

IndicatorParametersOutput
AROONperiod{up, down}
AROONOSCperiodnumber
CCIperiodnumber
VHFperiodnumber
DMperiod{plus, minus}
DIperiod{plus, minus}
DXperiodnumber
ADXperiodnumber
ADXRperiodnumber
SARacceleration?, maximum?number
VIperiod{vi_plus, vi_minus}
ICHIMOKUtenkan_period?, kijun_period?, senkou_b_period?, displacement?{tenkan, kijun, senkou_a, senkou_b, chikou}

Volume

IndicatorParametersOutput
ADnonenumber
ADOSCperiod_fast, period_slownumber
KVOperiod_fast?, period_slow?number
NVInonenumber
OBVnonenumber
PVInonenumber
MFIperiodnumber
EMVnonenumber
MARKETFInonenumber
VOSCperiod_fast, period_slownumber
CMFperiodnumber
CHOperiod_fast, period_slownumber
PVOperiod_fast, period_slow, period_signal?{pvo, signal, histogram}
FIperiodnumber
VROCperiodnumber
PVTnonenumber

Pattern Recognition Heuristics

trading-indi includes candlestick pattern recognition for identifying common chart patterns:

PatternParametersOutputDescription
DojidojiThres?booleanOpen and close at nearly the same price
LongLeggedDojiperiod?booleanDoji with very long shadows
DragonflyDojilowerShadowThres?, upperShadowThres?booleanDoji with long lower shadow, no upper shadow
GravestoneDojiupperShadowThres?, lowerShadowThres?booleanDoji with long upper shadow, no lower shadow
SpinningTopperiod?, rangeMultiplier?, bodyThres?booleanSmall body with long upper and lower shadows
MarubozuWhiteperiod?, shadowThres?booleanLong white candle with minimal shadows
MarubozuBlackperiod?, shadowThres?booleanLong black candle with minimal shadows
HammerbodyThres?, lowerShadowThres?, upperShadowThres?booleanSmall body at top with long lower shadow
InvertedHammerbodyThres?, upperShadowThres?, lowerShadowThres?booleanSmall body at bottom with long upper shadow
HighWaveperiod?, rangeMultiplier?, bodyThres?, shadowThres?booleanVery long shadows in both directions with small body

Example: Pattern Recognition

import { Hammer, Doji, MarubozuWhite } from '@junduck/trading-indi';

const hammer = new Hammer();
const doji = new Doji();
const marubozu = new MarubozuWhite();

websocket.on('tick', (bar) => {
  const isHammer = hammer.onData(bar);
  const isDoji = doji.onData(bar);
  const isMarubozu = marubozu.onData(bar);

  if (isHammer) console.log('Hammer pattern detected - potential reversal');
  if (isDoji) console.log('Doji pattern detected - indecision');
  if (isMarubozu) console.log('Marubozu White - strong bullish momentum');
});

Computation Primitives

Build custom calculations using composable primitive operators. These are the building blocks for creating complex trading logic in the DAG flow system.

Arithmetic Operators

OperatorInputOutputDescription
Addlhs, rhsnumberAddition
Sublhs, rhsnumberSubtraction
Mullhs, rhsnumberMultiplication
Divlhs, rhsnumberDivision (safe from divide-by-zero)
Modlhs, rhsnumberModulo
Powbase, expnumberPower
Minlhs, rhsnumberMinimum of two values
Maxlhs, rhsnumberMaximum of two values
NegatexnumberNegation
AbsxnumberAbsolute value
Signx-1, 0, 1Sign of number
FloorxnumberFloor function
CeilxnumberCeiling function
RoundxnumberRound to nearest integer
SqrtxnumberSquare root
LogxnumberNatural logarithm
ExpxnumberExponential (e^x)
Log1pxnumberlog(1 + x)
Expm1xnumberexp(x) - 1
Reciprocalxnumber1/x
Clampx, min, maxnumberClamp value between min and max
Lerpa, b, tnumberLinear interpolation
InvLerpa, b, vnumberInverse linear interpolation
SumOf...inputsnumberSum of multiple values
ProdOf...inputsnumberProduct of multiple values
AvgOf...inputsnumberAverage of multiple values
MinOf...inputsnumberMinimum of multiple values
MaxOf...inputsnumberMaximum of multiple values
RelDista, bnumberRelative distance: abs(a-b)/abs(b)

Logical Operators

OperatorInputOutputDescription
LTlhs, rhsbooleanLess than
GTlhs, rhsbooleanGreater than
LTElhs, rhsbooleanLess than or equal
GTElhs, rhsbooleanGreater than or equal
EQlhs, rhsbooleanEqual
NEQlhs, rhsbooleanNot equal
Betweenx, lo, hibooleanCheck if x is between lo and hi
Outsidex, lo, hibooleanCheck if x is outside lo and hi
Andlhs, rhsbooleanLogical AND
Orlhs, rhsbooleanLogical OR
NotxbooleanLogical NOT
Xorlhs, rhsbooleanLogical XOR
AllOf...inputsbooleanAll inputs are true
AnyOf...inputsbooleanAny input is true
NoneOf...inputsbooleanNo inputs are true
IsNaNxbooleanCheck if NaN
IsFinitexbooleanCheck if finite
IsPositivexbooleanCheck if positive
IsNegativexbooleanCheck if negative
IsZeroxbooleanCheck if zero
IfThenElsecond, thenVal, elseValTConditional selection
Gatecond, valT | undefinedPass value if condition is true
Coalesce...inputsT | undefinedReturn first non-null value

DAG Flow System

The GraphExec and OpRegistry provide a powerful DAG (Directed Acyclic GraphExec) execution engine for building complex, composable trading strategies. Define your computation as a graph of operators with dependencies, and the system handles topological sorting and execution.

Key Features

  • Topological Execution: Automatically determines correct execution order
  • Type Safety: Zod-based schema validation
  • JSON Serialization: Save and load graphs as JSON
  • Forward References: Support for future node references
  • High Performance: Index-based adjacency lists, 2M+ ops/sec
  • AI-Friendly: Schema designed for AI agent code generation

Example: Multi-Indicator Strategy with DAG

import { GraphExec, OpRegistry } from '@junduck/trading-indi';

// Register all operators you want to use
OpRegistry.registerDefaults();

// Define your strategy as a graph
const graph = new GraphExec('trading-strategy');

// Input nodes
graph.addNode('close', 'Input', []);
graph.addNode('high', 'Input', []);
graph.addNode('low', 'Input', []);

// Calculate indicators
graph.addNode('rsi', 'RSI', ['close'], { period: 14 });
graph.addNode('ema20', 'EMA', ['close'], { period: 20 });
graph.addNode('ema50', 'EMA', ['close'], { period: 50 });

// Build trading logic with primitives
graph.addNode('rsi_oversold', 'LT', ['rsi', 30]);  // RSI < 30
graph.addNode('ema_bullish', 'GT', ['ema20', 'ema50']);  // EMA20 > EMA50
graph.addNode('buy_signal', 'And', ['rsi_oversold', 'ema_bullish']);

// Process streaming data
websocket.on('tick', (bar) => {
  graph.update('close', bar.close);
  graph.update('high', bar.high);
  graph.update('low', bar.low);

  const buySignal = graph.read('buy_signal');
  const rsi = graph.read('rsi');

  if (buySignal) {
    console.log(`BUY SIGNAL: RSI=${rsi}`);
  }
});

// Serialize to JSON for storage or AI agent generation
const schema = graph.exportSchema();
console.log(JSON.stringify(schema, null, 2));

// Load from JSON
const restoredGraph = GraphExec.fromSchema(schema);

Example: Complex Strategy with Multiple Outputs

import { GraphExec, OpRegistry } from '@junduck/trading-indi';

OpRegistry.registerDefaults();

const graph = new GraphExec('advanced-strategy');

// Inputs
graph.addNode('bar', 'Input', []);

// Multiple indicators
graph.addNode('rsi', 'RSI', ['bar'], { period: 14 });
graph.addNode('macd_result', 'MACD', ['bar'], {
  period_fast: 12,
  period_slow: 26,
  period_signal: 9
});
graph.addNode('atr', 'ATR', ['bar'], { period: 14 });

// Extract MACD components
graph.addNode('macd_line', 'GetField', ['macd_result', 'macd']);
graph.addNode('signal_line', 'GetField', ['macd_result', 'signal']);

// Build complex conditions
graph.addNode('rsi_bullish', 'Between', ['rsi', 30, 50]);
graph.addNode('macd_crossover', 'GT', ['macd_line', 'signal_line']);
graph.addNode('strong_signal', 'And', ['rsi_bullish', 'macd_crossover']);

// Calculate position sizing based on ATR
graph.addNode('atr_multiplier', 'Mul', ['atr', 2]);
graph.addNode('position_size', 'Div', [1000, 'atr_multiplier']);

// Update with streaming data
for (const bar of streamingData) {
  graph.update('bar', bar);

  const signal = graph.read('strong_signal');
  const posSize = graph.read('position_size');
  const atr = graph.read('atr');

  if (signal) {
    console.log(`Entry Signal - Position Size: ${posSize}, Stop Loss: ${atr * 2}`);
  }
}

Real-World Example: Intraday Strategy

import { RSI, ATR, EMA, BBANDS, ADX, MACD, VOLUME } from '@junduck/trading-indi';

const rsi = new RSI({ period: 14 });
const atr = new ATR({ period: 14 });
const ema20 = new EMA({ period: 20 });
const ema50 = new EMA({ period: 50 });
const bbands = new BBANDS({ period: 20, stddev: 2 });
const adx = new ADX({ period: 14 });
const macd = new MACD({ period_fast: 12, period_slow: 26, period_signal: 9 });
const obv = new OBV();

websocket.on('tick', (bar) => {
  const rsiValue = rsi.onData(bar);
  const atrValue = atr.onData(bar);
  const shortEMA = ema20.onData(bar.close);
  const longEMA = ema50.onData(bar.close);
  const { upper, middle, lower } = bbands.onData(bar.close);
  const adxValue = adx.onData(bar);
  const { macd: macdLine, signal, histogram } = macd.onData(bar);
  const obvValue = obv.onData(bar);

  // Multi-indicator strategy
  const isOversold = rsiValue < 30;
  const isBullishTrend = shortEMA > longEMA;
  const isStrongTrend = adxValue > 25;
  const isNearSupport = bar.close <= lower * 1.02; // Within 2% of lower band
  const isMACDBullish = macdLine > signal && histogram > 0;
  const isVolumeConfirming = obvValue > 0; // Positive volume flow

  if (isOversold && isBullishTrend && isStrongTrend && isNearSupport && isMACDBullish && isVolumeConfirming) {
    console.log('Strong Buy Signal - Multiple Confirmations');
    console.log(`Entry: ${bar.close}`);
    console.log(`Stop Loss: ${bar.close - (atrValue * 2)}`);
    console.log(`Target: ${bar.close + (atrValue * 3)}`);
    console.log(`RSI: ${rsiValue}, ADX: ${adxValue}, MACD: ${macdLine}`);
  }

  // Exit signal
  const isOverbought = rsiValue > 70;
  const isBearishMACD = macdLine < signal && histogram < 0;
  const isNearResistance = bar.close >= upper * 0.98; // Within 2% of upper band

  if (isOverbought || isBearishMACD || isNearResistance) {
    console.log('Exit Signal - Consider Taking Profits');
    console.log(`Current Price: ${bar.close}`);
    console.log(`RSI: ${rsiValue}, MACD: ${macdLine}, BB Position: ${(bar.close - lower) / (upper - lower)}`);
  }
});

Statistical Analysis

The library includes advanced statistical indicators for quantitative analysis:

import { Corr, Beta, ZSCORE } from '@junduck/trading-indi';

// Correlation between two assets
const correlation = new Corr({ period: 20 });
const corrValue = correlation.onData(assetPrice, benchmarkPrice);

// Beta calculation for risk analysis
const beta = new Beta({ period: 252 }); // Daily data for 1 year
const betaValue = beta.onData(stockPrice, marketIndexPrice);

// Z-Score for statistical arbitrage
const zscore = new ZSCORE({ period: 20 });
const zValue = zscore.onData(price);

API Reference

Exports

The library exports all its capabilities from the main package:

// Technical Indicators (80+)
import {
  // Foundation
  SMA, EMA, EWMA, Variance, Stddev, Min, Max, Sum, MinMax,

  // Statistics
  VarianceEW, Cov, Corr, Beta, ZSCORE, CORRELATION,

  // Volatility
  VOLATILITY, CVI, MASS, TR, ATR, NATR, PriceChannel, BBANDS, KC, DC,

  // Momentum
  BOP, MOM, ROC, ROCR, RSI, CMO, WAD, RVI, TSI, BBPOWER,

  // Oscillators
  AO, APO, DPO, Fisher, MACD, PPO, QSTICK, TRIX, ULTOSC,

  // Stochastic
  STOCH, STOCHRSI, WILLR,

  // Trend
  AROON, AROONOSC, CCI, VHF, DM, DI, DX, ADX, ADXR, SAR, VI, ICHIMOKU,

  // Volume
  AD, ADOSC, KVO, NVI, OBV, PVI, MFI, EMV, MarketFI, VOSC, CMF, CHO, PVO, FI, VROC, PVT
} from '@junduck/trading-indi';

// Pattern Recognition
import {
  Doji, LongLeggedDoji, DragonflyDoji, GravestoneDoji,
  SpinningTop, MarubozuWhite, MarubozuBlack,
  Hammer, InvertedHammer, HighWave
} from '@junduck/trading-indi';

// Computation Primitives
import {
  // Arithmetic
  Add, Sub, Mul, Div, Mod, Pow, Min, Max,
  Negate, Abs, Sign, Floor, Ceil, Round, Sqrt, Log, Exp,
  Log1p, Expm1, Reciprocal, Clamp, Lerp, InvLerp,
  SumOf, ProdOf, AvgOf, MinOf, MaxOf, RelDist,

  // Logical
  LT, GT, LTE, GTE, EQ, NEQ, Between, Outside,
  And, Or, Not, Xor, AllOf, AnyOf, NoneOf,
  IsNaN, IsFinite, IsPositive, IsNegative, IsZero,
  IfThenElse, Gate, Coalesce
} from '@junduck/trading-indi';

// DAG Flow System
import {
  GraphExec, OpRegistry,
  validateGraphSchema, formatValidationError, graphComplexity, graphDiff
} from '@junduck/trading-indi';

// Types
import type {
  NodeSchema, GraphSchema, GraphSchemaValidationResult, GraphError, GraphDiff,
  BarData, BarWith, PeriodOptions
} from '@junduck/trading-indi';

Hook Pattern

Every class-based operator has a corresponding functional hook:

import { useRSI, useSMA, useHammer } from '@junduck/trading-indi';

const getRSI = useRSI({ period: 14 });
const getSMA = useSMA({ period: 20 });
const isHammer = useHammer();

for (const bar of data) {
  const rsi = getRSI(bar);
  const sma = getSMA(bar.close);
  const hammer = isHammer(bar);
}

Bar Data Types

Most indicators accept BarData with these properties:

interface BarData {
  open?: number;
  high?: number;
  low?: number;
  close: number;
  volume?: number;
}

Each indicator only requires the fields it needs. Check TypeScript types for specific requirements.

Use Cases

1. Realtime Trading Bot

import { RSI, MACD, ATR, Hammer } from '@junduck/trading-indi';

const rsi = new RSI({ period: 14 });
const macd = new MACD({ period_fast: 12, period_slow: 26, period_signal: 9 });
const atr = new ATR({ period: 14 });
const hammer = new Hammer();

websocket.on('message', (bar) => {
  const rsiValue = rsi.onData(bar);
  const macdData = macd.onData(bar);
  const atrValue = atr.onData(bar);
  const isHammer = hammer.onData(bar);

  if (rsiValue < 30 && macdData.histogram > 0 && isHammer) {
    placeOrder({
      type: 'BUY',
      stopLoss: bar.close - (atr * 2),
      takeProfit: bar.close + (atr * 3)
    });
  }
});

2. Backtesting Engine

import { useSMA, useEMA, useRSI } from '@junduck/trading-indi';

const getSMA = useSMA({ period: 50 });
const getEMA = useEMA({ period: 20 });
const getRSI = useRSI({ period: 14 });

const results = historicalData.map(bar => ({
  timestamp: bar.timestamp,
  close: bar.close,
  sma50: getSMA(bar.close),
  ema20: getEMA(bar.close),
  rsi: getRSI(bar)
}));

3. Custom Indicator with DAG

import { GraphExec, OpRegistry } from '@junduck/trading-indi';

OpRegistry.registerDefaults();

// Build a custom "Trend Strength" indicator
const graph = new GraphExec('trend-strength');

graph.addNode('close', 'Input', []);
graph.addNode('ema20', 'EMA', ['close'], { period: 20 });
graph.addNode('ema50', 'EMA', ['close'], { period: 50 });
graph.addNode('rsi', 'RSI', ['close'], { period: 14 });
graph.addNode('adx', 'ADX', ['bar'], { period: 14 });

// Calculate trend strength: (EMA20 - EMA50) * RSI/100 * ADX/100
graph.addNode('ema_diff', 'Sub', ['ema20', 'ema50']);
graph.addNode('rsi_norm', 'Div', ['rsi', 100]);
graph.addNode('adx_norm', 'Div', ['adx', 100]);
graph.addNode('strength', 'Mul', ['ema_diff', 'rsi_norm']);
graph.addNode('trend_strength', 'Mul', ['strength', 'adx_norm']);

// Use it
for (const bar of data) {
  graph.update('close', bar.close);
  graph.update('bar', bar);

  const trendStrength = graph.read('trend_strength');
  console.log(`Trend Strength: ${trendStrength}`);
}

4. Multi-Asset Correlation Analysis

import { Corr, Beta } from '@junduck/trading-indi';

const correlation = new Corr({ period: 20 });
const beta = new Beta({ period: 252 });

for (let i = 0; i < assetPrices.length; i++) {
  const corr = correlation.onData(assetPrices[i], benchmarkPrices[i]);
  const betaValue = beta.onData(assetPrices[i], benchmarkPrices[i]);

  console.log(`Correlation: ${corr.correlation}, Beta: ${betaValue.beta}`);
}

Summary

trading-indi provides a complete framework for building incremental trading algorithms:

CategoryCountHighlights
Technical Indicators80+SMA, EMA, RSI, MACD, ATR, BBANDS, ADX, Ichimoku, and more
Pattern Recognition10+Doji, Hammer, Marubozu, Spinning Top, High Wave
Arithmetic Primitives28Add, Sub, Mul, Div, Pow, Sqrt, Log, Clamp, Lerp, SumOf, AvgOf, etc.
Logical Primitives23LT, GT, EQ, And, Or, Not, Between, IfThenElse, AllOf, AnyOf, etc.
Flow System1 DAG engineGraphExec, OpRegistry, Schema validation, JSON serialization

Key Features

  • Incremental Calculation: All operators maintain state and update efficiently
  • High Performance: 2M+ operations/sec, suitable for tick data
  • Memory Efficient: Sliding windows and online algorithms
  • Type Safe: Full TypeScript support with strict typing
  • Composable: Build complex strategies from simple building blocks
  • AI-Friendly: OperatorDoc schema for AI agent code generation
  • Zero Dependencies: Clean, modern TypeScript

Getting Started

  • Simple indicator: Use class-based or hook pattern for individual indicators
  • Pattern recognition: Detect candlestick patterns in realtime
  • Custom calculations: Combine primitives for custom logic
  • Complex strategies: Use DAG flow system to compose multi-indicator strategies
  • Serialization: Save/load strategies as JSON for portability

Changelog

See CHANGELOG.md for a detailed history of changes.

License

MIT

Keywords

trading

FAQs

Package last updated on 09 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts