coding help about buy and sell on certain days of the month
Forums › ProRealTime English forum › ProOrder support › coding help about buy and sell on certain days of the month
- This topic has 5 replies, 1 voice, and was last updated 3 years ago by teapot2002.
Tagged: last day
-
-
09/18/2017 at 2:17 PM #46506
Hi there,
I am a new ProRealTime user and just working my way through the programming manual in order to get to grips with the programming language!
It would be ever so helpful if someone could tell me the correct code for the following – it would help with my understanding of how the specific monthly date element of coding works:
Buy on the last 2 trading days of the month and sell at the close on the 3rd trading day of the month
If someone would be kind enough to tell me the code for the above lines, it would help me as I work through the ProRealTime coding manual.
Many thanks for your help!
Rob
09/18/2017 at 4:30 PM #46525I wrote functions to know if we are on the last day of month for someone else, here are the codes:
This indicator will tell you the number of the last traded day of the current month (save it as an indicator named “#lastdayofmonth”):
RETURN the last trading day of the month123456789101112131415161718192021222324//bisextil year or not?If Year Mod 4 = 0 And (Year Mod 100 <> 0 Or Year Mod 400 = 0) ThenIsBisextil = 1ElseIsBisextil = 0EndIf//days quantity per monthif IsBisextil thenfeb=29elsefeb=28endif//get the last day of the current monthif month=1 or month=3 or month=5 or month=7 or month=10 or month=12 thenlastdayofmonth = call "#get_lastdayofmonth"[year,month,31]elsif month=4 or month=6 or month=8 or month=9 or month=11 thenlastdayofmonth = call "#get_lastdayofmonth"[year,month,30]elsif month=2 thenlastdayofmonth = call "#get_lastdayofmonth"[year,month,feb]endifreturn lastdayofmonthThis code above need this other function (saved as an indicator named “#get_lastdayofmonth”).
#get_lastdayofmonth12345678910111213141516//what is the day of week?if myMonth >= 3 thenD = (((23*myMonth)/9) + myDay + 4 + myYear + (myYear/4) - (myYear/100) + (myYear/400) - 2) mod 7elsez = myYear - 1D = (((23*myMonth)/9) + myDay + 4 + myYear + (z/4) - (z/100) + (z/400) ) mod 7endiflastday=myDayif D=6 thenlastday=myDay-1elsif D=0 thenlastday=myDay-2endifreturn lastdaySo in your strategy, you’ll have to code something like:
1234567891011lastdayofmonth = CALL "#lastdayofmonth"//buy the last day of the monthif day=lastdayofmonth thenbuy 1 contract at marketendif//sell at 3rd day of the next monthif longonmarket and day>=3 thensell at marketendif09/20/2017 at 5:12 PM #4672511/08/2019 at 2:07 PM #11241511/08/2019 at 2:26 PM #112419Hi Nicholas.
I’m interested in buying or selling at start or end of the month but have no idea how to code it right except manually enter dates. Any help possible?
P.s. tried this code but can’t get to work 🙁
I think I worked it out right after posting. All good. Lets see how it rolls.
03/17/2021 at 5:35 PM #164512If, like me, you’d forgotten how to pass parameters to indicators, this is very helpful: https://www.prorealcode.com/blog/video-tutorials/adding-dynamic-parameters-to-your-indicators-prorealtime/
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on