ta.correlation()Correlation Coefficient
Describes the degree to which two series tend to deviate from their ta.sma values.
Syntax
ta.correlation(source1, source2, length) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| source1 | series int/float | First series. |
| source2 | series int/float | Second series. |
| length | series int | Number of bars in the rolling window. |
Returns
Correlation coefficient.
Remarks
na values in the source series are ignored.
Code Examples
//@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
Frequently Asked Questions
Generate ta.correlation() Code with AI
Draft Pine Script using ta.correlation() with Pineify's AI Coding Agent, then review the arguments and test the result on your chart. Usage depends on your plan and available credits.
Related Pine Script Functions
ta.variance() - Variance
Learn how to use ta.variance() in Pine Script. Calculate statistical variance for volatility analysis.
ta.stdev() - Standard Deviation
Learn how to use ta.stdev() in Pine Script. Syntax, parameters, code examples for statistical standard deviation calculation.
ta.rci() - Rank Correlation Index
Learn how to use ta.rci() in Pine Script. Syntax, parameters, code examples for the Rank Correlation Index.
ta.linreg() - Linear Regression
Learn how to use ta.linreg() in Pine Script. Syntax, parameters, code examples for linear regression curve fitting.
ta.percentrank() - Percent Rank
Learn how to use ta.percentrank() in Pine Script. Calculate percentile ranking of current value.