chart-patterns

chart-patterns

npm version GitHub license

TypeScript library that provides technical analysis for volume-based indicators and uses peak detection algorithms to generate pattern-based indicators.

📊 Market & Volume Distribution

Tool Description
Market Profile Generates TPO profiles with Value Area, Initial Balance, and Point of Control.
Volume Profile Generate Volume Profiles to find the Value Area. Process either Kline or tick data to build these profiles.

🧭 Z-Score Tools for Ranges & Swings

Tool Description
Peak Detector Z-Score-based Peak Detector to find swing highs and lows.
Range Finder Finds key support and resistance zones from price swings.
Zigzags Highlights major price swings only.
Zscore Measures how far price deviates from the mean — useful for spotting extremes.

🔍 Orderflow

Requires raw trade data. More information can be found in my blog post here.

Tool Description
Stacked Imbalances Finds clusters of aggressive buying or selling — potential turning points.
High Volume Node Highlights price levels with exceptionally high traded volume.

⚙️ General Indicators

Tool Description
EMA Exponential Moving Average — a weighted moving average that reacts quickly to price.
MFI Money Flow Index — Volume-based oscillator showing buy/sell pressure.
Pivot Points Calculates pivot, support, and resistance levels.
RSI Relative Strength Index — Measures momentum to spot overbought/oversold.
SMA Simple Moving Average — Simple average of price over a period.
Stochastic RSI Tracks RSI momentum shifts.
VWAP Average price weighted by volume.

🕯️ Candlestick Patterns

Pattern Description
Doji Signals indecision — open and close are nearly equal.
Engulfing Reversal pattern where one candle fully engulfs the previous.
Excess Detects large wicks, suggesting rejection from highs or lows.
Harami Small candle inside a larger one — potential reversal.
Homing Pigeon Two small-bodied candles in a downtrend — possible bullish reversal.
Inverted Hammer Small body with long upper wick — potential bullish reversal.
Marubozu Full-body candle with no wicks — strong directional move.
Morning Star / Evening Star Three-candle reversal pattern — bullish (morning) or bearish (evening).

Usage

import * as ta from 'chart-patterns';
import { IMarketProfile, ILocalRange, IZScoreConfig } from 'chart-patterns/dist/types';
import { MARKET_PROFILE_PERIODS, SIGNAL_DIRECTION } from 'chart-patterns/dist/constants';

// Market Profile
const marketProfiles: IMarketProfile[] = ta.MarketProfile.build({
candles,
candleGroupingPeriod: MARKET_PROFILE_PERIODS.DAILY,
tickSize: 0.1,
pricePrecision: 2,
tickMultiplier: 100,
timezone: 'Europe/London'
});

// Volume Profile - Session-based API
// Create a session for candle-based volume profile
const volumeProfileBarSession = ta.VolumeProfile.createBarSession({
valueAreaRowSize: 24,
valueAreaVolume: 0.7,
pricePrecision: 2
});

// Process candles one by one
for (const candle of candles) {
volumeProfileBarSession.processCandle(candle);
}

// Get value area and distribution results
const valueArea = barSession.getValueArea();
const distribution = barSession.getVolumeDistribution();

// For raw trade data - even more precision
const volumeProfileTickSession = ta.VolumeProfile.createTickSession();
// Process each individual trade
for (const trade of trades) {
volumeProfileTickSession.processTrade(trade);
}
// Get detailed trade analysis with exact price levels
const tickDistribution = volumeProfileTickSession.getVolumeDistribution();

// Money Flow Index - volume-based momentum oscillator
const mfiValues = ta.MFI.calculateMFI(candles, 14);

// RSI and Stochastic RSI
const rsiValues = ta.RSI.calculateRSI(candles, 14);
const stochRsiResult = ta.RSI.calculateStochasticRSI(candles, 14, 14, 3, 3);

// Z-Score configuration for peak/pattern detection algorithms
const zScoreConfig: IZScoreConfig = {
lag: 2, // Controls smoothing and adaptability to trend changes
threshold: 0.1, // Number of standard deviations to classify a signal
influence: 1 // How strongly signals affect future calculations (0-1)
};

const ranges: ILocalRange[] = ta.RangeBuilder.findRanges(candles, zScoreConfig);

// Create zigzag points for pattern recognition
const zigzags = ta.ZigZags.create(candles, zScoreConfig);

// Candlestick Pattern Detection - Excess (large wicks indicating rejection)
const excessDirection: SIGNAL_DIRECTION = ta.CandlestickPatterns.getCandleExcessDirection(candles[0]);
// Returns: SIGNAL_DIRECTION.BULLISH (long lower wick), BEARISH (long upper wick),
// BIDIRECTIONAL (both), or NONE

// Process multiple candles for excess patterns
const excessSignals = candles.map(candle => ({
timestamp: candle.timestamp,
direction: ta.CandlestickPatterns.getCandleExcessDirection(candle)
})).filter(signal => signal.direction !== ta.SIGNAL_DIRECTION.NONE);

Visualisations

Market Profile Output

Market Profile visualization showing TPO distribution with Value Area, POC, and VAH/VAL highlighted

Range Detection Output

Range detection visualization showing support and resistance levels identified on BTC/USDT price action

Generated using TypeDoc