• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Decoding Markets

  • Top Posts
  • Courses
  • Resources
    • Books
  • Free Class
  • Blog
You are here: Home / Strategies/ Systems / Double Top Pattern – Backtest Rules & Results

February 13, 2019 By Joe Marwood 7 Comments

Double Top Pattern – Backtest Rules & Results

The double top pattern is a chart formation consisting of two consecutive price peaks that leads to a bearish reversal.

For years, traders have claimed that the double top is a high probability short setup.

This is because a double top pattern signifies that bulls are having trouble pushing the price past the prior high.

However, there has been little statistical research done to prove whether or not this pattern has any predictive ability.

In this article, we come up with a definition for the double top, code it up and test the pattern on some historical data.

1. Define The Double Top Pattern

Before we go any further it’s important to think about what a double top actually is and how we can write it into code.

This always presents a problem with chart patterns because they only become clear after the pattern is completed.

For example, a double top pattern only looks like a double top after the stock hits a high then drops through the accompanying support area.

If the stock doesn’t drop fully, then it will look more like a wedge or a triangle pattern.

If the high doesn’t hold long enough then the double top pattern very quickly looks nothing like a double top at all and instead morphs into a typical breakout.

Because of this, it’s essential to come up with a mathematical formula to represent a double top.

This won’t be perfect but it will be our best bet if we want to analyse the effectiveness of the pattern.

Two Peaks And A Neckline

Most descriptions of a double top include two price peaks and a supporting neck line.

It is this neckline that must be broken for the double top pattern to be completed.

A typical double top can therefore be broken down as follows:

Typical double top short trading pattern.
Typical double top pattern requires a close below the neckline to enforce a valid short entry.

However, coding this pattern is more tricky than it sounds because we need to be specific about certain criteria such as:

  • How to define the first peak (A)?
  • How much should the high at peak A differ from the high at peak C?
  • What should the distance be between the neckline and the highest peak?
  • How many bars should there be between peak A and peak C?
  • What is the maximum number of bars that the pattern should complete within?

The Solution

Our solution to this problem is to code up the pattern according to the points above and also make them adjustable parameters.

We can then run an optimization to see which settings work best in the context of a double top pattern.

Importantly, the settings should be set so as to not lose the essence of what a double top represents.

We therefore decided that a double top pattern occurs when all the following conditions are true:

  • The first peak A must be the highest High price in [126,252] trading days
  • The High prices at Peaks A and C must differ by less than 1%
  • The lowest High price between the peaks (i.e. the bottom of the trough) must not be more than [20,30,40,50,60] % below the highest peak
  • Consecutive peaks must be at least [10,20,30,40,50] bars apart
  • The whole pattern must occur within [63,126,189,252] trading days to be valid
  • The pattern completes after the second peak occurs and the High price falls below the lowest High between the peaks (B).
Double top trading pattern with adjustable parameters
This example of a double top pattern has the settings 20% from peak to trough, 30 days between peaks and 252 days for the whole pattern to complete.

Here is a snippet of the Amibroker code we came up with:

Now we can see a real example of the kind of trade setup we can identify with this double top code in NRG:

Double top trade example in NRG. Pink Asterisks show the two tops, which are within 1% of each other. Gold triangle shows the bar on which the Double Top pattern was completed. Red Arrow is the Short entry on the open and green arrow is the exit on close.

2. Set Up The Backtest

Now we have some code written for our double top pattern we can run some optimizations and see how the pattern performs on historical data.

But first we must define a backtest procedure and think about a baseline that we can use to compare our results.

For this analysis we decided to test the performance of double top patterns on all S&P 500 stocks across holding periods from one to ten days.

We also decided to use an in-sample period and out-of-sample period.

This enables us to run an optimization during the in-sample segment and then test it on the cleaner out-of-sample data.

For a benchmark, we decided to compare our results to the average return for every stock in the sample with a corresponding holding period.

For example, if the average 5-day return for all stocks in the sample is 0.5% but our pattern produces an average return per trade of 2%, there’s a good chance that we have found a profitable trading signal.

The procedure for this is to each day select all stocks that are members of the S&P 500 and calculate the closing price N-days in advance and calculate the average return over that holding period for all symbols.

