probably some of you came accross this strategy „First 5 trading days of the year“ which gives some indication about the direction of the upcoming trading year, at least for the stock market. A simple buy and hold strategy- if those first 5 years are positive- buy on day 6 and hold until end of the year.
As I am still an EL learner I thought to myself lets try to programme this strategy. The first hurdle for myself is to define those first 5 trading days. I cant use the 1st, 2nd or 3rd day of the year as I can only buy at close bar, correct?
So I have to look for the last trading day of a year and buy at the open of the next bar. Issue I had here: Some years do not inherit 31/12, its then 30/12 or even 29/12. As EL counts from left to right in the chart, how can I make sure that if 31/12 exists, the strategy does not use 30/12 or 29/12.
I think I got this to work by:
Code: Select all
var: last.trading.day(true);
if month(date)=12 and DayOfMonth(Date) >= 29 and DayOfweek(Date)=5
then last.trading.day = true;
I used the BarsSinceEntry function to count 5 days from the entry to sell on the close. Actually no buy or sell is needed, moreover a comparison of value from possible entry and exit. If exit(value+5,close)> entry(value,open) then buy the next day open and sell at the end of the year.
I know its not a hard strategy to code. With a little help more users can profit from it.
Code: Select all
inputs: BarToExitOn( 5 ) ;
var: last.trading.day(true);
if month(date)=12 and DayOfMonth(Date) >= 29 and DayOfweek(Date)=5
then last.trading.day = true;
if last.trading.day = true then buy next bar at open;
if BarsSinceEntry = BarToExitOn then Sell this bar close ;
Code: Select all
Value1=Close>Open[5]