chart-patterns
v1.0.26
Published
Trading Chart Patterns
Downloads
193
Readme
chart-patterns
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 | |------|-------------| | Divergences | Detects bullish/bearish divergences between price and indicators (MFI, RSI). | | 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, IDivergence } 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
candles.forEach((candle) => 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);
const zScoreConfigDivergences: IZScoreConfig = {
lag: 3,
threshold: 1,
influence: 0.75
};
// Divergence Detection - Find divergences between price and indicators
const mfiDivergences: IDivergence[] = ta.Divergences.mfi(candles, zScoreConfigDivergences, 14);
const rsiDivergences: IDivergence[] = ta.Divergences.rsi(candles, zScoreConfigDivergences, 14);
// Candlestick Pattern Detection - Excess (large wicks indicating rejection)
const excessDirection: SIGNAL_DIRECTION = ta.CandlestickPatterns.getCandleExcessDirection(candles[0]);