Using data from Norgate we did these calculations for every stock in the S&P 500 (including delisted stocks) from 1/2000 – 1/2018.

This is summarised below:

Summary Baseline Returns For S&P 500 Stocks:

  • 1 Day: 0.016%
  • 3 Days: 0.101%
  • 5 Days: 0.184%
  • 10 Days: 0.386%

You can see that the average daily return for all stocks is 0.016% (open to close) while the average return is 0.386% over 10 days. There is a slight upward bias to the results which is expected.

Note: You can also flip these results in order to see the average returns from going short instead of long. So, the average short return over 10-days is -0.386%.

Our full backtest settings can now be summarised as below:

  • Test universe: All S&P 500 stocks including historical members
  • In-sample test period: 1/2000 – 1/2012
  • Out-of-sample test period: 1/2012 – 1/2018
  • Commissions: 0
  • Liquidity filter: Close > $2 and 21-day turnover > $250,000
  • Holding periods: 1-day, 3-day, 5-day, 10-day
  • Execution: Enter short position on the next day open after the pattern completes. Exit position on the close of the corresponding day
  • Baseline: Average return for all stocks in the sample by holding period

3. Results

In the next table you’ll be able to see the results of our optimization during the in-sample period.

We are optimizing four strategy parameters here and looking for the best combination during the sample period between 1/2000 – 1/2012.

We have also filtered out any results that have less than 150 trades because we want to have a decent enough sample size.

Top 19 optimization results for our double top code. You can see our best performing double top pattern #321 produced an average profit of 0.39% per trade and a win rate of 50% over a sample of 170 trades. This was with a 3-day holding period.

You can see from the above that some variations of our double top pattern have a slight edge with an average profit per trade of up to 0.39%. You can also see that some variations have win rates as high as 56%.

Any variations with more than 150 trades and an average profit per trade >= 0.20% are highlighted green.

The best performing variation #321 produced an average profit per trade of 0.39% with a 50% win rate. This double top pattern had the following settings:

  • Max 1% difference between peak 1 and peak 2
  • Peak 1 is highest in 126 days
  • 20% max peak to trough
  • 20% min peak to peak bars
  • 189 bars max length
  • 3-day holding period

Compare To Out-Of-Sample

We have seen some small profits during the in-sample optimization, the next question is do these same variations hold up in the out-of-sample test period?

In the next table in-sample data for Avg % P/L has been added and the OOS results are sorted based on the highest IS Avg % P/L.

You can see that of the 19 variations with the highest in-sample average profit per trade (highlighted green) only two achieved an average profit per trade over 0.20% in the OOS test (highlighted yellow):

Our top 19 double top variations did not fare very well in out-of-sample. Only two variations produced average per trade profits > 0.20% in the OOS (highlighted yellow).

For example, variation #321 produced an average profit of 0.39% profit in-sample and a profit of 0.23% out-of-sample with a 3-day holding period.

This compares to an average 3-day short return of -0.101% for all stocks in the sample. We get this from our baseline result, implying there’s a small element of profit but not much.

4. Conclusions

Overall, with a fairly low average gain per trade (even before commissions) and also a small number of trades (10-30 per year), other significant improvements would be required to turn this into a profitable trading strategy.

There may be some benefit to a double top pattern as a hedge to a long strategy but profits of only 0.2% are unlikely going to cut it when we introduce commissions and slippage.

Also, it appears hard to predict which parameters will be successful in the future. There’s not enough profit and not enough stability in the results to be confident in this pattern.

One positive conclusion we can make is that short trades seem to work better over short holding periods – 3 days or 1 day. This information might be useful for a future experiment.

5. Intraday Test

Before we wrap up, I also wanted to run some analysis on intraday markets to see if double top patterns are more profitable on higher frequency data.

For this, I tested 15-minute time-frames for five major ETFs; SPY, QQQ, GLD, USO and TLT.

For these tests, we had to make a few changes to get reliable results and find entries that still look like double tops.

The code for the second peak was altered so that it must occur within 0.1% of the first peak.

The other difference was that any short trade must be placed before 2pm and all trades are exited on the close at 4pm.

