Skip to content
GetProfitable
Search
Momentum

Rate of Change

The percentage change in price over a chosen number of bars, drawn as columns around a zero line so the sign and the size of momentum are readable without reference to the price scale.

indicator
//@version=6
indicator("Rate of Change", "ROC")

length = input.int(9, "Lookback bars", minval = 1, group = "Settings")
src = input.source(close, "Source", group = "Settings")
bull = input.color(#26A69A, "Positive", group = "Style")
bear = input.color(#EF5350, "Negative", group = "Style")
lineCol = input.color(#787B86, "Zero line", group = "Style")

roc = ta.roc(src, length)

plot(roc, "Rate of change", style = plot.style_columns, color = roc >= 0 ? color.new(bull, 30) : color.new(bear, 30))
hline(0, "Zero", color = color.new(lineCol, 40))

turnedPositive = ta.crossover(roc, 0)
turnedNegative = ta.crossunder(roc, 0)
plotshape(turnedPositive, "Turned positive", location = location.bottom, style = shape.triangleup, color = bull, size = size.tiny)
plotshape(turnedNegative, "Turned negative", location = location.top, style = shape.triangledown, color = bear, size = size.tiny)
alertcondition(turnedPositive, "Rate of change turned positive", "Price is now above where it was at the start of the lookback")
alertcondition(turnedNegative, "Rate of change turned negative", "Price is now below where it was at the start of the lookback")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.

What it will not do

  • A zero cross only says the current price has caught up with the price N bars ago. It is a restatement of recent history, not a forecast.
  • The reading is as much about the bar that leaves the window as the bar that enters it, so a spike N bars ago produces a move now with nothing happening today.
  • Percentage change is unbounded and unsmoothed, which makes it jumpy on illiquid instruments and around gaps.

Written from this description

Plot the percentage change of the source over N bars as columns, green above zero and red below, draw a zero line, and mark the bars where the reading crosses zero in either direction.

Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.