Skip to content

Financial

Session-anchored intraday

Hourly bars that start at the 09:30 open rather than at 10:00, with pre-market and after-hours kept in phase.

Session-anchored intraday@ortex-charts/financial@ortex-charts/math
Loading session-anchored intraday
Hourly bars that start at the 09:30 open rather than at 10:00, with pre-market and after-hours kept in phase.
intraday-session.ts
import { createFinancialChart } from "@ortex-charts/financial";
import { aggregateBars, anchoredResolution, barSeriesFromRows, barSeriesToRows, parseResolution } from "@ortex-charts/math";

// The regular session of a United States equity. Pre-market from 04:00 and
// after-hours to 20:00 are in the data and stay on the same grid.
const SESSION = "0930-1600";
const HOURLY = parseResolution("60");

const prints = barSeriesFromRows(rows);
// Two aggregations of the same prints: one anchored to the session open,
// one on the plain clock grid.
const anchored = barSeriesToRows(aggregateBars(prints, anchoredResolution(HOURLY, SESSION), TIME_ZONE));
const clockAligned = barSeriesToRows(aggregateBars(prints, HOURLY, TIME_ZONE));

const chart = createFinancialChart(box, {
    theme,
    timeZone: TIME_ZONE,
    resolution: "60",
    // The chart anchors its own bar boundaries, axis labels and crosshair to
    // the same session. A datafeed sets this from `SymbolInfo.session`.
    session: SESSION,
    volume: false, // This sample feed carries prices without sizes.
    data: anchored,
});

/** Switch the anchor off and the first hour of the day becomes 10:00 again. */
function setAnchored(on: boolean): void {
    chart.chart.applyOptions({ session: on ? SESSION : "" });
    chart.setData(on ? anchored : clockAligned);
}