This is because we want to keep this test strictly to an intraday timeframe.

The tables below show our top 10 optimization results for different ETFs:

SPY 15-minute:

Our best profit per trade was only 0.06% trading the 15-minute chart for SPY.
Our best average profit per trade was only 0.06% trading the 15-minute chart for SPY.

QQQ 15-minute:

Our best profit per trade was 0.18% trading the 15-minute chart for QQQ.

Our best avg profit per trade was 0.18% trading the 15-minute chart for QQQ.

GLD 15-minute:

We did not find any profitable variation trading the 15-minute chart for GLD.

We did not find any profitable variation trading the 15-minute chart for GLD.

USO 15-minute:

Our best profit per trade was .81% trading the 15-minute chart for USO however this was a very small sample size of only 3 trades.

Our best avg profit per trade was .81% trading the 15-minute chart for USO however this was a very small sample size of only 3 trades.

TLT 15 minute:

Our best profit per trade was .55% trading the 15-minute chart for TLT however this was also a small sample size.

Our best avg profit per trade was .55% trading the 15-minute chart for TLT however this was also a small sample size.

Intraday Conclusions

Unfortunately the answers are again disappointing for this analysis (with the exception of USO).

For example, you can see that for SPY the best performing pattern produced an average profit of only 0.06% per trade while we found no profitable setup for GLD at all.

This is quite unusual for an optimization and we were struggling to find enough trading opportunities for this symbol.

Meanwhile, USO produced profits up to 0.81% per trade but the sample sizes were also small so more investigation would be needed.

6. Final Thoughts

We often hear traders talking about winning chart patterns like double tops and head and shoulders but time and again we test these patterns and find very little evidence of profitability.

There can only be 3 reasons for this dissonance:

  1. Some traders are making money from these patterns but they’re profits are actually due to luck and not chart reading.
  2. Some traders are making money from these patterns but they are incorporating other tricks and secret sauce that helps them to win.
  3. Traders are deluding themselves and actually not making money from these patterns at all.

All three reasons are perfectly believable and I have witnessed them numerous times through my years of trading.

The difficulty with markets is that it is all a big numbers game.

You will always have some winners due to the nature of statistics. It doesn’t follow that results are necessarily borne out of skill or a found edge.

Looking at the results of the double top, this is not a pattern you want to be shorting on its own. The results simply aren’t good enough.

Simulations in this article produced in Amibroker with data from Norgate. Intraday data from Esignal. Also thanks to Matt Radtke for his assistance with this article.


Thank You For Reading

joe marwood profile pictureJoe Marwood is an independent trader and the founder of Decoding Markets. He worked as a professional futures trader and has a passion for investing and building mechanical trading strategies. If you are interested in more quantitative trading strategies, investing ideas and tutorials make sure to check out our program Marwood Research.


Disclaimer

This post expresses the opinions of the writer and is for information, entertainment purposes only. Joe Marwood is not a registered financial advisor or certified analyst. The reader agrees to assume all risk resulting from the application of any of the information provided. Past performance is not a reliable indicator of future returns and financial trading is full of risk. Margin trading can lead to losses more than in your account. Mistakes in backtesting and presenting of analysis regularly occur. Please read the Full disclaimer.

Filed Under: Amibroker, Stocks, Strategies/ Systems, Technical Analysis, Top Posts Tagged With: stocks, technical analysis

Recommended Educational Resources:


  • Discover New Trading Strategies
  • Learn Japanese Candlesticks (Free)
  • Mental Models For Trading (Free)
  • Indicators For Amibroker (Free)
  • Tools For Options Traders (Free)
  • Historical Data For 8000 Stocks (Free)

Reader Interactions

