ta.change()
Change
Compares the current source value to its value length bars ago and returns the difference.
Syntax
ta.change(source, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source | series int/float | Series to compare (numeric or bool depending on usage). |
| length | series int | Bars 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
//@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
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.
Related Pine Script Functions
ta.mom() - Momentum
Learn how to use ta.mom() in Pine Script. Syntax, parameters, code examples for the Momentum indicator.
ta.roc() - Rate of Change
Learn how to use ta.roc() in Pine Script. Syntax, parameters, code examples for the Rate of Change percentage indicator.
ta.cross() - Cross
Learn how to use ta.cross() in Pine Script. Detect when two series cross each other in either direction.
ta.rising() - Rising
Learn how to use ta.rising() in Pine Script. Test if a series is consistently rising over a given period.
ta.falling() - Falling
Learn how to use ta.falling() in Pine Script. Test if a series is consistently falling over a given period.