DocsType Reference
OHLCV Price Data
There is no ctx.series object. OHLCV candle data is exposed as flat number[] arrays directly on ctx, each indexed by bar number.
Structure
interface OnBarContext { readonly open: number[]; // Opening price readonly high: number[]; // Highest price readonly low: number[]; // Lowest price readonly close: number[]; // Closing price readonly volume: number[]; // Trade volume readonly time: number[]; // Unix timestamp (milliseconds) // ...plus ind, order, pos, state - see Context Types }
Usage in onBar
function onBar(ctx, i) { const open = ctx.open[i]; const high = ctx.high[i]; const low = ctx.low[i]; const close = ctx.close[i]; const volume = ctx.volume[i]; // Previous bar const prevClose = ctx.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)- Accessing
ctx.close[i - 1]wheni === 0returnsundefined - Accessing
ctx.close[i + 1]is not possible — future data is never available
Related
seriesOHLCVopenhighlowclosevolumetimestamppricecandle