Trading metric
Correlation Coefficient Calculator
Paste two series of prices and get the Pearson correlation coefficient between them, either on the raw prices or on their period-by-period returns. It is the same quantity Pine Script's ta.correlation computes.
What the correlation coefficient is
The Pearson correlation coefficient, usually written r, measures how closely two series move together in a straight-line sense. It runs from −1 to +1. A value near +1 means the two rise and fall together, a value near −1 means one tends to rise when the other falls, and a value near 0 means there is no linear relationship between them.
The formula centres each series on its mean, multiplies the paired deviations, and divides by the product of the two series' spread: r = Σ(x − x̄)(y − ȳ) / √(Σ(x − x̄)² × Σ(y − ȳ)²). If either series is constant, its spread is zero and r is undefined, which is why this calculator shows a dash in that case.
Prices or returns
Two prices that both trend upward over time will often show a high correlation even if their day-to-day moves are unrelated, because the shared trend dominates the calculation. Correlating returns removes that trend and compares the bar-to-bar changes instead, which is the more usual choice when comparing instruments. Pine Script's ta.correlation works on whatever series you give it, so pass returns in if that is what you want to measure.
Correlation also describes only linear association over the window you used. It changes as the window moves, it says nothing about cause, and a short sample can produce a coefficient that looks strong by chance.
What are TradingView and Pine Script?
TradingView is one of the most widely used charting and market-analysis platforms, where traders and analysts study price movement across stocks, crypto, forex, and futures on interactive charts. Pine Script is TradingView's own lightweight programming language, created so anyone can build custom tools that run directly on those charts.
People use Pine Script to build four main kinds of tools. Indicators calculate and plot values on the chart, exactly like the calculation above, but recomputed automatically on every bar. Strategies add explicit entry and exit rules and can be backtested against historical data in TradingView's Strategy Tester to see how they would have behaved. Screeners scan many symbols at once for conditions you define. Alerts notify you the moment a condition you specified occurs, so you do not have to watch the screen.
The value is precision and automation. Instead of eyeballing a chart, you describe exactly what you want measured, visualized, or notified about, and TradingView runs it consistently across any market and timeframe. That is why traders, analysts, and developers write Pine Script: it turns a manual charting idea into a repeatable tool. These tools are for tracking, visualizing, and testing market ideas; they do not tell you what to trade, and that decision always remains yours.
Writing that code by hand means learning Pine Script's syntax, its type system, and the exact names of hundreds of built-in functions. It is a real programming language, and small mistakes stop a script from compiling in the Pine Editor.
Turn this into Pine Script
This calculator gives you one coefficient for the two series you pasted. On a chart you usually want a rolling value. The script pulls the other symbol with request.security and passes both series to ta.correlation over a lookback length, so the line updates every bar.
//@version=6
indicator("Correlation with another symbol", overlay=false)
otherSymbol = input.symbol("SPY", "Compare with")
length = input.int(20, "Length", minval=2)
otherClose = request.security(otherSymbol, timeframe.period, close)
corr = ta.correlation(close, otherClose, length)
plot(corr, "Correlation", color=color.blue)
hline(0, "Zero", color=color.gray)
hline(1, "+1", color=color.new(color.gray, 60))
hline(-1, "-1", color=color.new(color.gray, 60))PineScripter is an AI built specifically for Pine Script. You describe what you want in plain English and it writes TradingView-ready v6 code. Because it is specialized on the Pine Script language and its exact function signatures, it tends to produce code that compiles far more reliably than general-purpose models like ChatGPT, which often invent functions that do not exist in Pine Script.
Related free calculators
From the blog
PineScripter is an AI developer tool that helps you write Pine Script code. It is not a financial advisor and will never offer financial, investment, or trading advice. Everything on this page, including the calculator and the explanations, is provided purely for educational and informational purposes. Any decision about how to interpret an indicator or trade a market is entirely your own. See our full disclaimer for more.