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

# interval functions

> Reference for the 3 functions of the interval namespace: interval.change, interval.from_seconds and interval.in_seconds, each with its definition and an example.

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

## `interval` (library)

**Definition**

Eleven values describing the interval the chart is drawn on: the interval itself, its multiplier, its length in minutes, and eight booleans for what kind of interval it is.

Every one is simple rather than series, because the chart's interval does not change while a script runs.

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("interval Library Example", overlay=true)
if barstate.islast {
    kind = interval.isintraday ? "Intraday" : interval.isdaily ? "Daily" : "Weekly or longer"
    label.new(bar_index, high, text=kind + " chart, interval " + interval.interval)
}
```

## `interval.change` (function)

**Definition**

Returns true on the first bar of each new period of `interval`, for example on the first bar of every day when `interval` is "1D". Use it to reset values at the start of a larger period.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
interval.change(series string interval) → series bool
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `interval` | `series string` | yes | Interval string: a count and a unit, such as "15m", "4h" or "1D", with the units `s`, `m`, `h`, `D`, `W` and `M`. For `D`, `W` and `M` the count must be 1. Any other string compiles and gives false. |

**Returns**

`series bool`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("interval.change Example", overlay=true)
static float dayHigh = na
if interval.change("1D") {
    dayHigh := high
} else {
    dayHigh := math.max(dayHigh, high)
}
plot(dayHigh, title="High of the Day", color=color.green)
```

## `interval.from_seconds` (function)

**Definition**

Returns the interval string for a length in seconds, rounded up to the next supported interval. It is not an exact inverse of `interval.in_seconds`.

The result is one of "5s", "10s", "15s", "30s", "45s", "1m", "3m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "1D", "1W", "1M", "3M", "6M" and "12M": 2 seconds gives "5s", 120 seconds gives "3m", 86400 gives "1D". 1 second or less gives "1s", and more than 31622400 seconds gives "12M". Exactly 1, 3, 6 or 12 times 2628003 seconds (the length of a month in `interval.in_seconds`) is read first as that many months (another multiple, such as 2 months, is rounded up: 5256006 gives "3M"), while the rounding table counts a month as 30 days, so 2592001 seconds gives "3M" but 2628003 gives "1M".

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
interval.from_seconds(series int seconds) → series string
```

**Parameters**

| Name | Type | Required | Description |
| - | - | - | - |
| `seconds` | `series int` | yes | Length of the interval in seconds. |

**Returns**

`series string`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("interval.from_seconds Example", overlay=true)
fourTimesChart = interval.from_seconds(interval.in_seconds() * 4)
if barstate.islast {
    label.new(bar_index, high, text="4x chart interval: " + fourTimesChart)
}
```

## `interval.in_seconds` (function)

**Definition**

Returns the length of `interval` in seconds, for example 86400 for "1D". With no argument it measures the chart's own interval.

**Syntax**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
interval.in_seconds(series string interval) → series int
```

**Parameters**

| Name | Type | Required | Description | Default |
| - | - | - | - | - |
| `interval` | `series string` | no | Interval string, for example "1D". Optional. The default is the chart's own interval. | `interval.interval` |

**Returns**

`series int`

**Example**

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("interval.in_seconds Example", overlay=false)
chartSeconds = interval.in_seconds()
// Bars per day on an intraday chart
plot(86400 / chartSeconds, title="Bars per Day", color=color.blue)
```


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