ROC on TradingView — Pine Script v5 Source

The built-in ta.roc, a smoothed line, and zero-cross alerts

ROC in Pine Script
ROC in Pine Script

Pine has ta.roc built in, so the Rate of Change is a one-liner — but adding a smoothing line and zero-cross alerts makes it far more usable. See the explainer for the concept.

What you’ll need

  • A TradingView account (free tier is fine)
  • The Pine Editor

The source

//@version=5
indicator("AlgoGen ROC", shorttitle="AG ROC", overlay=false)

length = input.int(12, "Length", minval=1)
smooth = input.int(1,  "Smoothing (1 = raw)")

rocVal = ta.roc(close, length)
rocLine = ta.sma(rocVal, smooth)

col = rocLine >= 0 ? #0ca30c : #d03b3b
plot(rocLine, "ROC", color=col, linewidth=2)
hline(0, "Zero", color=color.gray)

alertcondition(ta.crossover(rocLine, 0),  "ROC cross up",   "ROC crossed above zero")
alertcondition(ta.crossunder(rocLine, 0), "ROC cross down", "ROC crossed below zero")

ta.roc(close, length) is the percent-change Rate of Change; smoothing it with a short ta.sma tames the noise, and colouring by sign (green above zero, red below) makes the momentum regime obvious — matching the output chart.

As a histogram

plot(rocLine, "ROC", style=plot.style_columns,
     color = rocLine >= 0 ? #0ca30c : #d03b3b)

A column style reads nicely for a zero-centered oscillator like ROC.

A signal line and a Coppock bonus

Adding a moving average of ROC gives you crossover signals, and the Coppock Curve is just weighted ROCs — both a couple of lines:

// Signal-line crossover:
rocSig = ta.sma(rocLine, 9)
plot(rocSig, "Signal", color=color.new(#eb6834, 0))
alertcondition(ta.crossover(rocLine, rocSig), "ROC/sig cross", "ROC crossed its signal")

// Coppock Curve: weighted MA of (ROC14 + ROC11):
coppock = ta.wma(ta.roc(close, 14) + ta.roc(close, 11), 10)

ta.wma weights recent bars more; the Coppock turning up from below zero is a classic long-term bottom hint — a real indicator built from nothing but ROC.

Gotchas

  • ta.roc is the percent form. It returns 100 × (close − close[n]) / close[n], oscillating around 0. ta.mom gives the absolute-difference Momentum instead.
  • No fixed levels. ROC is unbounded; there’s no built-in overbought/oversold, so judge extremes relative to recent history.
  • Smoothing trade-off. More smoothing = fewer false zero-crosses but more lag.

Same indicator elsewhere: Python, MQL5, EasyLanguage, NinjaScript. Then test an ROC rule in AlgoGen.


This post is educational, not financial advice. Indicators describe the past; they don’t predict the future. Backtest anything before you risk real money on it.

Sources and further reading

  1. Pine Script built-ins (TradingView)

Historical research from the Algogen archive. Not investment advice.

Blog

Have a strategy idea?

Describe it in plain English, preview where your rules fire, then decide whether the evidence is worth a backtest.

Keep me postedHow it works