Trendyways.js: Financial Technical Analysis Demos

Download Back To CSSScript.Com

A JavaScript technical analysis library for stock time series, chart data preparation, trend indicators, and pivot levels.

Loaded module
window.tw
Demo groups
11
The demo scripts did not load. Open this file from the docs folder so trendyways.min.js is available.
Price smoothing

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]);
Close vs MA, EMA, WMAwindow 4
Volatility envelope

Bollinger bands

Upper, middle, and lower bands reveal how far price has moved from its recent average.

Price with upper and lower bandsn 3, k 2

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);
Trend momentum

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;
MACD line, signal, and histogram12 / 26 / 9
Relative strength

RSI

RSI values plotted with common 70 and 30 guide levels for fast reading.

RSI with guide levelsperiod 14

Code demo

const result = tw.rsi(values, 14);
const rsiValues = result.map(row => row.rsi ?? null);
Range position

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);
%K and %D14 / 3
Directional strength

ADX and ATR

ADX, positive and negative directional movement, true range, and average true range on OHLC data.

ADX, DI+, DI-, and ATROHLC sample

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;
Price levels

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");
Price with floor pivot levelsR1 / PL / S1
Method Primary support Pivot or low Primary resistance Secondary resistance
Candle 100% 61.8% 50% 38.2% 23.6% 0%
Volume pressure

OBV, VPT, and MFI

Volume indicators compare price direction, traded volume, and typical price movement.

Volume indicator outputsscaled view

Code demo

const obv = tw.obv(closes, volumes);
const vpt = tw.vpt(closes, volumes);
const mfi = tw.mfi(ohlcv, 14);
Descriptive math

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);
Array operations

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);
Forecast checks

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);