oakscriptjs 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/session/context.ts"],
4
- "sourcesContent": ["/**\n * The session of a chart context, for code that does not run a whole script (a port with its own bar loop).\n *\n * The same values as the script API gives (`time(tf)`, `time_close(tf)`, `time_tradingday`, `session.*`, the periods\n * of `request.security`), from the session, corrections and holidays of the context. Bar times are in the unit of\n * the context (`timeUnit`, seconds by default, as `Bar.time`); PineScript time values are returned in ms.\n *\n * @module session/context\n */\n\nimport type { Bar } from '../types/index.js';\nimport { info, in_seconds } from '../timeframe/index.js';\nimport { afterCompletion, periodsOf, resample } from '../security/resample.js';\nimport { parsePineSession, sessionRun } from '../time/session.js';\nimport { SessionBars, sessionFlags, strayPeriods, type SessionFlags } from './bars.js';\nimport { TradingCalendar, type SessionSpec } from './calendar.js';\n\n/** The part of a chart context that the session functions read (a `ChartContext` of the script API fits). */\nexport interface SessionContext {\n /** Chart timeframe: \"5\", \"60\", \"1D\"... */\n timeframe?: string;\n /** Exchange time zone: \"America/New_York\", \"Etc/UTC\"... */\n timezone?: string;\n /** Session of the loaded bars: hours, corrections, holidays */\n session?: SessionSpec | string;\n /** Regular trading hours when the bars include extended hours (default: `session`) */\n regularSession?: SessionSpec | string;\n /** Unit of the bar times: 's' (default) or 'ms' */\n timeUnit?: 's' | 'ms';\n}\n\n/** The session calendars of a context: the loaded bars and the regular hours. */\nexport interface ChartSessions {\n bars: SessionBars;\n regular: SessionBars;\n /** ms per unit of the bar times */\n unit: number;\n}\n\nconst toSpec = (s: SessionSpec | string): SessionSpec => (typeof s === 'string' ? { session: s } : s);\nconst cache = new WeakMap<object, ChartSessions>();\n\n/**\n * Session calendars of a chart context (cached per context object).\n * @throws Error when the context has no timeframe, time zone or session\n */\nexport function chartSessions(chart: SessionContext): ChartSessions {\n const cached = cache.get(chart);\n if (cached) return cached;\n const { timeframe, timezone, session } = chart;\n if (!timeframe || !timezone || !session) {\n throw new Error('The chart context needs timeframe, timezone and session for the session functions.');\n }\n const loaded = toSpec(session);\n const regular = chart.regularSession ? toSpec(chart.regularSession) : loaded;\n const out: ChartSessions = {\n bars: new SessionBars(new TradingCalendar(timezone, loaded), timeframe),\n regular: new SessionBars(new TradingCalendar(timezone, { holidays: loaded.holidays, ...regular }), timeframe),\n unit: chart.timeUnit === 'ms' ? 1 : 1000,\n };\n cache.set(chart, out);\n return out;\n}\n\n/** Open and close (ms) of the period that contains a bar opening at a time in ms; NaN outside the session. */\nexport interface SessionPeriods {\n open: (time: number) => number;\n close: (time: number) => number;\n}\n\n/** Calendars of the `session` / `timezone` arguments before the cache restarts */\nconst MAX_ARGUMENT_CALENDARS = 64;\nconst argumentCalendars = new Map<string, TradingCalendar>();\n\n/**\n * Calendar of a session string read in a time zone, without corrections and holidays: it depends on these only, so\n * the calls with other timeframes or other chart contexts share it and its periods (a script often reads\n * `time(timeframe.period, s)` and `time(\"D\", s)` on every bar).\n */\nfunction argumentCalendar(timezone: string, session: string, rule: 'symbol' | 'pine', dayPlacement: boolean): TradingCalendar {\n const key = `${rule}|${dayPlacement}|${timezone}|${session}`;\n let calendar = argumentCalendars.get(key);\n if (!calendar) {\n calendar = new TradingCalendar(timezone, { session }, rule, dayPlacement);\n if (argumentCalendars.size >= MAX_ARGUMENT_CALENDARS) argumentCalendars.clear();\n argumentCalendars.set(key, calendar);\n }\n return calendar;\n}\n\n/**\n * Calendar for the `session` / `timezone` arguments of `time(tf, session, timezone)`. Without both: the loaded\n * session. As in PineScript, an explicit time zone reads the symbol session hours in that zone without corrections\n * and holidays, and an explicit session follows PineScript's session string rules.\n */\nfunction calendarFor(\n bars: SessionBars,\n chart: SessionContext,\n session: string | undefined,\n timezone: string | undefined,\n dayPlacement: boolean\n): { bars: SessionBars; test: boolean; inside?: (time: number) => boolean } {\n if (!session && !timezone) return { bars, test: false };\n const tz = timezone ?? chart.timezone!;\n // a session string that is empty or does not start with a digit is the symbol session: \"regular\" the regular\n // hours, \"extended\" and any other name the loaded hours (PineScript)\n if (session !== undefined && parsePineSession(session) === null) {\n const name = session.trim();\n const symbol = name === 'regular' && chart.regularSession ? chart.regularSession : chart.session!;\n return { bars: new SessionBars(argumentCalendar(tz, toSpec(symbol).session, 'symbol', false), bars.chart.period), test: true };\n }\n return {\n bars: new SessionBars(\n argumentCalendar(tz, session || toSpec(chart.session!).session, session ? 'pine' : 'symbol', dayPlacement),\n bars.chart.period\n ),\n test: true,\n // a PineScript session string: the rules of time.inSession (runs ending at 0000, days around a clock change)\n inside: session ? (time) => sessionRun(time, session, tz, in_seconds(bars.chart.period) * 1000) !== null : undefined,\n };\n}\n\n/**\n * `time(tf, session, timezone)` / `time_close(tf, session, timezone)` of a bar, as PineScript computes them (#173):\n * an intraday timeframe tests the bar with the session rules of time.inSession and aligns its periods on the start\n * of the run that contains the bar; \"D\" tests the bar against the day's session period (the calendar; the time\n * between two runs of a day is inside it, #182); a timeframe of more than one day (\"2D\", \"W\", \"M\") has no test and\n * keeps the period's time. `bars` is the calendar of the loaded session (`chartSessions(chart).bars`).\n */\nexport function sessionPeriods(\n bars: SessionBars,\n chart: SessionContext,\n timeframe: string,\n session?: string,\n timezone?: string\n): SessionPeriods {\n const tf = info(timeframe);\n const { bars: calendar, test, inside } = calendarFor(bars, chart, session, timezone, !tf.isintraday);\n const open = (t: number): number => calendar.timeOf(t, timeframe);\n const close = (t: number): number => calendar.closeOf(t, timeframe);\n if (!test) return { open, close };\n if (tf.isintraday) {\n if (session !== undefined && parsePineSession(session) !== null && !calendar.chart.isdwm) {\n const tz = timezone ?? chart.timezone!;\n const barMs = in_seconds(calendar.chart.period) * 1000;\n const ms = in_seconds(tf.period) * 1000;\n const run = (t: number) => sessionRun(t, session, tz, barMs);\n const start = (t: number, r: [number, number]) => r[0] + Math.floor((t - r[0]) / ms) * ms;\n return {\n open: (t) => { const r = run(t); return r ? start(t, r) : NaN; },\n close: (t) => { const r = run(t); return r ? Math.min(start(t, r) + ms, r[1]) : NaN; },\n };\n }\n const isIn = (t: number) => (inside ? inside(t) : calendar.inside(t));\n return { open: (t) => (isIn(t) ? open(t) : NaN), close: (t) => (isIn(t) ? close(t) : NaN) };\n }\n if (tf.isdaily && tf.multiplier === 1) {\n return { open: (t) => (calendar.inside(t) ? open(t) : NaN), close: (t) => (calendar.inside(t) ? close(t) : NaN) };\n }\n return { open, close };\n}\n\n/** Periods per chart, timeframe, session and time zone (no session / time zone is \"\"): maps of the given strings, no\n * key to build on every bar */\nconst periodCache = new WeakMap<object, Map<string, Map<string, Map<string, SessionPeriods>>>>();\n\nfunction periodsOfChart(chart: SessionContext, timeframe: string, session?: string, timezone?: string): { s: ChartSessions; p: SessionPeriods } {\n const s = chartSessions(chart);\n let byTimeframe = periodCache.get(chart);\n if (!byTimeframe) periodCache.set(chart, (byTimeframe = new Map()));\n let bySession = byTimeframe.get(timeframe);\n if (!bySession) byTimeframe.set(timeframe, (bySession = new Map()));\n let byZone = bySession.get(session ?? '');\n if (!byZone) bySession.set(session ?? '', (byZone = new Map()));\n let p = byZone.get(timezone ?? '');\n if (!p) byZone.set(timezone ?? '', (p = sessionPeriods(s.bars, chart, timeframe, session, timezone)));\n return { s, p };\n}\n\n/**\n * PineScript `time(timeframe, session, timezone)` (ms) of a bar that opens at `time`: the start of its period; NaN\n * without one or outside `session` (#182). Without `session` and `timezone`, the periods of the loaded session.\n */\nexport function periodTime(time: number, timeframe: string, chart: SessionContext, session?: string, timezone?: string): number {\n const { s, p } = periodsOfChart(chart, timeframe, session, timezone);\n return p.open(time * s.unit);\n}\n\n/** PineScript `time_close(timeframe, session, timezone)` (ms) of a bar that opens at `time` (#182). */\nexport function periodClose(time: number, timeframe: string, chart: SessionContext, session?: string, timezone?: string): number {\n const { s, p } = periodsOfChart(chart, timeframe, session, timezone);\n return p.close(time * s.unit);\n}\n\n/** PineScript `time_tradingday` (ms, 00:00 UTC of the trading day) of a bar that opens at `time`. */\nexport function tradingDayTime(time: number, chart: SessionContext): number {\n const s = chartSessions(chart);\n return s.bars.tradingDayTime(time * s.unit);\n}\n\n/** PineScript `session.*` flags of bars that open at `times` (in order). */\nexport function chartSessionFlags(times: ArrayLike<number>, chart: SessionContext): SessionFlags {\n const s = chartSessions(chart);\n return sessionFlags(Array.from(times, (t) => t * s.unit), s.bars, s.regular);\n}\n\n/** Higher-timeframe bars of the chart bars and what `mapToChart` needs to bring values back to the chart. */\nexport interface SessionResample {\n /** Bars of `timeframe`, built from the chart bars */\n bars: Bar[];\n /** Period index of each chart bar */\n group: number[];\n /** Latest completed period at each chart bar */\n latest: number[];\n}\n\n/**\n * Same-symbol `request.security` on a timeframe equal to or higher than the chart's, with the session of the context:\n * D / W / M periods follow the regular hours, corrections and holidays; intraday periods the loaded session.\n * Compute on `bars`, then bring each value series back with `mapToChart(values, group, latest, lookahead, gaps)`.\n * @throws Error when `timeframe` is lower than the chart timeframe\n */\nexport function resampleSession(bars: Bar[], timeframe: string, chart: SessionContext): SessionResample {\n const s = chartSessions(chart);\n const chartTf = s.bars.chart;\n const tf = info(timeframe || chartTf.period);\n if (tf.period === chartTf.period) {\n const group = bars.map((_, i) => i);\n return { bars, group, latest: group };\n }\n if (in_seconds(tf.period) < in_seconds(chartTf.period)) {\n throw new Error(`resampleSession: timeframe \"${tf.period}\" is lower than the chart timeframe \"${chartTf.period}\".`);\n }\n const times = bars.map((b) => (b.time as number) * s.unit);\n const calendar = tf.isdwm ? s.regular : s.bars;\n const starts = times.map((t) => calendar.timeOf(t, tf.period));\n const dayPeriods = times.map((t, i) => {\n const at = s.bars.calendar.locate(t);\n const periods = at ? calendar.calendar.periods(at.date) : [];\n return periods.length ? calendar.timeOf(periods[0]![0], tf.period) : starts[i]!;\n });\n strayPeriods(starts, dayPeriods, times, s.bars, tf.isdwm ? null : in_seconds(tf.period) * 1000);\n const reaches = times.map((t) => s.bars.closeOf(t, chartTf.period) >= calendar.periodEnd(t, tf.period));\n const { group, latest } = periodsOf(starts, dayPeriods, reaches);\n // a higher-timeframe bar ends at the bar that completes it (no value from after the completion)\n const after = afterCompletion(group, latest);\n const kept = (_: unknown, i: number): boolean => !after[i];\n return { bars: resample(bars.filter(kept), starts.map((x) => x / s.unit).filter(kept)).bars, group, latest };\n}\n\n/**\n * Open time of the `count`-th bar after the bar that opens at `time`, on the trading calendar of the context: the\n * closed hours, weekends, holidays and days off are skipped. `count` 0 is the bar itself. For a drawing that ends\n * `count` bars after the last bar (PineScript `bar_index + count`).\n */\nexport function barTimeAfter(time: number, count: number, chart: SessionContext): number {\n const s = chartSessions(chart);\n let t = time * s.unit;\n for (let k = 0; k < count && !Number.isNaN(t); k++) t = s.bars.nextBarTime(t);\n return t / s.unit;\n}\n\n/**\n * Number of bars from the bar that opens at `from` to the bar that contains `to`, on the trading calendar of the\n * context (0 when `to` is in the bar of `from` or before it). For a drawing placed at a time after the last bar\n * (PineScript `time + n days` with `xloc.bar_time`): the chart shows it on the bar of that time, weekends and\n * holidays skipped. `to` is first rounded to the nearest second, a half second going up (#174: 15 ms before a bar\n * opens is on that bar, 501 ms before is on the bar before). NaN when no bar is found within 100,000 bars.\n */\nexport function barsUntil(from: number, to: number, chart: SessionContext): number {\n const s = chartSessions(chart);\n const target = Math.floor((to * s.unit) / 1000 + 0.5) * 1000;\n let t = from * s.unit;\n for (let k = 0; k < 100_000; k++) {\n const next = s.bars.nextBarTime(t);\n if (Number.isNaN(next)) return NaN;\n if (next > target) return k;\n t = next;\n }\n return NaN;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,uBAAiC;AACjC,sBAAqD;AACrD,qBAA6C;AAC7C,kBAA2E;AAC3E,sBAAkD;AAwBlD,MAAM,SAAS,CAAC,MAA0C,OAAO,MAAM,WAAW,EAAE,SAAS,EAAE,IAAI;AAC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CAAC,GAAG,IAAK,KAAI,EAAE,KAAK,YAAY,CAAC;AAC5E,SAAO,IAAI,EAAE;AACf;AASO,SAAS,UAAU,MAAc,IAAY,OAA+B;AACjF,QAAM,IAAI,cAAc,KAAK;AAC7B,QAAM,SAAS,KAAK,MAAO,KAAK,EAAE,OAAQ,MAAO,GAAG,IAAI;AACxD,MAAI,IAAI,OAAO,EAAE;AACjB,WAAS,IAAI,GAAG,IAAI,KAAS,KAAK;AAChC,UAAM,OAAO,EAAE,KAAK,YAAY,CAAC;AACjC,QAAI,OAAO,MAAM,IAAI,EAAG,QAAO;AAC/B,QAAI,OAAO,OAAQ,QAAO;AAC1B,QAAI;AAAA,EACN;AACA,SAAO;AACT;",
4
+ "sourcesContent": ["/**\n * The session of a chart context, for code that does not run a whole script (a port with its own bar loop).\n *\n * The same values as the script API gives (`time(tf)`, `time_close(tf)`, `time_tradingday`, `session.*`, the periods\n * of `request.security`), from the session, corrections and holidays of the context. Bar times are in the unit of\n * the context (`timeUnit`, seconds by default, as `Bar.time`); PineScript time values are returned in ms.\n *\n * @module session/context\n */\n\nimport type { Bar } from '../types/index.js';\nimport { info, in_seconds } from '../timeframe/index.js';\nimport { afterCompletion, periodsOf, resample } from '../security/resample.js';\nimport { parsePineSession, sessionRun } from '../time/session.js';\nimport { SessionBars, sessionFlags, strayPeriods, type SessionFlags } from './bars.js';\nimport { TradingCalendar, type SessionSpec } from './calendar.js';\n\n/** The part of a chart context that the session functions read (a `ChartContext` of the script API fits). */\nexport interface SessionContext {\n /** Chart timeframe: \"5\", \"60\", \"1D\"... */\n timeframe?: string;\n /** Exchange time zone: \"America/New_York\", \"Etc/UTC\"... */\n timezone?: string;\n /** Session of the loaded bars: hours, corrections, holidays */\n session?: SessionSpec | string;\n /** Regular trading hours when the bars include extended hours (default: `session`) */\n regularSession?: SessionSpec | string;\n /** Unit of the bar times: 's' (default) or 'ms' */\n timeUnit?: 's' | 'ms';\n}\n\n/** The session calendars of a context: the loaded bars and the regular hours. */\nexport interface ChartSessions {\n bars: SessionBars;\n regular: SessionBars;\n /** ms per unit of the bar times */\n unit: number;\n}\n\nconst toSpec = (s: SessionSpec | string): SessionSpec => (typeof s === 'string' ? { session: s } : s);\nconst cache = new WeakMap<object, ChartSessions>();\n\n/**\n * Session calendars of a chart context (cached per context object).\n * @throws Error when the context has no timeframe, time zone or session\n */\nexport function chartSessions(chart: SessionContext): ChartSessions {\n const cached = cache.get(chart);\n if (cached) return cached;\n const { timeframe, timezone, session } = chart;\n if (!timeframe || !timezone || !session) {\n throw new Error('The chart context needs timeframe, timezone and session for the session functions.');\n }\n const loaded = toSpec(session);\n const regular = chart.regularSession ? toSpec(chart.regularSession) : loaded;\n const out: ChartSessions = {\n bars: new SessionBars(new TradingCalendar(timezone, loaded), timeframe),\n regular: new SessionBars(new TradingCalendar(timezone, { holidays: loaded.holidays, ...regular }), timeframe),\n unit: chart.timeUnit === 'ms' ? 1 : 1000,\n };\n cache.set(chart, out);\n return out;\n}\n\n/** Open and close (ms) of the period that contains a bar opening at a time in ms; NaN outside the session. */\nexport interface SessionPeriods {\n open: (time: number) => number;\n close: (time: number) => number;\n}\n\n/** Calendars of the `session` / `timezone` arguments before the cache restarts */\nconst MAX_ARGUMENT_CALENDARS = 64;\nconst argumentCalendars = new Map<string, TradingCalendar>();\n\n/**\n * Calendar of a session string read in a time zone, without corrections and holidays: it depends on these only, so\n * the calls with other timeframes or other chart contexts share it and its periods (a script often reads\n * `time(timeframe.period, s)` and `time(\"D\", s)` on every bar).\n */\nfunction argumentCalendar(timezone: string, session: string, rule: 'symbol' | 'pine', dayPlacement: boolean): TradingCalendar {\n const key = `${rule}|${dayPlacement}|${timezone}|${session}`;\n let calendar = argumentCalendars.get(key);\n if (!calendar) {\n calendar = new TradingCalendar(timezone, { session }, rule, dayPlacement);\n if (argumentCalendars.size >= MAX_ARGUMENT_CALENDARS) argumentCalendars.clear();\n argumentCalendars.set(key, calendar);\n }\n return calendar;\n}\n\n/**\n * Calendar for the `session` / `timezone` arguments of `time(tf, session, timezone)`. Without both: the loaded\n * session. As in PineScript, an explicit time zone reads the symbol session hours in that zone without corrections\n * and holidays, and an explicit session follows PineScript's session string rules.\n */\nfunction calendarFor(\n bars: SessionBars,\n chart: SessionContext,\n session: string | undefined,\n timezone: string | undefined,\n dayPlacement: boolean\n): { bars: SessionBars; test: boolean; inside?: (time: number) => boolean } {\n if (!session && !timezone) return { bars, test: false };\n const tz = timezone ?? chart.timezone!;\n // a session string that is empty or does not start with a digit is the symbol session: \"regular\" the regular\n // hours, \"extended\" and any other name the loaded hours (PineScript)\n if (session !== undefined && parsePineSession(session) === null) {\n const name = session.trim();\n const symbol = name === 'regular' && chart.regularSession ? chart.regularSession : chart.session!;\n return { bars: new SessionBars(argumentCalendar(tz, toSpec(symbol).session, 'symbol', false), bars.chart.period), test: true };\n }\n return {\n bars: new SessionBars(\n argumentCalendar(tz, session || toSpec(chart.session!).session, session ? 'pine' : 'symbol', dayPlacement),\n bars.chart.period\n ),\n test: true,\n // a PineScript session string: the rules of time.inSession (runs ending at 0000, days around a clock change)\n inside: session ? (time) => sessionRun(time, session, tz, in_seconds(bars.chart.period) * 1000) !== null : undefined,\n };\n}\n\n/**\n * `time(tf, session, timezone)` / `time_close(tf, session, timezone)` of a bar, as PineScript computes them (#173):\n * an intraday timeframe tests the bar with the session rules of time.inSession and aligns its periods on the start\n * of the run that contains the bar; \"D\" tests the bar against the day's session period (the calendar; the time\n * between two runs of a day is inside it, #182); a timeframe of more than one day (\"2D\", \"W\", \"M\") has no test and\n * keeps the period's time. `bars` is the calendar of the loaded session (`chartSessions(chart).bars`).\n */\nexport function sessionPeriods(\n bars: SessionBars,\n chart: SessionContext,\n timeframe: string,\n session?: string,\n timezone?: string\n): SessionPeriods {\n const tf = info(timeframe);\n const { bars: calendar, test, inside } = calendarFor(bars, chart, session, timezone, !tf.isintraday);\n const open = (t: number): number => calendar.timeOf(t, timeframe);\n const close = (t: number): number => calendar.closeOf(t, timeframe);\n if (!test) return { open, close };\n if (tf.isintraday) {\n if (session !== undefined && parsePineSession(session) !== null && !calendar.chart.isdwm) {\n const tz = timezone ?? chart.timezone!;\n const barMs = in_seconds(calendar.chart.period) * 1000;\n const ms = in_seconds(tf.period) * 1000;\n const run = (t: number) => sessionRun(t, session, tz, barMs);\n const start = (t: number, r: [number, number]) => r[0] + Math.floor((t - r[0]) / ms) * ms;\n return {\n open: (t) => { const r = run(t); return r ? start(t, r) : NaN; },\n close: (t) => { const r = run(t); return r ? Math.min(start(t, r) + ms, r[1]) : NaN; },\n };\n }\n const isIn = (t: number) => (inside ? inside(t) : calendar.inside(t));\n return { open: (t) => (isIn(t) ? open(t) : NaN), close: (t) => (isIn(t) ? close(t) : NaN) };\n }\n if (tf.isdaily && tf.multiplier === 1) {\n return { open: (t) => (calendar.inside(t) ? open(t) : NaN), close: (t) => (calendar.inside(t) ? close(t) : NaN) };\n }\n return { open, close };\n}\n\n/** Periods per chart, timeframe, session and time zone (no session / time zone is \"\"): maps of the given strings, no\n * key to build on every bar */\nconst periodCache = new WeakMap<object, Map<string, Map<string, Map<string, SessionPeriods>>>>();\n\nfunction periodsOfChart(chart: SessionContext, timeframe: string, session?: string, timezone?: string): { s: ChartSessions; p: SessionPeriods } {\n const s = chartSessions(chart);\n let byTimeframe = periodCache.get(chart);\n if (!byTimeframe) periodCache.set(chart, (byTimeframe = new Map()));\n let bySession = byTimeframe.get(timeframe);\n if (!bySession) byTimeframe.set(timeframe, (bySession = new Map()));\n let byZone = bySession.get(session ?? '');\n if (!byZone) bySession.set(session ?? '', (byZone = new Map()));\n let p = byZone.get(timezone ?? '');\n if (!p) byZone.set(timezone ?? '', (p = sessionPeriods(s.bars, chart, timeframe, session, timezone)));\n return { s, p };\n}\n\n/**\n * PineScript `time(timeframe, session, timezone)` (ms) of a bar that opens at `time`: the start of its period; NaN\n * without one or outside `session` (#182). Without `session` and `timezone`, the periods of the loaded session.\n */\nexport function periodTime(time: number, timeframe: string, chart: SessionContext, session?: string, timezone?: string): number {\n const { s, p } = periodsOfChart(chart, timeframe, session, timezone);\n return p.open(time * s.unit);\n}\n\n/** PineScript `time_close(timeframe, session, timezone)` (ms) of a bar that opens at `time` (#182). */\nexport function periodClose(time: number, timeframe: string, chart: SessionContext, session?: string, timezone?: string): number {\n const { s, p } = periodsOfChart(chart, timeframe, session, timezone);\n return p.close(time * s.unit);\n}\n\n/** PineScript `time_tradingday` (ms, 00:00 UTC of the trading day) of a bar that opens at `time`. */\nexport function tradingDayTime(time: number, chart: SessionContext): number {\n const s = chartSessions(chart);\n return s.bars.tradingDayTime(time * s.unit);\n}\n\n/** PineScript `session.*` flags of bars that open at `times` (in order). */\nexport function chartSessionFlags(times: ArrayLike<number>, chart: SessionContext): SessionFlags {\n const s = chartSessions(chart);\n return sessionFlags(Array.from(times, (t) => t * s.unit), s.bars, s.regular);\n}\n\n/** Higher-timeframe bars of the chart bars and what `mapToChart` needs to bring values back to the chart. */\nexport interface SessionResample {\n /** Bars of `timeframe`, built from the chart bars */\n bars: Bar[];\n /** Period index of each chart bar */\n group: number[];\n /** Latest completed period at each chart bar */\n latest: number[];\n}\n\n/**\n * Same-symbol `request.security` on a timeframe equal to or higher than the chart's, with the session of the context:\n * D / W / M periods follow the regular hours, corrections and holidays; intraday periods the loaded session.\n * Compute on `bars`, then bring each value series back with `mapToChart(values, group, latest, lookahead, gaps)`.\n * @throws Error when `timeframe` is lower than the chart timeframe\n */\nexport function resampleSession(bars: Bar[], timeframe: string, chart: SessionContext): SessionResample {\n const s = chartSessions(chart);\n const chartTf = s.bars.chart;\n const tf = info(timeframe || chartTf.period);\n if (tf.period === chartTf.period) {\n const group = bars.map((_, i) => i);\n return { bars, group, latest: group };\n }\n if (in_seconds(tf.period) < in_seconds(chartTf.period)) {\n throw new Error(`resampleSession: timeframe \"${tf.period}\" is lower than the chart timeframe \"${chartTf.period}\".`);\n }\n const times = bars.map((b) => (b.time as number) * s.unit);\n const calendar = tf.isdwm ? s.regular : s.bars;\n const starts = times.map((t) => calendar.timeOf(t, tf.period));\n const dayPeriods = times.map((t, i) => {\n const at = s.bars.locateBar(t);\n const periods = at ? calendar.calendar.periods(at.date) : [];\n return periods.length ? calendar.timeOf(periods[0]![0], tf.period) : starts[i]!;\n });\n strayPeriods(starts, dayPeriods, times, s.bars, tf.isdwm ? null : in_seconds(tf.period) * 1000);\n const reaches = times.map((t) => s.bars.closeOf(t, chartTf.period) >= calendar.periodEnd(t, tf.period));\n const { group, latest } = periodsOf(starts, dayPeriods, reaches);\n // a higher-timeframe bar ends at the bar that completes it (no value from after the completion)\n const after = afterCompletion(group, latest);\n const kept = (_: unknown, i: number): boolean => !after[i];\n return { bars: resample(bars.filter(kept), starts.map((x) => x / s.unit).filter(kept)).bars, group, latest };\n}\n\n/**\n * Open time of the `count`-th bar after the bar that opens at `time`, on the trading calendar of the context: the\n * closed hours, weekends, holidays and days off are skipped. `count` 0 is the bar itself. For a drawing that ends\n * `count` bars after the last bar (PineScript `bar_index + count`).\n */\nexport function barTimeAfter(time: number, count: number, chart: SessionContext): number {\n const s = chartSessions(chart);\n let t = time * s.unit;\n for (let k = 0; k < count && !Number.isNaN(t); k++) t = s.bars.nextBarTime(t);\n return t / s.unit;\n}\n\n/**\n * Number of bars from the bar that opens at `from` to the bar that contains `to`, on the trading calendar of the\n * context (0 when `to` is in the bar of `from` or before it). For a drawing placed at a time after the last bar\n * (PineScript `time + n days` with `xloc.bar_time`): the chart shows it on the bar of that time, weekends and\n * holidays skipped. `to` is first rounded to the nearest second, a half second going up (#174: 15 ms before a bar\n * opens is on that bar, 501 ms before is on the bar before). NaN when no bar is found within 100,000 bars.\n */\nexport function barsUntil(from: number, to: number, chart: SessionContext): number {\n const s = chartSessions(chart);\n const target = Math.floor((to * s.unit) / 1000 + 0.5) * 1000;\n let t = from * s.unit;\n for (let k = 0; k < 100_000; k++) {\n const next = s.bars.nextBarTime(t);\n if (Number.isNaN(next)) return NaN;\n if (next > target) return k;\n t = next;\n }\n return NaN;\n}\n"],
5
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,GAAG,OAAO,IAAI,CAAC,MAAM,IAAI,EAAE,IAAI,EAAE,OAAO,IAAI,CAAC,EAAE,MAAM,OAAO,OAAO;AAC7G;AAOO,SAAS,aAAa,MAAc,OAAe,OAA+B;AACvF,QAAM,IAAI,cAAc,KAAK;AAC7B,MAAI,IAAI,OAAO,EAAE;AACjB,WAAS,IAAI,GAAG,IAAI,SAAS,CAAC,OAAO,MAAM,CAAC,GAAG,IAAK,KAAI,EAAE,KAAK,YAAY,CAAC;AAC5E,SAAO,IAAI,EAAE;AACf;AASO,SAAS,UAAU,MAAc,IAAY,OAA+B;AACjF,QAAM,IAAI,cAAc,KAAK;AAC7B,QAAM,SAAS,KAAK,MAAO,KAAK,EAAE,OAAQ,MAAO,GAAG,IAAI;AACxD,MAAI,IAAI,OAAO,EAAE;AACjB,WAAS,IAAI,GAAG,IAAI,KAAS,KAAK;AAChC,UAAM,OAAO,EAAE,KAAK,YAAY,CAAC;AACjC,QAAI,OAAO,MAAM,IAAI,EAAG,QAAO;AAC/B,QAAI,OAAO,OAAQ,QAAO;AAC1B,QAAI;AAAA,EACN;AACA,SAAO;AACT;",
6
6
  "names": ["group"]
7
7
  }
