Trading System: How to Code “Sell In May And Go Away”

Line1

Beginners Course  |  Intermediate Course  |  Amibroker Course

The saying “Sell in May and Go Away” is one of the most popular investment sayings of the last few years.  But how do we really know if it is true?

There is only one real way to tell, and that is to test a trading system automatically, that sells in May each year and buys in November after the so called “danger period” is over.

In this video we look at how to code a Sell In May trading system, and also see the results from the last 13 years on the S&P 500.  The results may surprise you!

We also look at what adding a 200 day Moving Average to our criteria would do for our results, as this is the most common indicator that talking heads on TV use to gauge a market.  Again, the results may surprise you.

Check it out!

How We Enter Our Code:

  • From the main screen in Amibroker, open the formula Editor by going to Analysis > Formula Editor.
  • Type in the following code:

Buy = Month() == 11;

Sell = Month() == 5;

What This Code Means

What we are asking Amibroker to do, is to buy when the month is equal to 11 (November), and Sell when the month is equal to 5 (May).

Adding a Moving Average is simple, the code is:

Buy = Month() == 11 AND C >= MovingAv = MA(C, 200);

This makes Amibroker buy when the month is 11 and the price is over the 200 day moving average.

The Results:

The results of Sell In May and go away when automatically tested on the S&P 500 :

  • Sell In May, Buy in November: 6.89% per annum
  • Adding the 200 day Moving Average: 6.62% per annum
  • Buy and Hold system: 6.81% per annum

Using this automatic testing, we can see that the results are not greatly improved simply by selling in May and going away, and in fact when we add the famous 200 day Moving Average to the mix our annual return goes down, even though our equity curve is smoother.

These are the great benefits of automatic testing!  Fast, free and easy.

I hope this helps, happy trending and enjoy.

– Dave McLachlan

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Videos in the FREE Amibroker Course:

  1. Amibroker: How To Import A Watchlist With A CSV File
  2. Amibroker: How To Backtest A Single Stock Or Index
  3. Amibroker: How To Backtest a Portfolio or Group of Stocks
  4. Amibroker: How To Optimize A Trading System
  5. Amibroker: How To Scan The Market For Buy And Sell Signals
  6. Amibroker: How To Use Explore To Find And Filter Stocks
  7. Amibroker: How To Add Position Sizing Using AFL
  8. Amibroker: How to Add An Index Filter To Your Trading System Using AFL
  9. Amibroker: How To Plot Your Trading System On A Chart (incl. Buy/Sell Arrows)
  10. Amibroker: How to Use the If, Then Else Function (IIF)
  11. Amibroker: How to Code the ATR Trailing Stop (Chandelier) using ApplyStop
  12. Amibroker: How to Plot ApplyStop on a Chart
  13. Amibroker: How to Code Van Tharp Position Sizing (Fixed Fractional)
  14. Amibroker: How to “Scale In” to Positions (1) – Buying Once a Month
  15. Amibroker: How to “Scale In” to Positions (2) – Pyramiding Three Times
  16. Amibroker: How to Use “Cross”, When One Thing Crosses Another
  17. Amibroker Advanced: How to Compare Equity Curves

FREE Trading System Video Lessons:

  1. 7 Free Trading Systems and Their Returns From The Last 13 Years
  2. Seven Full Trading Systems Revisited, With Completely New Data
  3. Trading System: How to Create A Buy and Hold Trading System
  4. Trading System: How to Code “Sell In May And Go Away”
  5. Trading System: How to Code a Moving Average Channel That Made 23% p.a
  6. Trading System: How to Code Highest Highs As Used In 52 Week Highs Or Turtle Trading System
  7. Trading System: How to Code a Bollinger Band Breakout Trading System
  8. Trading System: How to Code a Moving Average Crossover That Returned 28% per annum
  9. Trading System: How to Refer to Previous Signals For MAup Trading System
  10. Trading System: How to Code the Leap Of Faith (Gaps) Trading System That Returned 24% p.a.
  11. Trading System: How to Code a Short Selling System (Plus Results)
  12. Trading System: Meb Faber Trading System Using Different Timeframes
  13. Trading System: How to Code the Three Billion Dollar Trading System

FREE Amibroker Q & A Videos:

  1. Amibroker Q & A: How To Do A Monte Carlo Test? (on ALL versions)
  2. Amibroker Q & A: Visualising Monte Carlo Data with Histograms and Scatter Plots
  3. Amibroker Q & A: How to Create the 52 Week High/Low Index with AddToComposite
  4. Amibroker Q & A: How to Code Trend Pilot: Five Consecutive Days Above or Below a Moving Average
  5. Amibroker Q & A: Three “Hacks” To Improve Your Coding Skills
  6. Amibroker Q & A: How to Remove Excess Signals

Read Related Articles:




  And, subscribe for free to stay in touch and receive the latest updates:

Enter Your Email Address:

.
(Check Your Junk Mail, Just In Case)

June 16, 2013  Tags: , , , , , , ,   Posted in: Amibroker, Amibroker Trading System, Trading System

Leave a Reply