UtilityPine Script v6

ta.change()

Change

Compares the current source value to its value length bars ago and returns the difference.

Syntax

Syntax
ta.change(source, length) → series float

Arguments

ParameterTypeDescription
sourceseries int/floatSeries to compare (numeric or bool depending on usage).
lengthseries intBars back to compare; optional, default 1.

Returns

The difference between the values when they are numerical. When a bool source is used, returns true when the current source is different from the previous source.

Remarks

na values in the source series are included in calculations and will produce an na result.

Code Examples

Pine Script v6 Example
//@version=6
indicator('Day and Direction Change', overlay = true)
dailyBarTime = time('1D')
isNewDay = ta.change(dailyBarTime) != 0
bgcolor(isNewDay ? color.new(color.green, 80) : na)

isGreenBar = close >= open
colorChange = ta.change(isGreenBar)
plotshape(colorChange, 'Direction Change')

Trading Applications

Calculate bar-to-bar price changes

Detect timeframe changes (e.g., new day)

Build custom momentum indicators

Identify direction changes in boolean series

Related Functions

Frequently Asked Questions

Generate ta.change() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.change() and other built-in functions instantly.