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

ta.change() measures how a series differs from its past self: typically source - source[length] for numeric series, with length defaulting to 1 when omitted. For bool series, behavior reflects whether the value changed versus the prior bar.

ta.mom() is momentum as source - source[length] for numeric series in the TA namespace; ta.change() is the general change primitive and also supports non-numeric change detection patterns (e.g., time/bool use cases). Prefer the clearest function for your series type.

Yes—common patterns test ta.change(boolSeries) to detect flips between true/false, useful for state changes like candle color or signal toggles.

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.