Appearance
Session
Kind: module
Namespace: session
Provides functions for working with trading sessions and time-based filtering.
Overview
A session defines a time window with optional day-of-week filtering. Sessions are useful for restricting calculations to specific market hours or trading periods.
Sessions are created via input.session() and represented as a session object.
Session boundaries are evaluated in UTC by default. Pass a timeZone option to input.session() to interpret the session in a specific time zone (e.g. "America/New_York" for US regular hours). IANA region names are DST-aware; fixed offsets like "UTC+3" are not.
Format
HHMM-HHMM
HHMM-HHMM:days| Part | Description | Example |
|---|---|---|
HHMM | Time in 24-hour format | 0930 = 9:30 AM |
days | Days of week (ISO 8601): 1=Mon, ..., 7=Sun | 12345 = Mon-Fri |
Day numbers (ISO 8601)
| Number | Day |
|---|---|
| 1 | Monday |
| 2 | Tuesday |
| 3 | Wednesday |
| 4 | Thursday |
| 5 | Friday |
| 6 | Saturday |
| 7 | Sunday |
Examples of session strings
| String | Meaning |
|---|---|
"0930-1600" | 9:30 AM - 4:00 PM, every day |
"0930-1600:12345" | 9:30 AM - 4:00 PM, Mon-Fri |
"0000-0000" | Full 24 hours |
Session Object
The session object represents a time window and provides methods for checking if a given time falls within it.
session.contains()
Kind: method
Checks if a time is within the session.
Syntax
session.contains() → bool
session.contains(time) → boolArguments
| Name | Type | Default | Description |
|---|---|---|---|
| time | long? | time | Timestamp in milliseconds. Defaults to current bar |
Returns
true if the time is within the session, false otherwise.
Example
javascript
const marketHours = input.session("Market Hours", "0930-1600:12345");
function onTick() {
const inSession = marketHours.contains();
spline(close, {
title: "Price",
color: inSession ? color.BLUE : color.GRAY
});
}