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 Source series. source2 required series float Target series. length required series int Length (number of bars back). Return Type
series float Example
//@lipi=2
indicator("Price-Volume Correlation", overlay=false)
// Input for correlation period
length = input(20, title="Correlation Length")
// Calculate correlation between closing price and volume
correlationValue = talib.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)