All indicators
Momentum / Own pane

Rate of Change

Percent change of price over the last Length bars, around a zero line.

  • ROC
  • Built into Spectral
  • Updates every tick
  • roc
  • rate of change
  • percent change
  • momentum
  • oscillator

By Spectral · v1.0.0

MIT-0: free to use, change and share, no attribution needed. What you build from it is yours.

Already in Spectral: add it from the Indicators toolbox. The file here is the same indicator written as a custom indicator, to change or learn from. Installed, it appears next to the built-in one, marked Custom.

Rate of Change on a Spectral chart
Spectral chart with sample market data, default settings.

Overview

Rate of Change is the percent difference between the current price and the price Length bars ago: 100 x (price - earlier price) / earlier price. Positive values mean price is higher than it was, negative values lower.

How to read it

Above zero price has risen over the lookback, below zero it has fallen; the distance from zero shows how fast. A line that keeps rising shows an accelerating move, one that rolls over while price still climbs shows the advance slowing.

Because it is a percentage, readings compare across instruments and price levels. Extremes are relative to the instrument's own history; there are no fixed overbought or oversold levels.

Settings and limitations

Length defaults to 9 bars, as on TradingView; 12 and 25 are also common. The first value appears on bar Length + 1 (bar 10 with the default). Each value depends on a single earlier bar, so a large move dropping out of the lookback can turn the line even when price is quiet.

Notes

Matches Rate of Change on TradingView and most platforms. Momentum shows the same comparison in price units instead of percent.

Settings

Each setting appears in the indicator's settings panel in Spectral, next to a color setting for every output.

SettingTypeDefaultRange or optionsWhat it does
LengthWhole number91 – 1000Bars back the current price is compared with.
SourcePrice sourcecloseopen, high, low, close, hlc3Price the change is calculated from.

Presets

Each preset is its own entry in the Indicators toolbox, with these settings changed.

Toolbox entryShort nameSettings
Rate of Change (12)ROC 12Length: 12
Rate of Change (25)ROC 25Length: 25

What it draws

Lines

  • ROCsolid · 1.5 px · primary#8AA9C3

Levels

  • Zero linedotted · 1 px#788493

Source

Save it as rate-of-change.js and add it with Indicators → Custom indicators → Add file…. The format is explained in the custom indicators guide.

// Copyright (c) 2026 Spectral
// SPDX-License-Identifier: MIT-0
// Free to use, copy, modify and share: https://spectral.trade/docs/custom-indicators/LICENSE.txt
/** @type {import('./spectral-indicator').IndicatorV2} */
export default {
  schemaVersion: 2,
  id: 'rate-of-change',
  name: 'Rate of Change',
  shortName: 'ROC',
  version: '1.0.0',
  author: 'Spectral',
  description: 'Percent change of price over the last Length bars, around a zero line.',
  pane: 'oscillator',
  live: { lookback: 'length' },
  inputs: {
    length: { type: 'integer', label: 'Length', default: 9, min: 1, max: 1000, description: 'Bars back the current price is compared with.' },
    source: { type: 'source', label: 'Source', default: 'close', description: 'Price the change is calculated from.' },
  },
  plots: {
    roc: { label: 'ROC', color: '#8AA9C3', lineWidth: 1.5, primary: true },
  },
  levels: {
    zero: { label: 'Zero line', color: '#788493', lineStyle: 'dotted' },
  },
  presets: [
    { id: 'roc-12', name: 'Rate of Change (12)', shortName: 'ROC 12', inputs: { length: 12 } },
    { id: 'roc-25', name: 'Rate of Change (25)', shortName: 'ROC 25', inputs: { length: 25 } },
  ],
  docs: {
    overview: 'Rate of Change is the percent difference between the current price and the price Length bars ago: 100 x (price - earlier price) / earlier price. Positive values mean price is higher than it was, negative values lower.',
    howToRead: 'Above zero price has risen over the lookback, below zero it has fallen; the distance from zero shows how fast. A line that keeps rising shows an accelerating move, one that rolls over while price still climbs shows the advance slowing.\n\nBecause it is a percentage, readings compare across instruments and price levels. Extremes are relative to the instrument\'s own history; there are no fixed overbought or oversold levels.',
    settings: 'Length defaults to 9 bars, as on TradingView; 12 and 25 are also common. The first value appears on bar Length + 1 (bar 10 with the default). Each value depends on a single earlier bar, so a large move dropping out of the lookback can turn the line even when price is quiet.',
    notes: 'Matches Rate of Change on TradingView and most platforms. Momentum shows the same comparison in price units instead of percent.',
  },
  calculate(ctx) {
    const { bars, inputs, ta } = ctx;
    const source = ta.source(bars, inputs.source);
    const length = inputs.length;
    const roc = source.map((value, index) => {
      const earlier = index >= length ? source[index - length] : null;
      return earlier === null || earlier === 0 ? null : (100 * (value - earlier)) / earlier;
    });
    return { plots: { roc }, levels: { zero: 0 } };
  },
};

Adapt it with an LLM

Paste this into your assistant and replace the second-to-last line with the change you want.

Start from this Spectral custom indicator: https://spectral.trade/indicators/rate-of-change.js
Format reference: https://spectral.trade/docs/custom-indicators.llm.md
Keep the file format and every rule of the reference; give the result a new id, name, shortName and version, and update docs and input descriptions to match.
Keep its live updates exact and fast (section "Fast live updates" of the reference): carry values from bar to bar only through ctx.ta, and raise live.lookback if the change reads further back; Spectral rejects a file whose live updates differ from a full recalculation or are too slow.
Change I want: <describe the change>
Answer with the complete file in one code block, ready to save as <id>.js.