lightweight-charts-indicators

February 27, 2026 · View on GitHub

Live Demo

446 technical analysis indicators for TradingView's lightweight-charts library — 82 standard indicators, 317 community indicators, and 44 candlestick patterns. PineScript v6 compatible with full drawing primitive support (lines, boxes, labels, tables).

Installation

npm install lightweight-charts-indicators oakscriptjs lightweight-charts

Quick Start

import { SMA, RSI, MACD, BollingerBands } from 'lightweight-charts-indicators';
import type { Bar } from 'oakscriptjs';

const bars: Bar[] = [
  { time: 1, open: 100, high: 105, low: 95, close: 102, volume: 1000 },
  // ... more bars
];

// Simple Moving Average
const smaResult = SMA.calculate(bars, { len: 14 });

// RSI
const rsiResult = RSI.calculate(bars, { length: 14 });

// MACD
const macdResult = MACD.calculate(bars, { fastLength: 12, slowLength: 26, signalLength: 9 });

// Bollinger Bands
const bbResult = BollingerBands.calculate(bars, { length: 20, mult: 2 });

Lightweight-Charts Integration Example

Here's a complete example showing how to integrate indicators with TradingView's lightweight-charts:

import { createChart, ColorType, LineSeries, CandlestickSeries } from 'lightweight-charts';
import { SMA, RSI, BollingerBands } from 'lightweight-charts-indicators';
import type { Bar } from 'oakscriptjs';

// Sample OHLCV data
const bars: Bar[] = [
  { time: 1609459200, open: 100, high: 105, low: 98, close: 103, volume: 1000 },
  { time: 1609545600, open: 103, high: 108, low: 101, close: 107, volume: 1200 },
  { time: 1609632000, open: 107, high: 110, low: 104, close: 105, volume: 900 },
  // ... more bars
];

// Create the main chart
const chartContainer = document.getElementById('chart')!;
const chart = createChart(chartContainer, {
  layout: {
    background: { type: ColorType.Solid, color: '#1e1e1e' },
    textColor: '#d1d4dc',
  },
  width: 800,
  height: 400,
});

// Add candlestick series
const candlestickSeries = chart.addSeries(CandlestickSeries);
candlestickSeries.setData(bars.map(bar => ({
  time: bar.time as number,
  open: bar.open,
  high: bar.high,
  low: bar.low,
  close: bar.close,
})));

// Calculate and add SMA overlay
const smaResult = SMA.calculate(bars, { len: 20, src: 'close' });
const smaSeries = chart.addSeries(LineSeries, { color: '#2962FF', lineWidth: 2 });
smaSeries.setData(smaResult.plots.plot0);

// Calculate and add Bollinger Bands
const bbResult = BollingerBands.calculate(bars, { length: 20, mult: 2 });
const bbUpperSeries = chart.addSeries(LineSeries, { color: '#787B86', lineWidth: 1 });
const bbMiddleSeries = chart.addSeries(LineSeries, { color: '#FF6D00', lineWidth: 1 });
const bbLowerSeries = chart.addSeries(LineSeries, { color: '#787B86', lineWidth: 1 });
bbUpperSeries.setData(bbResult.plots.plot0);  // Upper band
bbMiddleSeries.setData(bbResult.plots.plot1); // Basis (middle)
bbLowerSeries.setData(bbResult.plots.plot2);  // Lower band

// Create a separate pane for RSI (oscillator)
const rsiContainer = document.getElementById('rsi-chart')!;
const rsiChart = createChart(rsiContainer, {
  layout: {
    background: { type: ColorType.Solid, color: '#1e1e1e' },
    textColor: '#d1d4dc',
  },
  width: 800,
  height: 150,
});

const rsiResult = RSI.calculate(bars, { length: 14, src: 'close' });
const rsiSeries = rsiChart.addSeries(LineSeries, { color: '#7E57C2', lineWidth: 2 });
rsiSeries.setData(rsiResult.plots.plot0);

// Sync the time scales
chart.timeScale().subscribeVisibleLogicalRangeChange(range => {
  if (range) rsiChart.timeScale().setVisibleLogicalRange(range);
});

Available Indicators (446)

Moving Averages

IndicatorExportDescription
Simple Moving AverageSMAArithmetic mean over a specified period
Exponential Moving AverageEMAWeighted average giving more weight to recent prices
Weighted Moving AverageWMALinearly increasing weights
Smoothed Moving Average (RMA)RMAWilder smoothing (alpha = 1/length)
Double EMADEMAReduces lag by applying EMA twice
Triple EMATEMAFurther reduces lag with triple exponential smoothing
Hull Moving AverageHMAReduces lag while maintaining smoothness
Least Squares Moving AverageLSMAUses linear regression to fit a line
Arnaud Legoux Moving AverageALMAGaussian distribution to reduce lag
Volume Weighted Moving AverageVWMAMoving average weighted by volume
Smoothed Moving AverageSMMAWilder smoothing moving average
McGinley DynamicMcGinleyDynamicAdaptive moving average that adjusts to market speed
MA CrossMACrossTwo moving averages for crossover signals
Moving Average RibbonMARibbonMultiple MAs showing trend direction and momentum
Zero Lag LSMAZLSMADouble linreg to cancel LSMA lag

