Momentum OscillatorsPine Script v6

ta.roc()Rate of Change

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

TradingView language reference

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

Missing endpoints produce na. The denominator is source[length]; zero makes the percentage undefined, while a negative reference value needs interpretation beyond an ordinary positive-price return.

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

ta.roc(source, length) returns the percent change from source[length] to source, typically as 100 * (source - source[length]) / source[length].

Momentum (ta.mom) is the raw point change; ROC scales that change by the older price, expressing movement in percentage terms.

There is no universal threshold; "strong" depends on volatility and timeframe. Compare ROC to its own history or use standardized signals rather than fixed magic numbers.

Generate ta.roc() Code with AI

Draft Pine Script using ta.roc() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.