Sidechair

ta.roc()

Browse the reference

Returns the rate of change: the percentage change of source over the last length bars.

Try it in the editor

ta.roc computes 100 * (source - source[length]) / source[length]. A value of 5 means source is 5 percent above where it was length bars ago.

The first reading needs a past bar, so it arrives on bar number length + 1. A past value of zero gives na or an infinite result, so use it on prices rather than on series that cross zero.

Syntax

Pine Script
ta.roc(source: series int/float, length: series int) -> series float

Arguments

NameTypeDefaultDescription
sourceseries int/floatrequiredSeries to compare with its past value.
lengthseries intrequiredHow many bars back to compare. A whole number of 1 or more.

Returns

series float: the percentage change over the window, or na on the first length bars.

Remarks

  • Use ta.mom for the plain difference.

Example

Pine ScriptRate of change with a zero lineOpen in editor
//@version=6
indicator("ROC")
plot(ta.roc(close, 12), "ROC", color = color.blue)
hline(0, color = color.gray)

See also

Runs on Sidechair