RateOfChangePercent — Rate of Change Percent
The three TA-Lib rate-of-change variants in one indicator: percent (ROCP × 100), ratio
(ROCR) and ratio100 (ROCR100). Same measurement, three conventions — pick the scale your
rule is written in rather than converting.
Signature
RateOfChangePercent(period, on=<source>)| Argument | Type | Required | Notes |
|---|---|---|---|
period |
int Param or literal | Yes | Lookback. Default 10, bounds 1–400. |
on= |
symbol, OHLCV field, or indicator | No | Source. Defaults to the trade symbol’s close. |
Formula
$$ \text{percent} = 100\left(\frac{C_t}{C_{t-n}} - 1\right), \quad \text{ratio} = \frac{C_t}{C_{t-n}}, \quad \text{ratio100} = 100,\frac{C_t}{C_{t-n}} $$
Warmup
period + 1 bars; percent 0, ratio 1 and ratio100 100 until then.
Reading the value
roc.percentroc.ratioroc.ratio100Multi-value: cannot be chained onto or crossed.
Example
class RocMomentum(Strategy): """Enter on strong 10-bar momentum.""" trade = Symbol() sizing = FixedCapital()
def execute(self): roc = RateOfChangePercent(10, on=self.trade) if roc.percent > 3 and self.trade.is_flat: self.buy(self.trade, reason=f"ROC {roc.percent:.1f} pct") if roc.percent < 0 and self.trade.is_long: self.sell(self.trade, self.trade.position, reason="Momentum gone")Notes
- TA-Lib’s ROCP / ROCR / ROCR100. The platform’s seeded
ROCis the plain price-difference form; this is the normalised family. - Proven by an assert-via-trade run on SPY daily (all three outputs matched a strategy-side reference exactly on every bar; zero alarm trades).