TradingView
Steversteves
27 Haz 2023 01:12

Trend Correlation Heatmap 

iShares Russell 2000 ETFArca

Açıklama

Hello everyone!

I am excited to release my trend correlation heatmap, or trend heatmap for short.

Per usual, I think its important to explain the theory before we get into the use of the indicator, so let's get into the theory!

The theory:

So what is a correlation?

Correlation is the relationship one variable has to another. Correlations are the basis of everything I do as a quantitative trader. From the correlation between the same variables (i.e. autocorrelation), the correlation between other variables (i.e. VIX and SPY, SPY High and SPY Low, DXY and ES1! close, etc.) and, as well, the correlation between price and time (time series correlation).

This may sound very familiar to you, especially if you are a user, observer or follower of my ideas and/or indicators. Ninety-five percent of my indicators are a function of one of those three things. Whether it be a time series based indicator (i.e.my time series indicator), whether it be autocorrelation (my autoregressive cloud indicator or my autocorrelation oscillator) or whether it be regressive in nature (i.e. my SPY Volume weighted close, or even my expected move which uses averages in lieu of regressive approaches but is foundational in regression principles. Or even my VIX oscillator which relies on the premise of correlations between tickers.) So correlation is extremely important to me and while its true I am more of a regression trader than anything, I would argue that I am more of a correlation trader, because correlations are the backbone of how I develop math models of stocks.

What I am trying to stress here is the importance of correlations. They really truly are foundational to any type of quantitative analysis for stocks. And as such, understanding the current relationship a stock has to time is pivotal for any meaningful analysis to be conducted.

So what is correlation to time and what does it tell us?
Correlation to time, otherwise known and commonly referred to as "Time Series", is the relationship a ticker's price has to the passing of time. It is displayed in the traditional Pearson Correlation Coefficient or R value and can be any value from -1 (strong negative relationship, i.e. a strong downtrend) to + 1 (i.e. a strong positive relationship, i.e. a strong uptrend). The higher or lower the value the stronger the up or downtrend is.

As such, correlation to time tells us two very important things. These are:
a) The direction of the stock; and
b) The strength of the trend.

Let's take a look at an example:



Above we have a chart of QQQ. We can see a trendline that seems to fit well. The questions we ask as traders are:
1. What is the likelihood QQQ breaks down from this trendline?
2. What is the likelihood QQQ continues up?
3. What is the likelihood QQQ does a false breakdown?

There are numerous mathematical approaches we can take to answer these questions. For example, 1 and 2 can be answered by use of a Cumulative Distribution Density analysis (CDDA) or even a linear or loglinear regression analysis and 3 can be answered, more or less, with a linear regression analysis and standard error ascertainment, or even just a general comparison using a data science approach (such as cosine similarity or Manhattan distance).

But, the reality is, all 3 of these questions can be visualized, at least in some way, by simply looking at the correlation to time. Let's look at this chart again, this time with the correlation heatmap applied:



If we look at the indicator we can see some pivotal things. These are:

1. We have 4, very strong uptrends that span both higher AND lower timeframes. We have a strong uptrend of 0.96 on the 5 minute, 50 candle period. We have a strong uptrend at the 300 candle lookback period on the 1 minute, we have a strong uptrend on the 100 day lookback on the daily timeframe period and we have a strong uptrend on the 5 minute on the 500 candle lookback period.

2. By comparison, we have 3 downtrends, all of which have correlations less than the 4 uptrends. All of the downtrends have a correlation above -0.8 (which we would want lower than -0.8 to be very strong), and all of the uptrends are greater than + 0.80.

3. We can also see that the uptrends are not confined to the smaller timeframes. We have multiple uptrends on multiple timeframes and both short term (50 to 100 candles) and long term (up to 500 candles).

4. The overall trend is strengthening to the upside manifested by a positive Max Change and a Positive Min change (to be discussed later more in-depth).

With this, we can see that QQQ is actually very strong and likely will continue at least some upside. If we let this play out:



We continued up, had one test and then bounced.

Now, I want to specify, this indicator is not a panacea for all trading. And in relation to the 3 questions posed, they are best answered, at least quantitatively, not only by correlation but also by the aforementioned methods (CDDA, etc.) but correlation will help you get a feel for the strength or weakness present with a stock.

What are some tangible applications of the indicator?
For me, this indicator is used in many ways. Let me outline some ways I generally apply this indicator in my day and swing trading:

