Returns the rate of change: the percentage change of source over the last length bars.
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
ta.roc(source: series int/float, length: series int) -> series floatArguments
| Name | Type | Default | Description |
|---|---|---|---|
| source | series int/ | required | Series to compare with its past value. |
| length | series int | required | How 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.momfor the plain difference.
Example
//@version=6
indicator("ROC")
plot(ta.roc(close, 12), "ROC", color = color.blue)
hline(0, color = color.gray)See also
Runs on Sidechair