There is no
time.now() and no timeframe namespace (timeframe.period fails with No variable with name timeframe found): use interval.interval.
Parts of a time
year, month, dayofmonth, dayofweek, hour, minute, second are series ints for the current bar. Each is also a function of a time and an optional zone: hour(time, "America/New_York"). The zone is an IANA name; the default is the exchange’s (syminfo.timezone). A name it cannot load, "UTC-5" included, gives 0. weekofyear(time) exists only as a function. dayofweek counts Sunday as 1 to Saturday as 7; compare with dayofweek.sunday … dayofweek.saturday.
timestamp(2024, 3, 1) builds a time (hour, minute, second optional; the exchange’s zone), timestamp("UTC", 2024, 3, 1, 9, 30, 0) names the zone (an IANA name, or an offset such as "UTC-5" or "GMT+0530", as in time and str.format_time), and timestamp("2024-03-01") reads a date string (UTC without a zone; na if unreadable). When the script is added to the chart timestamp() is na, so it cannot be the default of input.time; give milliseconds.
Testing a session
time(interval, session) returns the opening time of the interval period that holds the bar, or na when that opening time is outside session. Periods are cut on the clock (a 1-hour period holding a 09:30 bar opens at 09:00), so time("1D", "0930-1600") is always na. A session is "0930-1600", with ranges joined by commas ("1000-1100,1400-1500") and optionally : and days, Sunday as 1 ("0930-1600:23456"). A range that ends before it starts wraps past midnight; "0000-0000" is the whole day. Times are read in the exchange’s zone; a timezone argument between session and bars_back changes that. time_close takes the same arguments.
session.isfirst is true on a session’s first bar; session.date is its date string. There is no session.islast: Namespace session has no variable islast. Did you mean isfirst?
The chart’s interval
An interval string is a number and a unit:s, m, h, D, W, M ("30s", "5m", "1h", "1D").
interval.intervalis the chart’s interval string,interval.multiplierits number,interval.timeframe_minutesits length in minutes.interval.isintraday,isseconds,isminutes,ishourly,isdaily,isweekly,ismonthly,iseodare simple bools.interval.change("1D")is true on the first bar of each new day (or other period).interval.in_seconds("1D")is 86400 (no argument: the chart’s interval);interval.from_seconds(86400)is"1D". A month is 2628003 seconds; tick and range intervals givena.