Returns the closing time of the current bar or period, or na outside the trading session you give.
time_close(timeframe, session) works like time(timeframe, session) but returns the end of the bar or higher-timeframe period instead of its start. It is na for bars outside the session.
Use it to know when the current period ends, for example to count the minutes left in the day.
Syntax
time_close(timeframe: series string, session: series string (optional), bars_back: series int (optional), timeframe_bars_back: series int (optional)) -> series int
time_close(timeframe: series string, session: series string, timezone: series string, bars_back: series int (optional), timeframe_bars_back: series int (optional)) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| timeframe | series string | required | The timeframe of the period to look up, such as "D", "W" or timeframe.period for the chart's own. |
| session | series string | every bar qualifies | The session as text, such as "0930-1600" or "0930-1600:23456". When left out, or empty, every bar qualifies and the call only changes the timeframe. |
| bars_back | series int | 0 | How many bars back to look for the time. |
| timeframe_bars_back | series int | 0 | Counts back in bars of the given timeframe instead of chart bars. |
| timezone | series string | required | The time zone the session is read in. |
Returns
series int: The UNIX timestamp in milliseconds at which the bar or period ends, or na when the bar is outside the session.
Remarks
- On Sidechair: the end is the period's start plus the timeframe length. A daily period ends 24 hours after it opened, not at the exchange's closing time.
- On Sidechair: bars_back and timeframe_bars_back are accepted and ignored.
Examples
//@version=6
indicator("Hours left in the hour")
hoursLeft = (time_close("60") - time) / 3600000
plot(hoursLeft, "Hours left in the hour", style = plot.style_stepline)//@version=6
indicator("Minutes left in the day")
minutesLeft = (time_close("D") - time) / 60000
plot(minutesLeft, "Minutes left", color.orange, style = plot.style_stepline)See also
Runs on Sidechair