Skip to content

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
PartDescriptionExample
HHMMTime in 24-hour format0930 = 9:30 AM
daysDays of week (ISO 8601): 1=Mon, ..., 7=Sun12345 = Mon-Fri

Day numbers (ISO 8601)

NumberDay
1Monday
2Tuesday
3Wednesday
4Thursday
5Friday
6Saturday
7Sunday

Examples of session strings

StringMeaning
"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) → bool

Arguments

NameTypeDefaultDescription
timelong?timeTimestamp 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
    });
}