Series & ta.*
A Series is a per-bar value with history. Index it current-first (close[1] is the previous bar). Because JS can’t overload operators, use the chainable math methods.
// 'close' is a Series: a per-bar value WITH history, indexed current-first.
const now = close[0]; // newest bar's close (same as close.value)
const prev = close[1]; // the bar before it (same as close.at(1))
const ema = ta.ema(close, 20); // a Series (full history): plot it or chain it
// JS can't overload + - * /, so use chainable methods (each returns a Series):
const body = close.sub(open); // close - open
const upBar = close.gt(open); // 1/0 series (is this an up bar?)
const dir = close.gt(open).iff(1, -1); // per-bar ternary
const prevS = close.offset(1); // close[1] as a Series
// Functions with several outputs return an object:
const { upper, middle, lower } = ta.bbands(close, 20, 2);
const { macd, signal, histogram } = ta.macd(close, 12, 26, 9);
plot(ema, { title: 'EMA 20' });The ta.* library
The ta.* library covers the usual suspects, including sma ema rma wma hma rsi macd bbands stoch supertrend atr adx vwap cci mfi and many more, all returning history-aware Series. The full list is under ta.* functions.