• Quant (h)Edge
  • Posts
  • [TradingView Indicator] Examples of Using Autocorrelation To Confirm Trends.

[TradingView Indicator] Examples of Using Autocorrelation To Confirm Trends.

In a previous post, I wrote the following about using autocorrelation in trading.

In theory, autocorrelations (correlation of a variable with lagged values) should be a great timing indicator. It goes positive when a trend is confirmed and negative when the trend breaks down so you can use it to follow the trend of play the mean-reversion. But it is not as straightforward as that. If you use autocorrelation to confirm a trend, it would only be helpful if the trend starts slowly (small moves) and then develops into big moves or persistent moves in one direction. If the trend starts with big moves, the autocorrelation will turn positive when most of the move has happened. If you use it for mean-reversion, you need to watch out for noise. You first need to look for evidence that the trend is done using other tools like RSI, momentum indicators, sentiment, fundamental/macro changes, etc, then you can look for entry points using the autocorrelation. Another problem is that you have to decide on a lookback period. RSI uses 14 by default but since few ever change it, then everyone is basically using the same RSI indicators. Since autocorrelation is not a popular indicator, the choice of lookback period matters. You can try to optimize it (fitting past data) but you would likely be overfitting and past performance would be no indicator of future performance.

I wrote a TradingView indicator that calculates autocorrelation - which takes values between -1 and 1- and normalizes it to span 0 and 1. That way, it can share a y-axis with RSI making it possible to use them together. Here are some examples.

The Recent Oil Move Up

Oil is up 9% in the last 30 days, but the bulk of that move happened yesterday and today. The chart below shows an arrow where the autocorrelation starts going higher, then crosses the 0.5 value, which is the same as crossing from -ve to +ve, thereby confirming the trend. At the same time, RSI is trending higher indicating a bullish trend. This would have been a great entry point for long oil (if you already had that bias) since you would have caught a big part of the move higher.

Using autocorrelation for trend confirmation works best when the trend starts slowly—small moves in the trending direction or a persistent move in one direction. This is an example of the latter. I posited that if the trend starts with big moves, the entry signal will be late, but that doesn’t seem to be the case because of volatility expansion: a big move out of nowhere tends to be followed by moves of similar magnitude. This is one of the stylized facts of volatility and is known as volatility clustering—periods of low volatility and high volatility cluster together.

Nat Gas Up Then Down

Going towards the end of the year, there were concerns that the end of the Russia-Ukraine deal that allowed Russia to transit nat gas through Ukraine for Europe would cause a decrease in supply while keeping demand unchaged, hence prices would go up. Nat Gas gapped higher. Autocorrelation would have given you good entries for the move up, and the move down, when the market found out that the affected European countries had prepared in advance for this.

In the first case, you have the RSI bottoming out and autocorrelation starting to rise which confirms the trend upwards. In the second case, you have RSI decreasing from its peak while autocorrelation sharply rises giving the entry signal for a short.

Be Careful of False Signals

False signals happen when RSI establishes a direction and autocorrelation gives the entry signal, but then a sharp contrarian move happens immediately after. This can happen when the price moves very slowly in one direction. The chart shows an example of this (where the arrow in the price chart is). However, in this particular case, the trade would have still worked. You have RSI decreasing steadily and autocorrelation crossing above 0.5 to signal a short entry, but prices immediately pop higher. The near-term resistance isn’t breached and later you get another short entry signal.

So Be Sure To Use Both RSI and Autocorrelation, and After Doing Your Other Research

Indicators are not meant to be predictive, so you first have to do your research and then use these indicators to fine-tune your entries.

This is SPX today. Both RSI and autocorrelation started moving higher yesterday and today the entry signal was generated early enough for you to catch a good portion of the move.

I’m still playing around with the idea because like I said there are some caveats to using autocorrelation, but these examples emphasize my point that it is a good market timing tool. You can also use autocorrelation to play mean reversion, but it involves a lot of noise and false signals.

You can get the TradingView indicator here. I’ll keep developing it and making updates as I get new insights.

Reply

or to participate.