# The System

This system has been around for several years.  Its based on the belief that fund managers start pouring money into the market near the end of the month and this creates momentum that lasts for just a few days.  The original system states to enter the market on the close of the last bar of the day if the its above a certain moving average value.  In the Jaekle and Tomasini book, the authors describe such a trading system.  Its quite simple, enter on the close of the month if its greater than X-Day moving average and exit either 4 days later or if during the trade the closing price drops below the X-Day moving average.

## EasyLanguage or Multi-Charts Version

Determining the end of the month should be quite easy -right?  Well if you want to use EasyLanguage on TradeStation and I think on Multi-Charts you can’t sneak a peek at the next bar’s open to determine if the current bar is the last bar of the month.  You can try, but you will receive an error message that you can’t mix this bar on close with next bar.  In other words you can’t take action on today’s close if tomorrow’s bar is the first day of the month.  This is designed, I think, to prevent from future leak or cheating.  In TradeStation the shift from backtesting to trading is designed to be a no brainer, but this does provide some obstacles when you only want to do a backtest.

### LDOM function – last day of month for past 15 years or so

So I had to create a LastDayOfMonth function.  At first I thought if the day of the month is the 31st then it is definitely the last bar of the month.  And this is the case no matter what.  And if its the 30th then its the last day of the month too if the month is April, June, Sept, and November.  But what happens if the last day of the month falls on a weekend.  Then if its the 28th and its a Friday and the month is blah, blah, blah.  What about February?  To save time here is the code:

``Inputs: movAvgPeriods(50);vars: endOfMonth(false),theDayOfWeek(0),theMonth(0),theDayOfMonth(0),isLeapYear(False);endOfMonth = false;theDayOfWeek = dayOfWeek(date);theMonth = month(date);theDayOfMonth = dayOfMonth(date);isLeapYear = mod(year(d),4) = 0;// 29th of the month and a Fridayif theDayOfMonth = 29 and theDayOfWeek = 5 then 	endOfMonth = True;// 30th of the month and a Fridayif theDayOfMonth = 30 and theDayOfWeek = 5 then 	endOfMonth = True;// 31st of the month 	if theDayOfMonth = 31 then 	endOfMonth = True;// 30th of the month and April, June, Sept, or Novif theDayOfMonth = 30 and (theMonth=4 or theMonth=6 or theMonth=9 or theMonth=11) then 	endOfMonth = True;// 28th of the month and February and not leap yearif theDayOfMonth = 28 and theMonth = 2 and not(isLeapYear)  then 	endOfMonth = True;// 29th of the month and February and a leap year or 28th, 27th and a Friday	if theMonth = 2 and isLeapYear thenBegin	If theDayOfMonth = 29 or ((theDayOfMonth = 28 or theDayOfMonth = 27) and theDayOfWeek = 5) then 	endOfMonth = True;	end;// 28th of the month and Friday and April, June, Sept, or Novif theDayOfMonth = 28 and (theMonth = 4 or theMonth = 6 or 	theMonth = 9 or theMonth =11) and theDayOfWeek = 5 then	endOfMonth = True;// 27th, 28th of Feb and Friday	if theMonth = 2 and theDayOfWeek = 5 and theDayOfMonth = 27 then	endOfMonth = True;// 26th of Feb and Friday and not LeapYearif theMonth = 2 and theDayOfWeek = 5 and theDayOfMonth = 26 and not(isLeapYear) then	endOfMonth = True;	// Memorial day adjustmentIf theMonth = 5 and theDayOfWeek = 5 and theDayOfMonth = 28 then	endOfMonth = True;//Easter 2013 adjustmentIf theMonth = 3 and year(d) = 113 and theDayOfMonth = 28 then	endOfMonth = True;//Easter 2018 adjustmentIf theMonth = 3 and year(d) = 118 and theDayOfMonth = 29 then	endOfMonth = True;	if endOfMonth and c > average(c,movAvgPeriods) then		Buy("BuyDay") this bar on close;If C <average(c,movAvgPeriods) then 	Sell("MovAvgExit") this bar on close;If BarsSinceEntry=4 then 	Sell("4days") this bar on close;``
Last Day Of Month Function and Strategy

All the code is generic except for the hard code for days that are a consequence of Good Friday.

All this code because I couldn’t sneak a peek at the date of tomorrow.  Here are the results of trading the ES futures sans execution costs for the past 15 years.

What if it did the easy way and executed the open of the first bar of the month.

``If c > average(c,50) and month(d) <> month(d of tomorrow) then 	buy next bar at open;If  barsSinceEntry >=3 then 	sell next bar at open;If marketPosition = 1 and c < average(c,50) then 	sell next bar at open;``

The results aren’t as good but it sure was easier to program.