-
Notifications
You must be signed in to change notification settings - Fork 0
Quick Start
Four things that work, in the order they stop being surprising. Every block on this page compiles as written.
//@version=6
indicator("quick start 1", overlay = true)
import The_Peaceful_Lizard/std_time/1 as t
t.DateTime d = t.unix_to_date_zone(time, t.Zone.NEW_YORK)
plot(d.is_trading_day(t.Exchange.NYSE) ? 1 : 0)
unix_to_date_zone turns the bar's instant into civil fields in a real zone,
daylight saving included. From there everything is a method on the record.
Note t.DateTime, not DateTime. Imported types take your alias.
//@version=6
indicator("quick start 2", overlay = true)
import The_Peaceful_Lizard/std_time/1 as t
t.DateTime d = t.unix_to_date_zone(time, t.Zone.NEW_YORK)
string why = d.holiday_name(t.Exchange.NYSE)
bool starts = not na(why) and na(why[1])
if starts
label.new(bar_index, high, why, style = label.style_label_down)
why is assigned on every bar and why[1] reads its own history, so the label
fires once per closure rather than on every bar of one. Keeping the call out of
the if condition matters: a call placed behind a short-circuiting and is not
guaranteed to run every bar, and a function whose history you read has to.
holiday_name is the source of truth: is_holiday is defined as this being
non-na, so the predicate and the name cannot disagree. On 29 and 30 October
2012 it answers "Hurricane Sandy".
//@version=6
indicator("quick start 3", overlay = true)
import The_Peaceful_Lizard/std_time/1 as t
var t.Session sess = t.session_of(t.SessionId.US_REGULAR)
if t.changed(time[1], time, t.TimeUnit.DAY, t.Zone.NEW_YORK)
t.Interval iv = sess.bounds(t.unix_to_date_zone(time, t.Zone.NEW_YORK))
if not na(iv)
box.new(left = iv.FromMS, top = high, right = iv.ToMS, bottom = low,
xloc = xloc.bar_time, bgcolor = color.new(color.blue, 90),
border_color = color.blue)
Two things are doing work here. changed detects a new New York day on any
chart, in any zone. bounds returns the session's actual window for that date,
so the day after Thanksgiving draws to 13:00 rather than 16:00, without you
special-casing it.
var on the session matters: it is configuration, not per-bar work.
//@version=6
indicator("quick start 4", overlay = true)
import The_Peaceful_Lizard/std_time/1 as t
var t.Session sess = t.session_of(t.SessionId.US_REGULAR)
if sess.is_last_bar(time, time_close)
label.new(bar_index, high, "close", style = label.style_label_down)
The usual Pine idiom infers the session end from the data, so it cannot be true until the next bar exists, and on the chart's final bar it never fires at all. This computes the close instant from the calendar and compares the bar's own window against it, so it lands on the bar itself, historical and realtime alike, half days included.
- The model, in order: Core Concepts.
- Something specific: Task Index or API Index.
- Coming from the built-ins: Migrating from Pine Built-ins.
- More worked examples: Recipes.
Previous: Installation · Next: Core Concepts
std_time v1 · API Index · Task Index · Scope and Limitations · Verification
Calendar data current to the horizons on Versioning and Data Currency. Shanghai, Bombay and Singapore answer exactly through 2026.
MPL-2.0 · Copyright (c) 2026 Jesse Sanford · published on TradingView as The_Peaceful_Lizard
Start here
The model
- Core Concepts
- Civil and Exact Arithmetic
- Value Semantics
- Error Model
- Time Zones
- Exchange Calendars
- Trading Days and Day Counts
- Expiries
- Sessions
- Formatting and Parsing
- Choosing the Right Tool
- Pitfalls
Recipes
Reference
- API Index · Task Index
- DateTime
- Session
- Zone
- Exchange
- Period · Interval
- Weekday · Enums
- Free functions
- Glossary
The fine print