Comments

  1. Justin says

    February 14, 2019 at 8:23 pm

    Thanks for the analysis. I agree that traders often do things that have a perceived edge but don’t test their theories thoughtfully in live market conditions. One issue that concerns me be about your results is the entry and exit criteria. Your entries seem to be quite late and your system exits quickly. Adjusting your entry and exit criteria could have a massive impact on returns.

    This type of trading set-up also has a big discretionary component. For example if a trader has seen hundreds or thousands of double tops in their trading career, they may know which ones have a higher priority and which ones to skip. They may have fine tuned their entries and exits to suit each setup based on experience. The difficulty is that the discretion cannot be accurately tested.

    Reply
    • Joe Marwood says

      February 14, 2019 at 9:18 pm

      Sure, totally agree with you there can be a discretionary element, that’s what I tried to mention in the closing statement. Traders might have tricks, secret sauce etc that helps them pick the winning patterns from the losing ones. The only problem here is that, statistically, those winning discretionary traders may just be lucky traders. This is what a lot of other analysis has tried to prove over the years.

      Not sure I agree with you re: my entries and exits. Entries were placed at the earliest point after the pattern completes (not counting pre-market). Plus, 10-day exit is considered quick?

      Reply
  2. Luis MIguel yuste galindo says

    April 15, 2019 at 3:16 am

    Hola, podria publicar la parte del codigo que falta en la ejecucion del doble techo, no soy capaz con ese trozo de hacerle funcionar, precisamente me gustaria hacerlo al contrario que al testear el punto bajo del doble techo de señal para entrar largo con objetivo el punto alto, pero no se programarlo. y con ese trozo de codigo casi esta

    Reply
    • Joe Marwood says

      April 15, 2019 at 2:43 pm

      Sorry but I don’t have the time to debug individual formulas. As far as I know the code is working so not sure what your problem could be. Thanks.

      Reply
  3. Dennis says

    April 21, 2019 at 7:07 pm

    There are a few variables that may greatly change your results. First is support and resistance levels. A double top into heavy resistance will have a much higher chance of success. Second is velocity. A double top that forms after a parabolic move or overextension will have a higher chance of success. Double tops after a slow grind are less likely to reverse significantly, and more likely to end up in a breakout. I think most discretionary intraday traders are looking for these other variables before pulling the trigger. Just food for thought.

    Reply
  4. Alex says

    May 27, 2020 at 8:21 am

    Good article. Is it possible to get full code to run and test? Thanks

    Reply
    • Joe Marwood says

      June 8, 2020 at 10:29 pm

      Code for the pattern is shown inside the article. Thanks.

      Reply

Leave a Reply Cancel reply

Your email address will not be published.

Primary Sidebar

Access Marwood Research image

Popular

How to 10x Your Momentum Trading Strategy

How To 10x Your Momentum Returns

Slide 3 Books

The 100 Best Trading And Investing Books Of All Time

best moving average test on s&p 500

Which Is The Best Moving Average? Test Results Reveal The Truth

Testing The RSI Model From The Quantitative Technical Analysis Book By Howard Bandy

Stock screen image

20 Traps All Traders And Investors Must Avoid

Which Trailing Stop Is The Best?

Investing With Intelligent Machines

vrsn example moving average pullback trade

The 200 Day Moving Average Pullback Doesn’t Work

Search

Recommended Resources

  • Discover New Trading Strategies
  • Learn Japanese Candlesticks (Free)
  • Mental Models For Trading (Free)
  • Indicators For Amibroker (Free)
  • Tools For Options Traders (Free)
  • Hist. Data For 8000 Stocks (Free)

Financial Disclaimer

Financial trading is risky and you can lose money. Joe Marwood is not a registered investment advisor and nothing on this site is to be regarded as personalized investment advice. Past performance is not indicative of future results. Data errors and mistakes do occur. Please see the full disclaimer.

Footer

About The Author

Joe Marwood is an independent trader and investor specialising in financial market analysis and trading systems. He worked as a professional futures trader for a trading firm in London and has a passion for building mechanical trading strategies. He has been in the market since 2008 and working with Amibroker since 2011.

Joe Marwood Profile PIc

Recent Posts

  • Investing With Intelligent Machines
  • Trend Following With ETFs and Large Cap Stocks
  • Should You Trade This Earnings Pullback Strategy?
  • Simple Algo Trading With Alpaca And Streak
  • Is Value Investing Dead? Dissecting The Value Investing Narrative
  • How To Screen For Stocks With Norgate Data
  • Do Stocks Have A Floor?
  • What Trading Signals Work Best For Long-Term Investors?

Search

Privacy policy | Contact | Disclaimer | All Rights reserved. JB Marwood.