It’s no surprise that general market sentiment is important if you’re a trader/investor, and in 2022 conditions have been particularly difficult to profit from. However, it has indeed been a great year for honing a business edge.

One of the ways I’ve refined my edge is by evaluating how a stock performs relative to the broader market. In other words, if a trade takes place, can we understand if the security is stronger than the broader market and therefore likely to make good gains when the selling pressure subsides.

Take STNG for example, there may only have been a “momentum break” in the stock when the market was down (vs. the Nasdaq-100 Index ETF, QQQ) . Clearly, the stock showed that the market couldn’t bring it down.

A stock price comparison of STNG against the Nasdaq-100 ETF, QQQ. The bottom chart shows the “relative strength” indicator that I use to show a stock’s performance against the market.

The bottom graph shows the result of a simple calculation I do custom relative strength, i.e. the performance of this security relative to the market. I like to think of it showing investor interest in a stock versus general market sentiment.

In this article I will describe:

  • How to calculate simple relative strength indicator.
  • How this indicator works as a trading strategy.
  • How you could benefit from using the indicator.

There’s also some Python code you can steal at the end 🙂

Before continuing, I want to clarify that this indicator is not the well-known RSI (Relative Strength Index) which is derived from a single instrument, this indicator compares two different instruments.

The calculation is actually very simple and can be applied to any timeframe (although I use the daily timeframe). It is carried out in this 3-step process:

  1. Take the last n measurements of the stock and the comparison stock price. I use closing prices.
  2. Scale both time series by the value of this instrument at the furthest point in time (so both time series start with value = 1).
  3. Perform numpy.mean(stock_scaled-index_scaled) to get the relative strength for this trading session.

And that’s all! Here’s a GIF showing this in action for the example given above:

A calculation of relative strength for each trading day throughout this year. I used an analysis period of 20 days for this calculation.

Wait, why are you scaling the furthest day in time?

We have to evolve because the prices of the instruments are extremely different and therefore difficult to compare. Scaling using this approach allows you to see instrument performance from that point.

For example, if the stock has been up for n days and the market is down, it is very clear to see a divergence in the two time series.

You can of course experiment with other scaling methods, maybe another works better, if so, share it in the comments!

Why didn’t you use something like a euclidean distance?

The Euclidean distance will give a positive number. What interests me is how good/bad a stock is relative to general market sentiment. This method allows for negative numbers that indicate the market is showing more strength than the stock (which could be a potential sign of weakness).

It’s a lagging indicator, isn’t it?

Yes, anything that derives from price action will!

So… what analysis period should I use?

Honestly, it takes some experimentation and you have to find what suits you. However, I like to use two relative strength calculations over the following timeframes:

  • Short-term behavior = last 20 days (~1 month of trading activity)
  • Long-term behavior = last 60 days (~3 months of trading activity)

I think that gives a better overall picture than just using a single look-back period.

Are there other time series comparison methods we can use?

I considered using dynamic time warping to give a measure of distance, however, this will give a positive number like Euclidean distance.

This algorithm works best as a scanner, which I explained here:

Before talking about the backtest, let me repeat that this is a lagging indicator and is likely to produce false/late signals. However, I was still curious if this indicator would work when incorporated into a trading strategy 🙂

The strategy is based on the following rules:

  1. If the short and long-term relative strength indicators are above zero, so buy the instrument at the next open.
  2. If the short-term relative strength goes below zero, then sell at the next open.

The basic premise is that the long-term trend shows strong investor confidence, and the peak of the short-term trend shows that there may be some good temporary money flow we can jump on; that is to say, buy dear, sell dearer.

I ran this backtest on all small, mid and large cap stocks in the nasdaq stock screener from January 2022 to October 2022, collecting the following three statistics each time:

  • The average win/loss percentage per trade.
  • The average length of detention (in days).
  • The multiples of your initial investment, if you applied the strategy only to this stock.

The histograms below show the results of each backtest:

The results of the backtest of the simple strategy using the relative strength indicators.

Obviously, this strategy sucks. Maybe it can be improved with hyperparameter optimization, similar to what I did using genetic algorithms:

However, I imagine that even after optimization it will be a sub-par strategy. I think this indicator is best used to get an idea of ​​the big picture, and used in combination with another indicator and/or trading concept (see next section!).

Personally, I think this technical indicator is best used to provide belief in a technical pattern. As a concrete example, when I search for a flag breakout pattern, the relative strength allows me to assess whether this particular security is stronger than general market conditions.

Here are two examples of powerful flag-shaped breakouts that have occurred this year, both of which have shown relative strength against the market:

An example of two breakout stocks showing relative strength against the broader market. The highlighted region shows the period of consolidation before the breakout and where the relative strength is most interesting.

The short-term and long-term relative strength indicates that the stock is performing well against the broader market and, therefore, a decent candidate to consider.

There are only two examples, hardly a good sample!

Don’t worry, I know! This is just to illustrate 🙂

As said before, I use it as a measure of conviction, no precision. I see a technical pattern I like, check the relative strength, then consider one or two other factors before buying (all part of my trading flow).

No indicator/method is perfect and you should never believe 100% anything on the internet without testing it yourself.

Wow, those trendlines are awesome, how did you draw them?

Ah, thanks for noticing that! You can read all about it in this article I wrote:

In this short article, I showed how I use a super basic calculation to measure a stock’s performance against general market sentiment. I think this indicator is best used in conjunction with other trading concepts and helps illuminate the bigger picture.

There is of course a lot of room for improvement, perhaps the look-back periods are not optimal, or perhaps there is a better scaling/evaluation approach. It would be great to hear if anyone expands on my work!