DocsStrategy APIseries

ctx.series

Access historical price and volume data.

Available Series

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

Accessing Data

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

Common Patterns

Bar range

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

Bullish/bearish bar

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

Price change

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

Volume analysis

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

New high/low detection

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

Related

seriespriceohlcvcandleqsl