Skip to content

Rate of change ratio

ROCR measures the ratio of the current price to the price at a previous period. It is calculated as (price/prevPrice).

Method

tm.ta.rocr(source, timeperiod)

Inputs

ParameterArgument typeDescriptionDefault Value
sourcepd.SeriesInput data series-
timeperiodintNumber of periods for the indicator10

Outputs

OutputType
rocrnp.ndarray

Example usage

strategy.py
import tradomate as tm
@tm.strategy()
def my_strategy(config: tm.TradomateConfig, data: tm.TradomateData):
# Trying out Rate of change ratio: (price/prevPrice)
rocr = tm.ta.rocr(data.close, timeperiod=10)
# Get the last value and print
last_value = rocr.iloc[-1]
tm.log(f"Last value of Rate of change ratio: (price/prevPrice) is {last_value}")
# Plot the values of rocr
tm.plot(rocr, title="Rate of change ratio: (price/prevPrice)", overlay=False)