Home Trading indicators Divergence Trading Strategy — What Is It? (Rules And Backtest)

Divergence Trading Strategy — What Is It? (Rules And Backtest)

Divergence Trading Strategy
Divergence Trading Strategy

Divergence is a very common signal used by traders to find opportunities in various financial markets, and there are many indicators you can use to identify it. But what is the divergence strategy?

In trading, divergence means that the price swings and the indicator movement are not in phase. A divergence signal is generated when the price is making a higher swing high but the indicator is making a lower high, or the price is making a lower swing low when the indicator is making a higher swing low, thus indicating a potential divergence trading strategy. This implies that the price swing is losing momentum and is likely to reverse soon.

In this post, we take a look at the divergence trading strategy and the indicators for trading it. We backtest a divergence strategy.

But first, let’s start with some theory and examples:

What is divergence in trading?

In trading, divergence means that the price swings and the indicator (oscillator) movement are not in phase. A divergence signal is formed if the price is making a higher swing high when the oscillator is making a lower high, or if the price is making a lower swing low when the indicator is making a higher swing low. There are other configurations that also indicate a divergence.

Usually, as the price swings up and down, the indicator should follow suit at the same speed, such that if the price is making a new high or a new low, the indicator should be doing the same as well. When that doesn’t happen, the price’s swing high or low and the oscillator’s high or low would be out of phase, and we have a divergence.

In other words, divergence occurs when the price is making a higher high, while the oscillator is making a lower high, or the price is making a lower high, while your oscillator is making a higher high. On the low side, the price may be making a lower low, while your indicator is making a higher low, or the price is making a higher low, while your indicator is making a lower low.

The key thing in divergence is the configuration of the swing highs and lows of both the price and the indicator you are using. Divergence works with momentum indicators. So, whenever the price swings and the indicator swings don’t correlate, the price is losing momentum, and some form of reversal may be about to happen, even if it’s just a temporary retracement.

Types of divergence

From what we have stated so far, you would notice that there are four different situations that can generate divergence. However, based on the price swings and the market structure, divergence is broadly classified into two categories: classical and hidden.

Classical divergence

Also known as regular divergence, the classical divergence is formed when the price is making a lower low but the indicator is making a higher low, or when the price makes a higher high but the indicator is making a lower high. This type of divergence forms mostly against the prevailing trend and may indicate the reversal of the trend or an emergence of a temporary pullback. Sometimes, a classical divergence may signal the continuation of the trend after a pullback if it forms in a multiple-legged pullback.

Depending on where it forms, a classical divergence can be a bullish divergence or a bearish divergence:

  • Bullish classical divergence: This signal is generated when the price makes a lower swing low while the indicator is making a higher low. It is associated with downswings and may occur in a downtrend or a multi-legged pullback in an uptrend. As the name suggests, the bullish classical divergence shows that an upward price reversal is likely.
  • Bearish classical divergence: This signal is generated when the price makes a higher swing high while the indicator is making a lower high. It is associated with upswings and may occur in an uptrend or a multi-legged pullback in a downtrend. The bearish classical divergence shows that a downward price reversal is likely.

Hidden divergence

Hidden divergence forms when the price makes a higher low in an uptrend but the indicator makes a lower low, or when the price makes a lower high in a downtrend and the indicator makes a higher high. This kind of divergence is mostly with normal pullbacks in a trend and indicates that a pullback is about to reverse for the trend to continue. However, on some occasions, a hidden divergence may occur at the end of a trend if it forms with the head and shoulder pattern or the inverse head and shoulder pattern.

Depending on where it occurs — swing high or low — the hidden divergence can be bullish or bearish:

  • Bullish hidden divergence: Mostly seen at the end of a pullback in an uptrend, the bullish hidden divergence forms when the price is making a higher swing low and the indicator is making a lower low. It signals a bullish reversal, so the existing uptrend would continue.
  • Bearish hidden divergence: This is mostly after a rally in a down-trending market. It forms when the price is making a lower swing high while the indicator is making a higher high. It signals a potential downward price reversal for the existing downtrend to continue.

Which indicator is best for divergence?

Many momentum oscillators generate divergence signals. The only way to know the best one for the market you want to trade is to back-test them and choose the one that performs best. As you know, we emphasize systematic trading, and what we have found is that whatever indicator you use, the divergence strategy is difficult to quantify.

Nonetheless, there are many indicators you can use for the divergence strategy. Some of them are purely price-based indicators, while some are based on volume data alone or a combination of price and volume data.

Examples of the price-based indicators include:

Examples of volume-based indicators include:

  • On-balance volume
  • Volume RSI
  • Chaikin money flow indicator
  • Accumulation/distribution
  • Volume price trend indicator
  • Negative volume index
  • Force index
  • Money flow index
  • Ease of movement

Choose the ones you prefer and backtest them to know what would work in the market you are trading. RSI may work well for stocks and not work well for commodity futures. In the same way, the stochastic or CCI may work well for commodity trading and perform poorly for stock trading. Only backtesting can sort this out for you, and you might want to have a look at our backtesting course:

