Steversteves

Ticker Correlation Reference Indicator

Steversteves Updated   
Hello,

I am super excited to be releasing this Ticker Correlation assessment indicator. This is a big one so let us get right into it!

Inspiration:

The inspiration for this indicator came from a similar indicator by Balipour called the Correlation with P-Value and Confidence Interval. It’s a great indicator, you should check it out!

I used it quite a lot when looking for correlations; however, there were some limitations to this indicator’s functionality that I wanted. So I decided to make my own indicator that had the functionality I wanted. I have been using this for some time but decided to actual spruce it up a bit and make it user friendly so that I could share it publically. So let me get into what this indicator does and, most importantly, the expanded functionality of this indicator.

What it does:

This indicator determines the correlation between 2 separate tickers. The user selects the two tickers they wish to compare and it performs a correlation assessment over a defaulted 14 period length and displays the results. However, the indicator takes this much further. The complete functionality of this indicator includes the following:

1. Assesses the correlation of all 4 ticker variables (Open, High, Low and Close) over a user defined period of time (defaulted to 14);
2. Converts both tickers to a Z-Score in order to standardize the data and provide a side by side comparison;
3. Displays areas of high and low correlation between all 4 variables;
4. Looks back over the consistency of the relationship (is correlation consistent among the two tickers or infrequent?);
5. Displays the variance in the correlation (there may be a statistically significant relationship, but if there is a high variance, it means the relationship is unstable);
6. Permits manual conversion between prices; and
7. Determines the degree of statistical significance (be it stable, unstable or non-existent).

I will discuss each of these functions below.

Function 1: Assesses the correlation of all 4 variables.

The only other indicator that does this only determines the correlation of the close price. However, correlation between all 4 variables varies. The correlation between open prices, high prices, low prices and close prices varies in statistically significant ways. As such, this indicator plots the correlation of all 4 ticker variables and displays each correlation.

Assessing this matters because sometimes a stock may not have the same magnitude in highs and lows as another stock (one stock may be more bullish, i.e. attain higher highs in comparison to another stock). Close price is helpful but does not pain the full picture. As such, the indicator displays the correlation relationship between all 4 variables (image below):


Function 2: Converts both tickers to Z-Score

Z-Score is a way of standardizing data. It simply measures how far a stock is trading in relation to its mean. As such, it is a way to express both tickers on a level playing field. Z-Score was also chosen because the Z-Score Values (0 – 4) also provide an appropriate scale to plot correlation lines (which range from 0 to 1).

The primary ticker (Ticker 1) is plotted in blue, the secondary comparison ticker (Ticker 2) is plotted in a colour changing format (which will be discussed below). See the image below:


Function 3: Displays areas of high and low correlation

While Ticker 1 is plotted in a static blue, Ticker 2 (the comparison ticker) is plotted in a dynamic, colour changing format. It will display areas of high correlation (i.e. areas with a P value greater than or equal to 0.9 or less than and equal to -0.9) in green, areas of moderate correlation in white. Areas of low correlation (between 0.4 and 0 or -0.4 and 0) are in red. (see image below):


Function 4: Checks consistency of relationship

While at the time of assessing a stock there very well maybe a high correlation, whether that correlation is consistent or not is the question. The indicator employs the use of the SMA function to plot the average correlation over a defined period of time. If the correlation is consistently high, the SMA should be within an area of statistical significance (over 0.5 or under -0.5). If the relationship is inconsistent, the SMA will read a lower value than the actual correlation.

You can see an example of this when you compare ETH to Tezos in the image below:


You can see that the correlation between ETH and Tezo’s on the high level seems to be inconsistent. While the current correlation is significant, the SMA is showing that the average correlation between the highs is actually less than 0.5.

The indicator also tells the user narratively the degree of consistency in the statistical relationship. This will be discussed later.

Function 5: Displays the variance

When it comes to correlation, variance is important. Variance simply means the distance between the highest and lowest value. The indicator assess the variance. A high degree of variance (i.e. a number surpassing 0.5 or greater) generally means the consistency and stability of the relationship is in issue. If there is a high variance, it means that the two tickers, while seemingly significantly correlated, tend to deviate from each other quite extensively.

