ChartnautDocs

Summaries and long windows

ctx.summary answers "what was the highest high, lowest low, first open, last close or total volume over this span" without loading the span's bars. Use it for all-time highs, 52-week ranges and last month's levels.

A script asks history two kinds of question:

  • A fold walks bars in order: an EMA, a zone list, a swing structure. It needs the bars, so its depth is a warmup count, capped by your plan's memory. See Timeframe handles and runOn.

  • A reduce wants one answer over a span. ctx.summary answers it from native history, and the answer is the same size whether the span is a week or a decade.

Raising warmup to find a maximum is the mistake this page exists to prevent. Two years of 5-minute bars is about 200,000 rows, far past any plan's memory, to produce one number.

ctx.summary(timeframe, window)

const all   = ctx.summary("1d", { since: "all" });             // everything available
const yr    = ctx.summary("1h", { since: "52w" });             // rolling year
const mtd   = ctx.summary("4h", { since: "month" });           // month to date
const lastM = ctx.summary("1d", { period: "month", back: 1 }); // last month, complete
const fromD = ctx.summary("5m", { since: "2026-01-01" });      // from a date

Window

Meaning

{ since: "all" }

Everything your plan and the instrument allow

{ since: "30d" }

A duration back: m, h, d or w

{ since: "2026-01-01" }

From that UTC midnight

{ since: "month" }

The current period to date. Also "day", "week", "quarter", "year"

{ period, back }

A whole previous period. back: 1 is the last complete one

Calendar arithmetic is UTC and weeks start Monday. A duration of a day or more starts at the UTC midnight on or before the start it names; from in the result reports the real start. Shorter durations are exact.

Both arguments must be known before the script runs: a timeframe literal or an input.timeframe-backed ctx.params.<id>, and an object literal window. Lint enforces it with summary/missing-window, summary/untyped-window and summary/invalid-window. timeframe may be the chart's own or any higher one. A lower timeframe reads undefined and records an error.

A summary needs no warmup(...) or retain(...). The runtime sees each ctx.summary call and loads what it needs.

What it returns

{ maxHigh, minLow, firstOpen, lastClose, sumVolume, from, to, truncated, reason? } | undefined

Only quantities that come out the same however the span is split: the maximum of a week is the maximum of its days. That is why there is no bar count and no price-times-volume sum. An anchored VWAP over a long span is not a summary question.

to is the end of the last closed bucket of timeframe at or before the current bar, so a summary never includes the forming bucket or the current bar. Add them yourself for "including right now":

const all = ctx.summary("1d", { since: "all" });
const ath = Math.max(all?.maxHigh ?? -Infinity, ctx.high);
ctx.hline("ath", ath);
if (all?.truncated) ctx.log.warn(`high since ${all.from}`); // not an all-time high

It is undefined before the first bucket of timeframe has closed, and on a lower-timeframe read. Guard for it.

Truncation

truncated is true when history could not reach the window's start. reason says why:

reason

Means

plan

Your plan's history window stops there

instrument

The instrument's first available bar

floor

The platform's data floor, 2 February 2015

When the history on your device does not reach far enough back, Chartnaut asks the server for the older part once. Until the answer arrives the value is defined but truncated, and the indicator shows as waiting; when it lands, the script runs again. Offline, the local answer stands, marked truncated. Read truncated either way before you call a number "all-time".

Where the answer comes from

The span's body is served from whole UTC days of daily history, and only the ragged ends from bars of timeframe. So a 52-week window at 5m costs a few hundred rows, not 75,000, and the maximum is the same number. A window whose start moves every bar, such as a rolling since: "30d" replayed over history, is answered from the history already loaded for past bars; only the current window is asked of the server.

Inside a timeframe handler, ctx.summary resolves as of the end of the bucket being handled.

Recipes

// 52-week position, any chart timeframe
const yr = ctx.summary("1d", { since: "52w" });
if (yr) ctx.plot("pos52w", (ctx.close - yr.minLow) / (yr.maxHigh - yr.minLow));

// Last month's range as levels
const m = ctx.summary("1d", { period: "month", back: 1 });
if (m) { ctx.hline("mHigh", m.maxHigh); ctx.hline("mLow", m.minLow); }

// Drawdown from this year's high
const y = ctx.summary("1d", { since: "year" });
if (y) ctx.plot("ddFromYtdHigh", (ctx.close - y.maxHigh) / y.maxHigh);

ctx.hline(id, price) here draws a chart-wide line, so declare those ids with output.priceLine.