Momentum OscillatorsPine Script v6

ta.roc()

Rate of Change

Calculates the percentage change of source over the last length bars.

Syntax

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

Arguments

ParameterTypeDescription
sourceseries int/floatSeries to compute percentage change for.
lengthseries intLookback bars for the prior reference value.

Returns

Rate of change percentage.

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("ta.roc")
plot(ta.roc(close, 10))

// same on pine
pine_roc(src, length) =>
    100 * (src - src[length]) / src[length]
plot(pine_roc(close, 10))

Trading Applications

Measure percentage price change over time

Identify momentum extremes for mean reversion

Compare momentum across different securities

Use zero-line crossovers for trend signals

Related Functions

Frequently Asked Questions

Generate ta.roc() Code with AI

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