Oscillators

IndicatorExportDescription
Relative Strength IndexRSIMomentum oscillator (0-100) measuring price changes
StochasticStochasticCompares closing price to price range
Stochastic RSIStochRSIStochastic applied to RSI values
Commodity Channel IndexCCIMeasures variation from statistical mean
Williams %RWilliamsPercentRangeMomentum showing overbought/oversold levels
Awesome OscillatorAwesomeOscillatorMarket momentum using SMA difference
Chande Momentum OscillatorChandeMOMomentum on a scale of -100 to +100
Detrended Price OscillatorDPORemoves trend to identify cycles
Relative Vigor IndexRVIMeasures conviction of price action
SMI Ergodic IndicatorSMIErgodicTSI-based momentum with signal line
SMI Ergodic OscillatorSMIErgodicOscillatorSMI minus signal as histogram
True Strength IndexTSIDouble-smoothed momentum oscillator
Woodies CCIWoodiesCCICCI with turbo for faster signals
Bollinger Bands %BBBPercentBPrice position relative to BB (0=lower, 1=upper)
Fisher TransformFisherTransformGaussian distribution for clearer turning points
Ultimate OscillatorUltimateOscillatorMulti-timeframe weighted momentum
Rank Correlation IndexRCICorrelation between price rank and time rank
RCI RibbonRCIRibbonMultiple RCI lines for trend visualization
Relative Volatility IndexRelativeVolatilityIndexVolatility-based oscillator
Chop ZoneChopZoneColored zone indicator for market choppiness
CCT Bollinger Band OscillatorCCTBBONormalized BB position (0-100) with signal line
KDJKDJExtended Stochastic with J line (3K - 2D)
WaveTrendWaveTrendChannel index oscillator with cross signals
Forecast OscillatorForecastOscillatorPercentage deviation from linear regression
Schaff Trend CycleSchaffTrendCycleDouble stochastic smoothing of MACD

Momentum

IndicatorExportDescription
MACDMACDRelationship between two EMAs
MomentumMomentumRate of change of price
Rate of ChangeROCPercentage change over a period
Balance of PowerBOPStrength of buyers vs sellers
Bull Bear PowerBullBearPowerBuying/selling pressure relative to EMA
Elder Force IndexElderForceIndexCombines price and volume
Price Oscillator (PPO)PriceOscillatorMACD as percentage for comparison
Coppock CurveCoppockCurveLong-term momentum using ROC and WMA
TRIXTRIXTriple EMA rate of change, filters noise
Connors RSIConnorsRSIComposite of RSI, streak, and percentile rank
KSTKSTKnow Sure Thing - weighted ROC sum
MACD 4CMACD4CMACD histogram with 4-color coding
Squeeze MomentumSqueezeMomentumBB/KC squeeze with momentum oscillator
Impulse MACDImpulseMACDZLEMA vs SMMA channel impulse

Trend

IndicatorExportDescription
Average Directional IndexADXMeasures trend strength regardless of direction
Directional Movement IndexDMI+DI, -DI, and ADX for trend direction/strength
Ichimoku CloudIchimokuCloudComprehensive trend system with support/resistance
Parabolic SARParabolicSARTrend-following with entry/exit points
SupertrendSupertrendATR-based dynamic support/resistance
AroonAroonTrend strength by time since high/low
BBTrendBBTrendMeasures trend using Bollinger Bands
Choppiness IndexChoppinessMarket choppiness vs trending
Mass IndexMassIndexIdentifies reversals via high-low range
Vortex IndicatorVortexIndicatorIdentifies trend start and direction
Williams AlligatorWilliamsAlligatorThree smoothed MAs for trend detection
Zig ZagZigZagConnects pivot highs and lows
Trend Strength IndexTrendStrengthIndexTrend strength based on directional movement
Chande Kroll StopChandeKrollStopATR-based trailing stop system
Williams FractalsWilliamsFractalsIdentifies reversal points in price
Moon PhasesMoonPhasesNew and full moon markers
TWAPTWAPTime-weighted average price
Coral TrendCoralTrendCascaded EMA filter for smooth trend detection
Chandelier ExitChandelierExitATR-based trailing stop system
Donchian Trend RibbonDonchianTrendRibbonMulti-layer Donchian breakout composite score

Volatility

