[ AlgoChart ] - Pearson Index CorrelationCorrelation Indicator (Pearson Index)
The correlation indicator measures the strength and direction of the relationship between two financial assets using the Pearson Index.
Correlation values range from +100 to -100, where:
+100 indicates perfect positive correlation, meaning the two assets tend to move in the same direction.
-100 indicates perfect negative correlation, where the two assets move in opposite directions.
The neutral zone ranges from +25% to -25%, suggesting that the asset movements are independent, with no clear correlation between them.
Interpreting Correlation Levels:
Correlation above +75%: The two assets tend to move similarly and in the same direction. This may indicate a risk of overexposure if both assets are traded in the same direction, as their movements will be very similar, increasing the likelihood of double losses or gains.
Correlation below -75%: The two assets tend to move similarly but in opposite directions. This correlation level can be useful for strategies that benefit from opposing movements between assets, such as trading pairs with inverse dynamics.
Practical Use of the Indicator:
Risk management: Use the indicator to monitor asset correlations before opening positions. High correlation may indicate you are duplicating exposure, as two highly correlated assets tend to move similarly. This helps avoid excessive risk and improves portfolio diversification.
Statistical Arbitrage: During moments of temporary decorrelation between two assets, the indicator can be used for statistical arbitrage strategies. In such cases, you can take advantage of the divergence by opening positions and closing them when the correlation returns to higher or positive levels, thus potentially profiting from the reconvergence of movements.
While the correlation indicator provides valuable insights into asset relationships, it is most effective when used in conjunction with other concepts and tools. On its own, it may offer limited relevance in trading decisions.
Pearsonscoefficient
Advanced Trend Detection StrategyThe Advanced Trend Detection Strategy is a sophisticated trading algorithm based on the indicator "Percent Levels From Previous Close".
This strategy is based on calculating the Pearson's correlation coefficient of logarithmic-scale linear regression channels across a range of lengths from 50 to 1000. It then selects the highest value to determine the length for the channel used in the strategy, as well as for the computation of the Simple Moving Average (SMA) that is incorporated into the strategy.
In this methodology, a script is applied to an equity in which multiple length inputs are taken into consideration. For each of these lengths, the slope, average, and intercept are calculated using logarithmic values. Deviation, the Pearson's correlation coefficient, and upper and lower deviations are also computed for each length.
The strategy then selects the length with the highest Pearson's correlation coefficient. This selected length is used in the channel of the strategy and also for the calculation of the SMA. The chosen length is ultimately the one that best fits the logarithmic regression line, as indicated by the highest Pearson's correlation coefficient.
In short, this strategy leverages the power of Pearson's correlation coefficient in a logarithmic scale linear regression framework to identify optimal trend channels across a broad range of lengths, assisting traders in making more informed decisions.
Pearsons R historic breaks ( for making strategy out of it )Pearsons R adjustments of linear regressions is a good tool to analyse visually the trend basis channeling of the market,
one of the common challenges in the scripts which i came across the tradingview community is the lack of the historic places put over the charts where the price actually crossed up/below the channel boundaries,
For me in order to do so we would have to replay the scripts over and over.
So I came up with an addon extension to a good script on the community ()
I have added the historic marks over the charts ( blue/green/red/orange Arrows which you see on the charts)
These arrows are the places where the price have crossed the channel boundaries historically
So,
Blue arrow = Bull Intent ,Place where the upper channel boundary line have been crossed
Orange arrow = Bear Intent , Place where the Lower channel boundary line have been crossed
Green arrow = Bull Max , Place where the Maximum Upper channel boundary line have been crossed
Red arrow = Bear Max , Place where the Minimum Lower channel boundary line have been crossed
For me this type of approach is good for making a strategy out of the concepts visually, in congestion to other indicators
I would suggest you guys to check this on alert basis with your setups to derive out the best from linear regressions
Lastly it would be a pleasure to give credits to the creators of Pearsons R scripts in Tradingview
@midtownsk8rguy
@TradeBoneDogs
@x11joe
Also thanking Tradingview for providing us such an awesome community and platform :)
Spearman Rank Correlation CoefficientI'm pleased to introduce this script in honor of the new array functions introduced to PineScript version 4.0. This update is a long time coming and opens the door to amazing scripting possibilities!
Definition
Named after Charles Spearman and denoted by the Greek letter ‘ ρ ’ (rho), the Spearman rank correlation coefficient is the nonparametric version of the Pearson correlation coefficient . Use the Spearman rank correlation when you have two ranked variables, and you want to see whether the two variables covary. That is, as one variable increases/decreases, the other variable tends to increase/decrease respectively.
It is best used to discover if two variables (and in this first version of the indicator, two ticker symbols) increase and decrease together. There are advantages to using this version of correlation vs. the Pearson R.
Interpretation
The value oscillates between +1 and -1.
A value of +1 means the two variables are perfectly correlated, that is they are increasing and decreasing together in perfect harmony.
A value of -1 means the two variables exhibit a perfect negative correlation, that is they increase and decrease oppositely.
A value of zero means the two variables are not correlated at all (noise).
Dual Purpose Pine Based CorrelationThis is my "Pine-based" correlation() function written in raw Pine Script. Other names applied to it are "Pearson Correlation", "Pearson's r", and one I can never remember being "Pearson Product-Moment Correlation Coefficient(PPMCC)". There is two basic ways to utilize this script. One is checking correlation with another asset such as the S&P 500 (provided as a default). The second is using it as a handy independent indicator correlated to time using Pine's bar_index variable. Also, this is in fact two separate correlation indicators with independent period adjustments, so I guess you could say this indicator has a dual purpose split personality. My intention was to take standard old correlation and apply a novel approach to it, and see what happens. Either way you use it, I hope you may find it most helpful enough to add to your daily TV tool belt.
You will notice I used the Pine built-in correlation() in combination with my custom function, so it shows they are precisely equal, even when the first two correlation() parameters are reversed on purpose or by accident. Additionally, there's an interesting technique to provide a visually appealing line with two overlapping plot()s combined together. I'm sure many members may find that plotting tactic useful when a bird's nest of plotting is occurring on the overlay pane in some scenarios. One more thing about correlation is it's always confined to +/-1.0 irregardless of time intervals or the asset(s) it is applied to, making it a unique oscillator.
As always, I have included advanced Pine programming techniques that conform to proper "Pine Etiquette". For those of you who are newcomers to Pine Script, this code release may also help you comprehend the "Power of Pine" by employing advanced programming techniques in Pine exhibiting code utilization in a most effective manner. One of the many tricks I applied here was providing floating point number safeties for _correlation(). While it cannot effectively use a floating point number, it won't error out in the event this should occur especially when applying "dominant cycle periods" to it, IF you might attempt this.
NOTICE: You may have observed there is a sqrt() custom function and you may be thinking... "Did he just sick and twistedly overwrite the Pine built-in sqrt() function?" The answer is... YES, I am and yes I did! One thing I noticed, is that it does provide slightly higher accuracy precision decimal places compared to the Pine built-in sqrt(). Be forewarned, "MY" sqrt() is technically speaking slower than snail snot compared to the native Pine sqrt(), so I wouldn't advise actually using it religiously in other scripts as a daily habit. It is seemingly doing quite well in combination with these simple calculations without being "sluggish". Lastly, of course you may always just delete the custom sqrt() function, via Pine Editor, and then the script will still operate flawlessly, yet more efficiently.
Features List Includes:
Dark Background - Easily disabled in indicator Settings->Style for "Light" charts or with Pine commenting
AND much, much more... You have the source!
The comments section below is solely just for commenting and other remarks, ideas, compliments, etc... regarding only this indicator, not others. When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members, I may implement more ideas when they present themselves as worthy additions. As always, "Like" it if you simply just like it with a proper thumbs up, and also return to my scripts list occasionally for additional postings. Have a profitable future everyone!
Correlation Coefficient [DW]This is a simple study designed to visualize price correlation coefficients between multiple securities.
Correlation Candles [DW]This is a simple study designed to visualize price correlations between securities.