DocsStrategy APIseries

OHLCV Price Data

Historical price and volume data is available as flat arrays directly on ctx - there is no ctx.series object.

Available Series

PropertyTypeDescription
ctx.opennumber[]Opening prices
ctx.highnumber[]High prices
ctx.lownumber[]Low prices
ctx.closenumber[]Closing prices
ctx.volumenumber[]Volume

Accessing Data

function onBar(ctx, i) { // Current bar 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 bars const prevClose = ctx.close[i - 1]; const close5ago = ctx.close[i - 5]; }

Common Patterns

Bar range

const range = ctx.high[i] - ctx.low[i]; const bodySize = Math.abs(ctx.close[i] - ctx.open[i]);

Bullish/bearish bar

const isBullish = ctx.close[i] > ctx.open[i]; const isBearish = ctx.close[i] < ctx.open[i];

Price change

if (i > 0) { const change = ctx.close[i] - ctx.close[i - 1]; const changePercent = change / ctx.close[i - 1] * 100; }

Volume analysis

const avgVolume = q.avg(ctx.volume, 20, i); const volumeRatio = ctx.volume[i] / avgVolume; if (volumeRatio > 2) { // Volume spike - 2x average }

New high/low detection

const highest20 = q.highest(ctx.high, 20, i - 1); const lowest20 = q.lowest(ctx.low, 20, i - 1); if (ctx.high[i] > highest20) { // New 20-bar high } if (ctx.low[i] < lowest20) { // New 20-bar low }

Boundary Checks

Always check bounds when accessing previous bars:

function onBar(ctx, i) { if (i < 20) return; // Need 20 bars of history const ma20 = q.avg(ctx.close, 20, i); }

Related

seriespriceohlcvcandleqsl