ta.pctchange
Take the fractional change of a series over the last n bars.
ta.pctchange(source, length)source / source[length] - 1, a fraction: exactly ta.ret, under its statistics name. The percentage version is ta.roc, which is this times 100. That settles the roc, ret and pctchange confusion: ta.roc is the only one of the three scaled by 100.
Parameters
A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
source | Series | number | - | - | The series to read. |
length | Constant | number | 1 | 1 to 10000 | Window in observed bars. |
Output
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
lengthbars. Names in the warm-up are this operator’s parameters.- Missing values
- na until
lengthbars of history exist. na when the earlier observation is zero or na.
Example
ta.pctchange(close, 1)plot(ta.pctchange(close, 1), "Percent change")