The indicator will tell the user the variance in the narrative bar at the bottom of the chart (see image below):


Function 6: Permits manual conversion of price

One thing that I frequently want and like to do is convert prices between tickers. If I am looking at SPX and I want to calculate a price on SPY, I want to be able to do that quickly. This indicator permits you to do that by employing a regression based formula to convert Ticker 1 to Ticker 2.
The user can actually input which variable they would like to convert, whether they want to convert Ticker 1 Close to Ticker 2 Close, or Ticker 1 High to Ticker 2 High, or low or open.

To do this, open the settings and click “Permit Manual Conversion”. This will then take the current Ticker 1 Close price and convert it to Ticker 2 based on the regression calculations.

If you want to know what a specific price on Ticker 1 is on Ticker 2, simply click the “Allow Manual Price Input” variable and type in the price of Ticker 1 you want to know on Ticker 2. It will perform the calculation for you and will also list the standard error of the calculation.

Below is an example of calculating a SPY price using SPX data:


Above, the indicator was asked to convert an SPX price of 4,100 to a SPY price. The result was 408.83 with a standard error of 4.31, meaning we can expect 4,100 to fall within 408.83 +/- 4.31 on SPY.

Function 7: Determines the degree of statistical significance

The indicator will provide the user with a narrative output of the degree of statistical significance. The indicator looks beyond simply what the correlation is at the time of the assessment. It uses the SMA and the highest and lowest function to make an assessment of the stability of the statistical relationship and then indicates this to the user. Below is an example of IWM compared to SPY:


You will see, the indicator indicates that, while there is a statistically significant positive relationship, the relationship is somewhat unstable and inconsistent. Not only does it tell you this, but it indicates the degree of inconsistencies by listing the variance and the range of the inconsistencies.

And below is SPY to DIA:


SPY to BTCUSD:


And finally SPY to USDCAD Currency:


Other functions:

The indicator will also plot the raw or smoothed correlation result for the Open, High, Low or Close price. The default is to close price and smoothed. Smoothed just means it is displaying the SMA over the raw correlation score. Unsmoothing it will show you the raw correlation score.
The user also has the ability to toggle on and off the correlation table and the narrative table so that they can just review the chart (the side by side comparison of the 2 tickers).

Customizability

All of the functions are customizable for the most part. The user can determine the length of lookback, etc. The default parameters for all are 14. The only thing not customizable is the assessment used for determining the stability of a statistical relationship (set at 100 candle lookback) and the regression analysis used to convert price (10 candle lookback).

User Notes and important application tips:

#1: If using the manual calculation function to convert price, it is recommended to use this on the hourly or daily chart.

#2: Leaving pre-market data on can cause some errors. It is recommended to use the indicator with regular market hours enabled and extended market hours disabled.

#3: No ticker is off limits. You can compare anything against anything! Have fun with it and experiment!

Non-Indicator Specific Discussions:

Why does correlation between stocks mater?

This can matter for a number of reasons. For investors, it is good to diversify your portfolio and have a good array of stocks that operate somewhat independently of each other. This will allow you to see how your investments compare to each other and the degree of the relationship.
Another function may be getting exposure to more expensive tickers. I am guilty of trading IWM to gain exposure to SPY at a reduced cost basis :-).

What is a statistically significant correlation?

The rule of thumb is anything 0.5 or greater is considered statistically significant. The ideal setup is 0.9 or more as the effect is almost identical. That said, a lot of factors play into statistical significance. For example, the consistency and variance are 2 important factors most do not consider when ascertaining significance. Perhaps IWM and SPY are significantly correlated today, but is that a reliable relationship and can that be counted on as a rule?

These are things that should be considered when trading one ticker against another and these are things that I have attempted to address with this indicator!

Final notes:
I know I usually do tutorial videos. I have not done one here, but I will. Check back later for this.

I hope you enjoy the indicator and please feel free to share your thoughts and suggestions!

Safe trades all!
Release Notes:
Fixed some code.

As well, I have completed a brief tutorial video:


Premium indicators and content have launched! Get access at: www.patreon.com/steversteves
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?