Trading Calendar, Time Zone, and Session Modeling for Pine Script
Summary
This Pine library provides civil date and time arithmetic, fixed-offset and daylight-saving zone conversions, ISO week handling, date adjustment, exchange holiday calendars, trading-day counts, session schedules, and economic-event dates. Its central design separates calendar operations from elapsed-time operations: adding a calendar day preserves local clock time, while adding a duration advances the instant. It also distinguishes fixed offsets from zones governed by daylight-saving rules.
The documentation describes validation against external exchange-calendar references for specified markets and date ranges, alongside rule-based calculations for items such as Easter and VIX settlement. It explains how unknown results are represented when published tables end, and how holiday candidates and weekday counts support trading-day calculations. Coverage is uneven: some calendars stop at a fixed year or require annual updates, historical zone rules may be extrapolated, and unscheduled closures cannot be predicted. Session presets may omit breaks or holidays, and the library does not model leap seconds.
Key ideas
- Calendar-day arithmetic and elapsed-time arithmetic require different operations, especially across daylight-saving changes.
- A fixed UTC offset does not capture a region's changing time-zone rules.
- Exchange holiday and session coverage varies by market and date range, with explicit horizons for some calendars.
- The library distinguishes an unknown calendar answer from a confirmed non-holiday result.
- Trading-day counts use weekday arithmetic plus candidate holiday dates rather than stepping through every day.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.