ta.autocorr
Measure whether a series tends to repeat or reverse its own recent moves.
ta.autocorr(source, length, lag)Autocorrelation at a fixed lag: the Pearson correlation of the length pairs (source, source[lag]) ending at the current bar, each leg taking its own mean. It is exactly ta.correlation(source, source[lag], length). That is the stated convention, and it differs from the textbook r_k that shares one mean and one variance across both legs. In [-1, 1].
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 to 10000 | Window in observed bars. |
lag | Constant | number | 1 | 1 to 10000 | How many bars back the window is correlated against. |
Output
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
length + lagbars. Names in the warm-up are this operator’s parameters.- Missing values
- Returns na until length + lag consecutive non-na observations have been seen (the
lengthpairs need that much history). An na resets the accumulation. na when either leg has zero variance over the window.
Example
ta.autocorr(ta.ret(close), 50, 1)plot(ta.autocorr(ta.ret(close), 50, 1), "Autocorrelation 50")