1. Gauging the strength of the stock: The indictor tells you the most prevalent behavior of the stock. Are there more downtrends than uptrends present? Are the downtrends present on the larger timeframes vs uptrends on the shorter indicating a possible bullish reversal? or vice versa? Are the trends strengthening or weakening? All of these things can be visualized with the indicator.

2. Setting parameters for other indicators: If you trade EMAs or SMAs, you may have a "one size fits all" approach. However, its actually better to adjust your EMA or SMA length to the actual trend itself. Take a look at this:



This is QQQ on the 1 hour with the 200 EMA with 200 standard deviation bands added. If we look at the heatmap, we can see, yes indeed 200 has a fairly strong uptrend correlation of 0.70. But the strongest hourly uptrend is actually at 400 candles, with a correlation of 0.91. So what happens if we change the EMA length and standard deviation to 400? This:



The exact areas are circled and colour coded. You can see, the 400 offers more of a better reference point of supports and resistances as well as a better overall trend fit. And this is why I never advocate for getting married to a specific EMA. If you are an EMA 200 lover or 21 or 51, know that these are not always the best depending on the trend and situation.


Components of the indicator:

Ah okay, now for the boring stuff. Let's go over the functionality of the indicator. I tried to keep it simple, so it is pretty straight forward. If we open the menu here are our options:



We have the ability to toggle whichever timeframes we want. We also have the ability to toggle on or off the legend that displays the colour codes and the Max and Min highest change.

Max and Min highest change: The max and min highest change simply display the change in correlation over the previous 14 candles. An increasing Max change means that the Max trend is strengthening. If we see an increasing Max change and an increasing Min change (the Min correlation is moving up), this means the stock is bullish. Why? Because the min (i.e. ideally a big negative number) is going up closer to the positives. Therefore, the downtrend is weakening.

If we see both the Max and Min declining (red), that means the uptrend is weakening and downtrend is strengthening. Here are some examples:





Final Thoughts:

And that is the indicator and the theory behind the indicator.
In a nutshell, to summarize, the indicator simply tracks the correlation of a ticker to time on multiple timeframes. This will allow you to make judgements about strength, sentiment and also help you adjust which tools and timeframes you are using to perform your analyses.

As well, to make the indicator more user friendly, I tried to make the colours distinctively different. I was going to do different shades but it was a little difficult to visualize. As such, I have included a toggle-able legend with a breakdown of the colour codes!

That's it my friends, I hope you find it useful!

Safe trades and leave your questions, comments and feedback below!
Yorumlar
PineCoders
In the name of all TradingViewers, thank you for your valuable contribution to the community, and congrats!
Steversteves
@PineCoders, Thank you so much! I really appreciate it :-)!
JB7oh2
Another masterpiece
Steversteves
@JB7oh2, Hahaha you're far too kind!
TRinvestment
Hello @Steversteves
I really enjoy this indicator, and I find the usefullness of it really interesting.

I have a regarding the timeframes.

In your example, you are using a 1M, 5M, 30M, 60M - On a daily chart, wouldn't it make sense to use some frames closer to it? like the 4h, weekly?

The reason I am asking is because I am trying to see if it can work with my day trading, and I am thinking about using 1M, 5M, 15M, 30M or 5M, 15M, 30M, 1h.

Would any of them make sense, or is the idea to look at timeframes, that are lowe than the one on the chart?

thanks for helping the tradingview community, really appericate your work!
PineCoders
This publication is now featured in our Editors' Picks: tradingview.com/scripts/editors-picks/
goldleo
5 star indyk :)
TRinvestment
@Steversteves I have a question regarding the script.

1. For a stock like zeal (danish) there is no calculation for it, even though the data goes back more than 10 years.
2. With FOM (danish) as well, the company have full data even though it only have been around for 3 years.

* Is this just because it’s danish stocks? and does this mean I can’t use it on anything else than US?
* And if so why is it different for the index?

zeal = prnt.sc/rP4CGKZOvYZv
Fom = prnt.sc/AGbBzELNYk36

Hope you can help, because I find the indicator really interesting!
TRinvestment
@Steversteves I think I know why now, it's because it's searching for the ticker in the system.

Zeal + FOM is not the first one on the list if you type the ticker, so it will use a different one, which is why I get a different result.

Could you maybe implement a way to choose current ticker or write the ticker, so it's using the same one for all the data? in that way you will avoid getting wrong data.

Keep up the good great.
ChiragPatnaik
Hello!

This is excellent.

A version could be to colour the candles once all selected time frames are in sync (for eg 1,3,5,15,30 are in uptrend with bullish stoch/rsi/macd), then bar gets painted green, else grey and vice versa.
Daha Fazla