Divergence strategy examples

As we have explained above, there are four types of divergence signals, two of which are bullish and the other two bearish. We will show examples of trade setups that were generated by the four types. Below we’ll show some anecdotal charts explaining graphically how you potentially can develop divergence trading strategies. However, you need to backtest yourself before you commit any capital to your trading ideas!

Example 1: Classical bullish divergence signal on the Nasdaq 100 chart (March 2020)

Following the emergence of the Covid-19 pandemic, the equity market crashed over a period of one month or so.

During that crash, a classical bullish divergence — the price made a lower swing low while the RSI made a higher low — was formed on the Nasdaq 100 H4 chart in the last weeks of March 2020. On the 23rd of March, a hammer candlestick formed, which would have triggered those following the divergence to enter their long positions. What followed was a huge upward price gap and a massive rally that ended the pandemic market crash. See the chart below:

Divergence trading strategy (Nasdaq 100)
Divergence trading strategy (Nasdaq 100). Classical bullish divergence signal.

Example 2: Hidden bullish divergence signal on the TSLA chart (March 2020)

The same Covid-pandemic market crash created a hidden bullish divergence on the Tesla stock (TSLA) chart — on the D1 timeframe. The divergence is called hidden bullish because while the TSLA price made a higher swing low, the RSI oscillator made a lower low. That was followed by a tall bullish engulfing candlestick pattern, which would have been a good trade trigger for those watching the divergence.

What followed was the market rally that marked the recovery from the pandemic market crash. See the chart below: Note that the RSI also entered the oversold territory when the divergence occurred.

Divergence trading strategy (Tesla)
Divergence trading strategy (Tesla). Hidden bullish divergence signal.

Example 3: Classical bearish divergence signal on the S&P 500 chart (February 2020)

Just before the Covid-19 pandemic was announced, the S&P 500 index H4 chart was showing a classical bearish divergence signal — the price made a higher swing high, while the RSI made a lower swing high.

Also, a harami candlestick pattern formed on the chart. A trader who was monitoring the divergence could have used the candlestick pattern as a trigger to enter a short position. That would have yielded a nice profit, as the market gaped down and crashed afterward following the news of the Covid pandemic.

Divergence trading strategy (S&P 500)
Divergence trading strategy (S&P 500). Classical bearish divergence signal.

Example 4: Hidden bearish divergence signal on the Nasdaq 100 chart (December 2018)

In early December 2018, the Nasdaq 100 H4 chart formed a bearish hidden divergence — the price made a lower swing high in a downtrend, while the RSI made a higher high. Looking at the chart, you would notice that a harami candlestick pattern occurred afterward, which would have been a good trigger to enter a short position. The market made a reasonable downswing that would have yielded a nice profit.

Divergence trading strategy (Nasdaq 100)
Divergence trading strategy (Nasdaq 100). Hidden bearish divergence signal.

Divergence trading strategy backtest (example)

As you might imagine, making a 100% quantifiable divergence trading strategy with trading rules and settings is not an easy task.

The best strategies can be found in our….

Strategy Shop

Backtested trading strategies

That said, we can make a very simple yet powerful backtest. We backtest the following trading idea on the S&P 500 (using the ETF with the ticker code SPY):

  • The close is setting a new N-day low.
  • The RSI indicator is not setting a new low.
  • We sell at the close based on a mean reversion criterium.

These are pretty easy trading rules to backtest.

We make a strategy optimization and we get the following table (we have previously covered how to optimize a trading strategy):

Divergence trading strategy (optimization)
Divergence trading strategy (optimization)

The first column shows how many days we use in our backtest and settings. The fourth column shows the profit factor. What is a good profit factor? We like to see at least 1.75 and as you can see, from 2 to up to around 20 days the results are pretty good. The next column, showing the Sharpe Ratio, is also pretty impressive (read here about what is a good Sharpe Ratio?)

Let’s look at the equity curve of the divergence trading strategy number 2 (row 2):

Divergence trading strategy (backtest and example)
Divergence trading strategy (backtest and example)

What is a good equity curve? We believe the equity curve above is a pretty good one, but it might be liable to a certain degree of curve fitting (what is curve fitting?) Max drawdowns are very low (what is a good maximum drawdown?) and the only losing year was 2012. However, please notice the relatively few trades over such a long period.

Divergence trading strategy, settings, rules, and code

If you want to have the Amibroker code or the divergence strategy backtest explained in plain English, you need to order the following product:

The product has lots of code and trading ideas and gives you plenty of profitable trading strategies with a few modifications.

Divergence trading strategy – ending remarks

Practically all articles about divergence trading strategies are followed by anecdotal graphs and how to trade them. But does any divergence trading strategy actually work? You have no idea until you actually sit down and backtest with solid trading rules and settings. In this article, we did. Our divergence strategy backtest shows that even simple ideas can get you a long way!

>