> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# session variables

> Reference for the 2 variables of the session namespace: session.date and session.isfirst, each with its definition and an example.

> [!NOTE]
>
> Language version: 2 · Reference version: 2.7 · Date: 2026-10-25 · Compiler build: df7b3b14 · Namespace: session · Entries: 3

## `session` (library)

**Definition**

Two values about the session the current bar falls in: its date, and whether this is the session's first bar.

Both are series, so unlike the interval values they change as the script moves through bars.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("session Library Example", overlay=true)
// Mark the first bar of every session
bgcolor(session.isfirst ? color.new(color.blue, 0.3) : na)
```

## `session.date` (variable)

**Definition**

The date of the session the current bar falls in.

Session values are series, not simple: this one changes as your script moves through bars.

**Type**

`series string`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Session-based CVD (Fixed)", overlay=false)
// Persistent variable
static customCVD = 0
isNewSession = session.date != session.date[1]
// Reset on new session, accumulate otherwise
customCVD := isNewSession ? 0 : customCVD + orderflow.delta
plot(customCVD, title="Session CVD", style=plotStyle.line, color=color.orange)
```

## `session.isfirst` (variable)

**Definition**

True on the first bar of a session.

This is the flag to reach for when something has to reset once per session. The cumulative delta function reads it for exactly that purpose, seeding its running total from zero rather than carrying the previous bar's total forward.

**Type**

`series bool`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("CVD with session.first", overlay=false)
// Initialize persistent variable
static customCVD = 0
// Check if it's the first candle of the session
if session.isfirst {
    customCVD := 0
} else  {
    customCVD := customCVD + orderflow.delta
}
plot(customCVD, title="Session CVD", color=color.blue)
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.