Lipi Reference Lipi

Functions

talib.correlation()

Correlation between two series, `source1` and `source2`, measured over `length` bars. Both series are ordinary arguments, so you can correlate anything a script can compute — not only prices.

Syntax

                talib.correlation(series float source1, series float source2, series int length) → series float
              

Arguments

source1 required series float First of the two series being compared.
source2 required series float Second of the two series being compared.
length required series int How many bars the measurement covers.

Return Type

series float

Example


          indicator("Price-Volume Correlation", overlay=false)
// Input for correlation period
length = input(20, title="Correlation Length")
// Calculate correlation between closing price and volume
correlationValue = ta.correlation(close, volume, length)
// Plot correlation value
plot(correlationValue, title="Price-Volume Correlation", color=color.blue, linewidth=2)
// Add reference levels
hline(1, "Perfect Positive", color=color.green)
hline(0, "No Correlation", color=color.gray)
hline(-1, "Perfect Negative", color=color.red)