StatisticalPine Script v6

ta.correlation()

Correlation Coefficient

Describes the degree to which two series tend to deviate from their ta.sma values.

Syntax

Syntax
ta.correlation(source1, source2, length) → series float

Arguments

ParameterTypeDescription
source1series int/floatFirst series.
source2series int/floatSecond series.
lengthseries intNumber of bars in the rolling window.

Returns

Correlation coefficient.

Remarks

na values in the source series are ignored.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.correlation")
plot(ta.correlation(close, open, 20), title="Close vs Open corr")

Trading Applications

Measure correlation between two assets

Build pairs trading strategies

Identify diversification opportunities

Monitor inter-market relationships

Related Functions

Frequently Asked Questions

Generate ta.correlation() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.correlation() and other built-in functions instantly.