Sidechair

ta.change()

Browse the reference

Returns the difference between the current value of source and its value length bars ago; for a bool source, whether it differs.

Try it in the editor

For numbers, ta.change is source - source[length], with length defaulting to 1. For a bool source it returns true on the bars where the value differs from the value length bars earlier.

The first length bars return na for numbers. Use it to spot a new session, a flipped condition or a price step.

Syntax

Pine Script
ta.change(source: series int/float, length: series int) -> series float
ta.change(source: series bool, length: series int) -> series bool
ta.change(source: series int, length: series int) -> series int

Arguments

NameTypeDefaultDescription
sourceseries int/float or series bool or series intrequiredSeries to compare with its past value; numbers or booleans.
lengthseries int1How many bars back to compare. A whole number of 1 or more.

Returns

  • series float: the difference from length bars ago, or na on the first length bars.
  • series bool: true when the value differs from length bars ago.
  • series int: the integer difference from length bars ago.

Remarks

  • ta.change(close) is the same as close - close[1].

Example

Pine ScriptBar-to-bar change as columnsOpen in editor
//@version=6
indicator("Change")
delta = ta.change(close)
plot(delta, "Change", color = delta >= 0 ? color.green : color.red, style = plot.style_columns)

See also

Runs on Sidechair