Sidechair

time_close()

Browse the reference

Returns the closing time of the current bar or period, or na outside the trading session you give.

Try it in the editor

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

Pine Script
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 int

Arguments

NameTypeDefaultDescription
timeframeseries stringrequiredThe timeframe of the period to look up, such as "D", "W" or timeframe.period for the chart's own.
sessionseries stringevery bar qualifiesThe 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_backseries int0How many bars back to look for the time.
timeframe_bars_backseries int0Counts back in bars of the given timeframe instead of chart bars.
timezoneseries stringrequiredThe 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

Pine ScriptHours until the period endsOpen in editor
//@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)
Pine ScriptMinutes until the day endsOpen in editor
//@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