Sessions and intervals
Two groups of names sit close together here, and they behave differently.
The interval values describe the chart your script is running on. Every one of them is simple: the chart’s interval does not change while a script runs. Read one wherever you like and the answer is the same on every bar.
The session values describe where the current bar falls. Both are series: they change as your script moves through the bars.
The chart’s interval
Three values describe the interval itself.
| Name | Type | Holds |
|---|---|---|
interval.interval | simple string | The chart’s interval |
interval.multiplier | simple int | The interval’s multiplier |
interval.timeframe_minutes | simple int | The interval in minutes |
Seven booleans answer what kind of interval it is.
| Name | Type | True when the interval is |
|---|---|---|
interval.isintraday | simple bool | Intraday |
interval.isminutes | simple bool | In minutes |
interval.ishourly | simple bool | Hourly |
interval.isdaily | simple bool | Daily |
interval.isweekly | simple bool | Weekly |
interval.ismonthly | simple bool | Monthly |
interval.iseod | simple bool | End of day |
Because these are simple rather than series, a test against one of them gives the same answer on every bar of the run.
interval.isintradayThe session
| Name | Type | Holds |
|---|---|---|
session.date | series string | The session’s date |
session.isfirst | series bool | Whether this is the first bar of the session |
session.isfirst marks the first bar of a session. Other parts of the language lean on it. The cumulative delta function reads it to decide when to restart, seeding its running total from zero on a session’s first bar rather than carrying the previous bar’s total forward. Anything of yours that has to reset once a session is the same shape of problem.
The bar’s time values
| Name | Type | Holds |
|---|---|---|
time | series int | The bar’s time |
time_close | series int | The bar’s closing time |
timenow | series int | The current time |
Seven more int series name the parts of a date and a time on the current bar.
| Name | Type |
|---|---|
year | series int |
month | series int |
dayofmonth | series int |
dayofweek | series int |
hour | series int |
minute | series int |
second | series int |
Each of those seven names also exists as a function, which is the subject of the next section. The variable reads the current bar. The function reads whatever time value you hand it.
Taking a time apart
Eight functions take a time and a timezone and return an int series. Both arguments are required. Seven of them share their names with the variables above; weekofyear has no variable form.
year(series int time, series string timezone) → series intmonth(series int time, series string timezone) → series intweekofyear(series int time, series string timezone) → series intdayofmonth(series int time, series string timezone) → series intdayofweek(series int time, series string timezone) → series inthour(series int time, series string timezone) → series intminute(series int time, series string timezone) → series intsecond(series int time, series string timezone) → series intThe time argument takes an int in any form, so the bar’s own time is accepted, and so is a constant. The timezone argument takes a string in any form. The chart instrument’s timezone is available as syminfo.timezone, described in Instrument properties.
hour(time, syminfo.timezone)Building a time value
timestamp goes the other way, assembling a time from its parts. It has two forms. Give it series arguments and you get an int series back. Give it simple arguments and you get a simple int back.
timestamp(series int year, series int month, series int day, series int hour, series int minute, series int second) → series inttimestamp(simple int year, simple int month, simple int day, simple int hour, simple int minute, simple int second) → simple intIn both forms the year, the month and the day are required. The hour, the minute and the second may be left out.
A script that plots the bar’s hour and minute
indicator("Bar hour and minute")
plot(hour)
plot(minute)Both plot calls sit at the top level of the script. Chart-output functions have to be called there: a call placed inside a branch, inside a loop or inside a function of your own is rejected.