Moving averages
Simple, exponential, and weighted averages calculated from the same closing-price series.
Code demo
const series = [{ c: 2 }, { c: 6 }, { c: 5 }, { c: 7 }, { c: 10 }, { c: 9 }, { c: 12 }, { c: 5 }];
const ma = tw.ma(series, 4);
const ema = tw.ema(series, 4, "c");
const wma = tw.wma(series, [0.6, 0.3, 0.1]);
Bollinger bands
Upper, middle, and lower bands reveal how far price has moved from its recent average.
Code demo
const series = [{ c: 2.1 }, { c: 4.3 }, { c: 4.5 }, { c: 4.8 }, { c: 5.0 }, { c: 5.8 }, { c: 7.1 }, { c: 9.1 }];
const bands = tw.bollinger(series, 3, 2);
MACD
MACD line, signal line, and histogram values from a longer closing-price sample.
Code demo
const series = closes.map(c => ({ c }));
const result = tw.macd(series);
const last = result[result.length - 1].macd;
RSI
RSI values plotted with common 70 and 30 guide levels for fast reading.
Code demo
const result = tw.rsi(values, 14); const rsiValues = result.map(row => row.rsi ?? null);
Stochastic oscillator
%K and %D show where the latest close sits within the recent high-low range.
Code demo
const highs = candles.map(row => row.h); const lows = candles.map(row => row.l); const closes = candles.map(row => row.c); const result = tw.stochastic(highs, lows, closes, 14, 3);
ADX and ATR
ADX, positive and negative directional movement, true range, and average true range on OHLC data.
Code demo
const adx = tw.adx(candles); const atr = tw.atr(candles); const lastAdx = adx[adx.length - 1].adx; const lastAtr = atr[atr.length - 1].at.atr;
Support and resistance
Floor pivots, Camarilla, Woodie's, Tom DeMark, and Fibonacci retracements from compact OHLC inputs.
Code demo
const floor = tw.floorPivots([{ c: 15, h: 18, l: 5 }]);
const cam = tw.camarillaPoints(points);
const wood = tw.woodiesPoints(points);
const tom = tw.tomDemarksPoints(points);
const fibs = tw.fibonacciRetrs(points, "UPTREND");
| Method | Primary support | Pivot or low | Primary resistance | Secondary resistance |
|---|
| Candle | 100% | 61.8% | 50% | 38.2% | 23.6% | 0% |
|---|
OBV, VPT, and MFI
Volume indicators compare price direction, traded volume, and typical price movement.
Code demo
const obv = tw.obv(closes, volumes); const vpt = tw.vpt(closes, volumes); const mfi = tw.mfi(ohlcv, 14);
Statistics
Basic descriptive functions for numeric arrays and object-based series.
Code demo
const values = [2, 6, 5, 7, 10, 9, 12, 5]; tw.max(values); tw.min(values); tw.mean(values); tw.sd(values);
Vector operations
Element-wise operations and scalar summaries for small numeric vectors.
Code demo
const a = [5, 3, 8]; const b = [2, 1, 6]; tw.diffVectors(a, b); tw.divVector(a, b); tw.powVector(a); tw.absVector([-1, -2, 3]); tw.sumVector(a); tw.avgVector(a); tw.combineVectors(a, b, (x, y) => x * y);
Error metrics
MSE, RMSE, and MAE compare predicted series with observed values.
Code demo
const actual = [1.2, 3.4, -7.8, 2.3, 8.9, 5]; const predicted = [2.2, 8.4, 7.8, -2.3, -8.9, 5.1]; tw.mse(actual, predicted); tw.rmse(actual, predicted); tw.mae(actual, predicted);