Rate of change Percentage: (price-prevPrice)/prevPrice (ROCP)
Summary
Rate of change expressed as a fraction of the price optInTimePeriod bars ago. Normalized and centered at zero (positive or negative). >0 rising vs N bars ago, <0 falling; equals ROC/100.
Chart
Chart metadata i
Outputs
outReal:line·zero·positive·negative
Formula
ROCP = (price - prevPrice) / prevPrice, prevPrice = inReal[i - optInTimePeriod]
Notes
- The input is assumed positive. The price
optInTimePeriodbars back is the divisor. Where it is exactly 0 the output is 0. Near zero the divisor is small and the output very large; no error is returned. A series that reaches or crosses zero, such as an oscillator or a spread, has no meaningful result here.
Inputs
inReal— Source price series
Outputs
outReal— Fractional rate of change vs the value optInTimePeriod bars earlier
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 10 | 1–100000 | Lookback distance to the previous price |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Display Shift |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
| ☐ Uses Transcendental |
| ✅ Input Must Be Positive i |
Example
C
#include <stdio.h>
#include <ta_libc.h>
int n = 252;
double series[252]; /* your data, oldest first */
double out[252];
int outBegIdx, outNBElement;
TA_Initialize();
TA_ROCP( 0, n - 1, series, 10, &outBegIdx, &outNBElement, out );
printf( "%d values from bar %d; last out = %f\n", outNBElement, outBegIdx, out[outNBElement - 1] );Rust
use ta_lib::Core;
let series = vec![0.0; 252]; // your data, oldest first
let mut out = vec![0.0; 252];
let core = Core::new();
let range = core.rocp(0, series.len() - 1, &series, 10, &mut out)?;
println!("{} values from bar {}; last out = {}", range.count, range.beg_idx, out[range.count - 1]);Java
import io.github.talib.Core;
import io.github.talib.OutRange;
double[] series = new double[252]; // your data, oldest first
double[] out = new double[252];
Core core = Core.DEFAULT;
OutRange r = core.rocp(0, series.length - 1, series, 10, out);
System.out.println(r.count() + " values from bar " + r.begIdx() + "; last out = " + out[r.count() - 1]);C#
using System;
using TALib;
var series = new double[252]; // your data, oldest first
var outReal = new double[252];
var core = Core.Default;
OutRange r = core.Rocp(0, series.Length - 1, series, 10, outReal);
Console.WriteLine($"{r.Count} values from bar {r.BegIdx}; last outReal = {outReal[r.Count - 1]}");TypeScript
import { rocp } from 'ta-lib';
const series = new Float64Array(252); // your data, oldest first
const { begIdx, values } = rocp(series, { timePeriod: 10 });
console.log(values.length + ' values from bar ' + begIdx + '; last values = ' + values[values.length - 1]);Implementation
Added in 0.4.0.
TA-Lib Definition: rocp.c · rocp.yaml
| Native | File |
|---|---|
| C | ta_ROCP.c |
| Rust | rocp.rs |
| Java | Core_ROCP.java |
| C# | Core_ROCP.cs |
| TypeScript | rocp.ts |
Python: talib.ROCP, see ta-lib-python.
TA-Lib is also available for R and more using a wrapper.
Aliases
Rate of Change Percentage, Percent Change