> ## 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.

# Global variables

> Reference for the 24 variables of the global scope (the names with no namespace): bar_index, close, dayofmonth, dayofweek and 20 more, each with its definition and an example.

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

## `bar_index` (variable)

**Definition**

The index of the bar being evaluated.

It is an int series rather than a float, and it changes bar by bar as a price does.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Bar Index Example", overlay=true)
plot(bar_index, color=color.blue)
```

## `close` (variable)

**Definition**

The bar's closing price. This is the value most calculations start from.

On a bar that has not finished forming, the reading is that bar's closing value so far.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("close")
latest_close = close
plot(latest_close, color=color.blue, title="Close Price")
```

## `dayofmonth` (variable)

**Definition**

The day of the month of the bar being evaluated.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Day of Month Example", overlay=true)
bgcolor(dayofmonth == 20 ? color.red : na)
```

## `dayofweek` (variable)

**Definition**

The day of the week of the bar being evaluated, as an int series.

Sunday is `1` and Saturday is `7`. Compare with `dayofweek.sunday` … `dayofweek.saturday` (same numbers) instead of memorising literals.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Day of Week Example", overlay=true)
plot(dayofweek == dayofweek.monday ? 1 : 0, title="Monday", color=color.blue)
```

## `high` (variable)

**Definition**

The bar's highest traded price.

Pair it with `low` when you want the bar's range; the difference between the two is a series like its parts.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("High Example", overlay=true)
plot(high, color=color.green, title="High Price")
```

## `hl2` (variable)

**Definition**

The bar's high and low, averaged: its midpoint. Supplied so you need not write the arithmetic.

Four of these averaged prices exist. Each is a float series like the values it averages, so one can stand anywhere a price is wanted.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("HL2 Example", overlay=true)
plot(hl2, color=color.orange, title="HL2 (Midpoint of High & Low)")
```

## `hlc3` (variable)

**Definition**

The bar's high, low and close, averaged.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("HL2 Example", overlay=true)
plot(hlc3, color=color.orange, title="HLC3 (Midpoint of High, Low and Close)")
```

## `hlcc4` (variable)

**Definition**

The bar's high, low and close with the close counted twice, averaged.

The name records the weighting: four components, of which two are the close.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("HL2 Example", overlay=true)
plot(hlcc4, color=color.orange, title="HLCC4 (Midpoint of High, Low, Close and Close)")
```

## `hour` (variable)

**Definition**

The hour of the bar being evaluated.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("hour Example", overlay=true)
// Highlight the first trading hour
bgcolor(hour == 9 ? color.new(color.blue, 0.15) : na)
```

## `last_bar_index` (variable)

**Definition**

Bar index of the last bar on the chart (the rightmost bar), including the realtime tip when one is forming.

Unlike `bar_index`, this value is the same on every bar in a run: it always points at the chart's final bar.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("last_bar_index Example", overlay=true)
isLast = bar_index == last_bar_index
bgcolor(isLast ? color.new(color.orange, 0.85) : na)
```

## `last_bar_time` (variable)

**Definition**

Open time of the last bar on the chart, in UNIX milliseconds (same convention as `time`).

Matches the timestamp of the rightmost bar, including the unconfirmed realtime bar when present.

**Type**

`series int`

**Example**

```lipi wrap theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("last_bar_time Example", overlay=true)
if bar_index == last_bar_index {
    label.new(bar_index, high, text=str.format_time(math.floor(last_bar_time / 1000), "2006-01-02 15:04"), style=label.style_label_down)
}
```

## `low` (variable)

**Definition**

The bar's lowest traded price.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Low Price Example", overlay=true)
lowestPrice = talib.lowest(low, 10)
plot(lowestPrice, color=color.red, title="Lowest Price (10 Bars)")
```

## `minute` (variable)

**Definition**

The minute of the bar being evaluated.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Minute-Based Signal", overlay=true)
isEvenMinute = (minute % 2 == 0)
plotshape(isEvenMinute, location=location.abovebar, color=color.green, title="Even Minute Signal")
```

## `month` (variable)

**Definition**

The month of the bar being evaluated.

As with the other date parts, there is a function of the same name that takes a time and a timezone instead.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Monthly Signal Example", overlay=true)
isDecember = (month == 12)
plot(isDecember ? close : na, color=color.blue, title="December Close")
```

## `ohlc4` (variable)

**Definition**

The bar's four values, open, high, low and close, averaged with equal weight.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("OHLC4 Example", overlay=true)
averagePrice = ohlc4
plot(averagePrice, color=color.orange, title="OHLC4 Price")
```

## `oi` (variable)

**Definition**

Open interest for the bar. It is 0, not `na`, where the bar carries no open-interest data.

This single name is the whole of the open-interest surface. There is no open-interest namespace and no second name.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("oi Example", overlay=false)
plot(oi, title="Open Interest", color=color.blue)
```

## `open` (variable)

**Definition**

The opening price of the bar your script is being evaluated on.

It is a float series, so it moves on as the script advances through the chart.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Open Price Example", overlay=true)
openPrice = open
prevOpen = open[1]
plot(openPrice, color=color.blue, title="Current Open Price")
plot(prevOpen, color=color.red, title="Previous Open Price")
```

## `second` (variable)

**Definition**

The second of the bar being evaluated.

Seven date parts are available as variables. `weekofyear` is not among them: it exists as a function only.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Second-Based Signal", overlay=true)
isHalfMinute = (second >= 30)
plotshape(isHalfMinute, location=location.abovebar, color=color.purple, title="Half-Minute Signal")
```

## `time` (variable)

**Definition**

The bar's opening time, as an int series.

It counts milliseconds from the Unix epoch. Note the unit: it is milliseconds, not seconds, so anything expecting seconds needs the value divided by a thousand first.

Hand it to one of the date functions - `year`, `month`, `hour` and the rest - together with a timezone to take it apart.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator(title="Time Example", overlay=true)
plot(time, title="Bar Time", color=color.blue)
```

## `time_close` (variable)

**Definition**

The bar's closing time, distinct from `time`.

It is the opening time advanced by one interval, in the same unit: milliseconds from the Unix epoch. Both are int series, so a script can compare the two or pass either to a date function.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator(title="Time Close Example", overlay=true)
plot(time_close, title="Bar Close Time", color=color.blue)
```

## `time_sessionday` (variable)

**Definition**

The UNIX time, in milliseconds, of the trading day the current bar belongs to. For instruments whose session starts the evening before, it gives the date the session is traded for rather than the calendar date of the bar.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("time_sessionday Example", overlay=true)
newTradingDay = time_sessionday != time_sessionday[1]
bgcolor(newTradingDay ? color.new(color.blue, 0.3) : na)
```

## `timenow` (variable)

**Definition**

The current time, rather than a time taken from the bar.

It is the instant the script ran, in milliseconds from the Unix epoch, and it is typed as a series like the bar's own time values.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator(title="Time Now Example", overlay=true)
plot(timenow, title="Current Time", color=color.blue)
```

## `volume` (variable)

**Definition**

The volume traded in the bar.

It is a float rather than an int, so it carries fractional volumes without a conversion.

**Type**

`series float`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator(title="Average Volume Example", overlay=true)
length = 20
average_volume = talib.sma(volume, length)
plot(volume, title="Volume", color=color.blue)
plot(average_volume, title="Average Volume", color=color.red)
```

## `year` (variable)

**Definition**

The year of the bar being evaluated.

A function of the same name also exists. The variable reads the current bar; the function reads whatever time you hand it.

**Type**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator(title="Year Example", overlay=true)
currentYear = year
plot(currentYear, title="Year", color=color.blue)
```


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