Skip to main content

ROC

Source

https://github.com/quadcode-tech/quadcodescript-library/blob/master/momentum/rate_of_change.lua

Syntax Format

roc(series[, period])

Overview

ROC (Rate of Change) is a momentum oscillator, which provides data on the change of the current series value over the given period. The returned value is provided as a percentage.

Parameters

ParameterTypePurposeDefault State
seriesseriesInput series, taken into calculation-
periodintegerInput period, taken into calculation1

Returns: series.

Example

instrument { name = "Rate of Change", overlay = false }

period = input (9, "period", input.integer, 1)

source = input (1, "source", input.string_selection, inputs.titles)

input_group {
"ROC Line",
color = input { default = "#57A1D0", type = input.color },
width = input { default = 1, type = input.line_width}
}

input_group {
"Baseline",
zero_color = input { default = rgba(255,255,255,0.15), type = input.color },
zero_width = input { default = 1, type = input.line_width },
zero_visible = input { default = true, type = input.plot_visibility }
}

local sourceSeries = inputs [source]

res = roc (sourceSeries, period)

if zero_visible then
hline (0, "", zero_color, zero_width, 0, style.dash_line)
end

plot (res, "ROC", color, width)

Formula

The formula for calculating ROC is:

image.png