The end-of-month effect
Forums › ProRealTime English forum › General trading discussions › The end-of-month effect
- This topic has 2 replies, 2 voices, and was last updated 1 month ago by dubbzie.
Viewing 3 posts - 1 through 3 (of 3 total)
-
-
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 #239307 -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)