The end-of-month effect
Forums › ProRealTime English forum › General trading discussions › The end-of-month effect
- This topic has 3 replies, 3 voices, and was last updated 1 month ago by
justisan.
-
-
10/20/2024 at 7:36 PM #239276
Hi all,
I want to go long at the close on the fifth last trading day of the month, and exit at the close of the third trading day of the next month. Anyone able to make script for this strategy?
1 user thanked author for this post.
10/21/2024 at 4:11 PM #239296Hi! here you have a code. It must be backtested in daily timeframe.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657myday=opendaymyDayOfWeek = opendayofweekMyMonth=openmonthMyYear=openyearbusinessdaysleft = 0//------------------------------------------////-----Check leap year----------------------////------------------------------------------////input:YEARLeapYear = 0If MyYear mod 4 = 0 thenIf MyYear mod 100 = 0 thenIf MyYear mod 400 = 0 thenLeapYear = 1EndifElseLeapYear = 1EndifEndif//------------------------------------------////-----Calculate max days in month----------////------------------------------------------//MaxDay = 31If MyMonth = 4 or MyMonth = 6 or MyMonth = 9 or MyMonth = 11 ThenMaxDay = 30EndifIf MyMonth = 2 thenx = LeapYearMaxDay = 28 + xEndifmyDayMax=MaxDayFOR count = myday to myDayMax DOIF myDayOfWeek >= 1 and myDayOfWeek <= 5 THENbusinessdaysleft = businessdaysleft + 1ENDIFmyDayOfWeek = (myDayOfWeek + 1) MOD 7NEXT//------------------------------------------////-----Open long position-------------------////------------------------------------------//dayscheck=5if not longonmarket and businessdaysleft=(dayscheck+1) thenbuy 1 contract at marketendif//------------------------------------------////-----Close long position------------------////------------------------------------------//newmonth=openmonth<>openmonth[1]if onmarket thenn=n+1if n>=3+dayscheck thensell at marketendifelsen=0endif4 users thanked author for this post.
10/21/2024 at 7:38 PM #23930705/23/2025 at 2:13 PM #247562Hi,
finally I came to test this day counting algo, and realized that it works perfectly for months which do not contain any exchange holidays, and so it does not count correctly for the months with exchange holidays. for this moment I assume there is no real posibility to consider in the algo correctly those months with exchange holidays: for that we would need to have “in the background” all exchange holidays of the past (for the backtesting) and for the future (for live implementation), for specific exchange, right? I assume still one could do it manually: collect past exchange holidays manually (or let collect them by AI if one trusts AI :-D) and put them in the code…
so I will probably collect exchange holidays for my exchange of interest, but anyway – I still don’t have an idea, how to consider them in the code, so counting runs correctly. do you have and idea, Ivan? or anybody else? I mean, if let’s say 1st of May is exchange holiday and this day in the year xyzw is not on weekend, how could I possibly tell it in the code, so counting is adjusted?
thanks,
justisan
-
AuthorPosts