Sell In May And Go Away (Amibroker And Tradestation Code)

The strategy in plain English:

The period from October until the end of April has almost made all the gains in the S&P 500 for 50 years.

Strategy 1:

  • We go long at the open on the first trading day of May
  • We sell at the open on the first trading day of October

Strategy 2:

  • We go long at the open on the first trading day of October
  • We sell at the open on the first trading day of May

Click here for the original article.

Amibroker code:

This code buys on the open in May and sells on the open in October:

Buy= Month()==5;

buyPrice= Open;

Sell= Month()==10;

sellPrice= Open ;

This code buys on the open in October and sells on the open in May:

Buy= Month()==10;

buyPrice= Open;

Sell= Month()==5;

sellPrice= Open ;

Tradestation code:

{
Sell in May and go away reversed (Strategy 27A)
We go long at the open on the first trading day of May
We sell at the open on the first trading day of October
}

if Month(Date next bar) = 5 then 
	buy next bar open;
	
if Month(Date next bar) = 10 then 
	sell next bar open;
{
Sell in May and go away reversed (Strategy 27B)
We go long at the open on the first trading day of October
We sell at the open on the first trading day of May
}

if Month(Date next bar) = 10 then 
	buy next bar open;
	
if Month(Date next bar) = 5 then 
	sell next bar open;

Disclosure: We are not financial advisors. Please do your own due diligence and investment research or consult a financial professional. All articles are our opinions – they are not suggestions to buy or sell any securities.