Docs

ta.autocorr

Measure whether a series tends to repeat or reverse its own recent moves.

itm
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.

NameKindTypeDefaultRangeDescription
sourceSeriesnumber--The series to read.
lengthConstantnumber-1 to 10000Window in observed bars.
lagConstantnumber11 to 10000How many bars back the window is correlated against.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
length + lag bars. 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 length pairs need that much history). An na resets the accumulation. na when either leg has zero variance over the window.

Example

itm
ta.autocorr(ta.ret(close), 50, 1)
itm
plot(ta.autocorr(ta.ret(close), 50, 1), "Autocorrelation 50")