Sidechair

timeframe.change()

Browse the reference

True on the first bar of a new period of the given timeframe, such as a new day, week or hour.

Try it in the editor

timeframe.change("D") is true on the first bar of each day and false on the other bars. Pass any timeframe larger than the chart's: "60", "240", "D", "W" or "M". With no argument it uses the chart's own timeframe.

Use it to reset a running value at the start of a period, such as a daily high or a session counter, or to mark where periods begin. The first bar of the chart counts as a change.

Syntax

Pine Script
timeframe.change(timeframe: series string (optional)) -> series bool

Arguments

NameTypeDefaultDescription
timeframeseries stringthe chart's timeframeThe period to watch, such as "60", "D", "W" or "M". It must be as long as the chart's timeframe or longer.

Returns

series bool: True on the first bar of each new period, false otherwise.

Remarks

  • The timeframe must be at least as long as the chart's. A shorter one is meaningless here: every bar is then a new period.
  • A new day starts at the exchange's day boundary, not at midnight in your time zone.
  • On Sidechair: true on bar 0 and whenever the period of the bar differs from the previous bar's, using the symbol's own trading day. A timeframe that is not above the chart's, or a string that is not a timeframe, returns true on every bar.

Example

Pine ScriptDaily high that resetsOpen in editor
//@version=6
indicator("Daily high", overlay = true)
var float dayHigh = na
dayHigh := timeframe.change("D") ? high : math.max(dayHigh, high)
plot(dayHigh, "Day high", color.orange, 2)
plot(close, "Close", color.gray)

See also

Runs on Sidechair