IndicatorExportDescription
Average True RangeATRAverage range between high and low
Average Day RangeADRAverage daily price range
Standard DeviationStandardDeviationMeasures price volatility
Historical VolatilityHistoricalVolatilityAnnualized standard deviation of log returns
Bollinger BandWidthBBBandWidthWidth of Bollinger Bands as percentage
Bollinger BarsBollingerBarsColored candles based on BB position

Channels & Bands

IndicatorExportDescription
Bollinger BandsBollingerBandsVolatility bands using standard deviation
Keltner ChannelsKeltnerChannelsVolatility envelope using EMA and ATR
Donchian ChannelsDonchianChannelsHighest high and lowest low over period
EnvelopeEnvelopeMoving average with fixed percentage bands
MedianMedianMedian price with ATR bands

Volume

IndicatorExportDescription
On Balance VolumeOBVCumulative volume based on price direction
Money Flow IndexMFIVolume-weighted RSI
Price Volume TrendPVTCumulative volume weighted by price changes
Volume OscillatorVolumeOscillatorPercentage difference between volume EMAs
Chaikin Money FlowChaikinMFBuying/selling pressure using price and volume
Chaikin OscillatorChaikinOscillatorMomentum of Accumulation/Distribution line
Ease of MovementEaseOfMovementPrice change relative to volume
Klinger OscillatorKlingerOscillatorVolume-based long-term money flow
Net VolumeNetVolumeDifference between up and down volume
Volume DeltaVolumeDeltaDifference between buying and selling volume
Cumulative Volume DeltaCumulativeVolumeDeltaRunning total of volume delta
Relative Volume at TimeRelativeVolumeAtTimeCurrent volume vs historical average
Colored Volume BarsColoredVolumeVolume colored by price/volume trend
OBV MACDOBVMACDMACD applied to On Balance Volume

Community Indicators (317)

317 community indicators ported from TradingView PineScript sources, covering trend systems, divergence detectors, multi-MA strategies, volume analysis, market structure, and more. Full list in docs/INDICATOR_INVENTORY_COMMUNITY.md.

Categories include: Hyper Trend, AlphaTrend, HalfTrend, QQE MOD, Hull Suite, SuperTrend variants, Market Structure Trailing Stop, Liquidity Levels, Order Blocks, ZigZag Fibonacci, Trendlines with Breaks, and many more.

Drawing primitive support: Lines (LineDrawingData), Boxes (BoxData), Labels (LabelData), Tables (TableData), Markers, Bar Colors, Background Colors, and Plot Candles.

Candlestick Patterns (44)

All 44 patterns from TradingView's standard candlestick pattern library, rendered as chart markers.

PatternSignalCandles
Abandoned BabyBullish / Bearish3
Dark Cloud CoverBearish2
DojiNeutral1
Doji StarBullish / Bearish2
Downside Tasuki GapBearish3
Dragonfly DojiBullish1
EngulfingBullish / Bearish2
Evening Doji StarBearish3
Evening StarBearish3
Falling Three MethodsBearish5
Falling WindowBearish2
Gravestone DojiBearish1
HammerBullish1
Hanging ManBearish1
HaramiBullish / Bearish2
Harami CrossBullish / Bearish2
Inverted HammerBullish1
KickingBullish / Bearish2
Long Lower ShadowBullish1
Long Upper ShadowBearish1
Marubozu BlackBearish1
Marubozu WhiteBullish1
Morning Doji StarBullish3
Morning StarBullish3
On NeckBearish2
PiercingBullish2
Rising Three MethodsBullish5
Rising WindowBullish2
Shooting StarBearish1
Spinning Top BlackNeutral1
Spinning Top WhiteNeutral1
Three Black CrowsBearish3
Three White SoldiersBullish3
Tri-StarBullish / Bearish3
Tweezer BottomBullish2
Tweezer TopBearish2
Upside Tasuki GapBullish3

Output Format

All indicators return an IndicatorResult object:

interface IndicatorResult {
  metadata: {
    title: string;
    shortTitle: string;
    overlay: boolean;  // true = display on price chart, false = separate pane
  };
  plots: {
    plot0: Array<{ time: number; value: number }>;
    plot1?: Array<{ time: number; value: number }>;
    // ... additional plots as needed
  };
}

Indicator Registry

For dynamic indicator selection (e.g., building a UI), use the indicatorRegistry:

import { indicatorRegistry } from 'lightweight-charts-indicators';

// List all indicators
indicatorRegistry.forEach(indicator => {
  console.log(`${indicator.name} (${indicator.category})`);
});

// Get indicator by ID
const sma = indicatorRegistry.find(i => i.id === 'sma');
const result = sma?.calculate(bars, sma.defaultInputs);

// Filter by category
const oscillators = indicatorRegistry.filter(i => i.category === 'Oscillators');

Building

npm run build

Testing

npm test

License

MIT