DocsType Reference
Series (OHLCV)
The ctx.series object provides all candle data for the backtest period. Each property is a number[] array indexed by bar number.
Structure
interface Series { open: number[]; // Opening price high: number[]; // Highest price low: number[]; // Lowest price close: number[]; // Closing price volume: number[]; // Trade volume timestamp: number[]; // Unix timestamp (milliseconds) length: number; // Total number of bars }
Usage in onBar
function onBar(ctx, i) { const open = ctx.series.open[i]; const high = ctx.series.high[i]; const low = ctx.series.low[i]; const close = ctx.series.close[i]; const volume = ctx.series.volume[i]; // Previous bar const prevClose = ctx.series.close[i - 1]; // Price range const range = high - low; // Candle body const body = Math.abs(close - open); const isBullish = close > open; }
Composite Prices
Some indicators accept a source option. The engine computes these automatically:
| Source | Formula |
|---|---|
'open' | Open price |
'high' | High price |
'low' | Low price |
'close' | Close price (default) |
'hl2' | (High + Low) / 2 |
'hlc3' | (High + Low + Close) / 3 |
'ohlc4' | (Open + High + Low + Close) / 4 |
'volume' | Volume |
Bounds Checking
istarts at 0 (first bar)ctx.series.lengthis the total number of bars- Accessing
ctx.series.close[i - 1]wheni === 0returnsundefined - Accessing
ctx.series.close[i + 1]is not possible — future data is never available
Related
seriesOHLCVopenhighlowclosevolumetimestamppricecandle