// The MIT License (MIT) // © mihakralj //@version=6 indicator("Rate of Change (ROC)", "ROC", overlay=false) //@function Calculates absolute Rate of Change between current price and N periods ago //@doc https://github.com/mihakralj/pinescript/blob/main/indicators/momentum/roc.md //@param source Source price series //@param length Lookback period //@returns Absolute price change value roc(series float source, simple int length)=> if length<=0 runtime.error("Length must be greater than 0") var int count = 0 float change = na if not na(source[count]) change := source - source[count] count := math.min(count + 1, length) change // ---------- Main loop ---------- // Inputs i_source = input.source(close, "Source") i_length = input.int(9, "Length", minval=1) // Calculate ROC float roc_val = roc(i_source, i_length) // Plot plot(roc_val, "ROC", color=color.yellow, linewidth=2)