The Holiday Effect: Independence Day (Amibroker And Tradestation Code)

The strategy in plain English:

  1. We buy the S&P 500 at the close of the second last trading day of June. For example, we buy at the close on the 29th of June so we are long on the open of the last trading day of June.
  2. We sell six days after we bought. The effect seems to last a few days after the holidays, thus we keep the position a bit longer.

Click here for the original article.

Amibroker code:

Buy= Ref(Month(),1)!=Ref(Month(),2) AND Month()==6 ;

buyPrice=Close;

Sell= BarsSince(Ref(Month(),1)!=Ref(Month(),2))==6;

sellPrice=Close ;

//buy at the close before 4th of July, sell at the close the first trateding day after

setOption("holdminbars",1);
SetTradeDelays( 0, 0, 0, 0 );

condition = Ref(Day(),1)>4 AND Month()== 7; 

Buy= condition AND BarsSince(Ref(condition,-1))>50 ; //the barssince is to avoid multiple trades in July after 4th of July
buyPrice=Close;
Sell= Day()>4;
sellPrice=Close ;
//Buy the close on the second last day before Independence day and sell at the the day before

setOption("holdminbars",1);
SetTradeDelays( 0, 0, 0, 0 );

condition = Ref(Day(),2)>4 AND Month()== 7;

Buy= condition AND BarsSince(Ref(condition,-1))>70 ;
buyPrice=Close;
Sell= 0;
sellPrice=Close ;

Tradestation code:

{
The Holiday Effect: Independence day (strategy 14)
https://www.quantifiedstrategies.com/trading-the-holiday-effect-anomaly-in-stock-markets/
We buy the S&P 500 at the close of the second last trading day of June. 
For example, we buy at the close on the 29th of June so we are long on the open of the last trading day of June.
We sell six days after we bought. The effect seems to last a few days after the holidays, thus we keep the position a bit longer.
}

if (TdaysTillMonthEnd=1) and (Month(Date)=6) Then
	Buy this bar on close;
	
if (Marketposition=1) and (Barssinceentry>=6) Then
	Sell this bar on close;

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.