@@ -66,7 +66,7 @@ export type * from './strategy/index.js';
66
66
  export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
67
67
  export type { LightweightSeriesDefinitions } from './runtime/adapters/LightweightChartsAdapter.js';
68
68
  export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
69
- export declare const VERSION = "0.18.0";
69
+ export declare const VERSION = "0.19.0";
70
70
  /**
71
71
  * Library information
72
72
  */
package/dist/esm/index.js CHANGED
@@ -82,7 +82,7 @@ export { STRATEGY_CONSTANTS, STRATEGY_DEFAULTS, STRATEGY_NUMBER_VARIABLES, STRAT
82
82
  export { LightweightChartsAdapter } from './runtime/adapters/LightweightChartsAdapter.js';
83
83
  export { SimpleInputAdapter } from './runtime/adapters/SimpleInputAdapter.js';
84
84
  // Version
85
- export const VERSION = '0.18.0';
85
+ export const VERSION = '0.19.0';
86
86
  /**
87
87
  * Library information
88
88
  */
@@ -2700,7 +2700,7 @@ function security(symbol, timeframe, expression, gaps = barmerge.gaps_off, looka
2700
2700
  const calendar = timeframeCore.info(tf).isdwm ? regular : loaded;
2701
2701
  const starts = times.map((t) => calendar.timeOf(t, tf));
2702
2702
  const dayPeriods = times.map((t, i) => {
2703
- const at = loaded.calendar.locate(t);
2703
+ const at = loaded.locateBar(t);
2704
2704
  const periods = at ? calendar.calendar.periods(at.date) : [];
2705
2705
  return periods.length ? calendar.timeOf(periods[0][0], tf) : starts[i];
2706
2706
  });