Skip to main content
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

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
Parameters Returns series bool Example

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
Parameters Returns series string Example

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
Parameters Returns series int Example