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
I 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”):
//bisextil year or not?
If Year Mod 4 = 0 And (Year Mod 100 <> 0 Or Year Mod 400 = 0) Then
IsBisextil = 1
Else
IsBisextil = 0
EndIf
//days quantity per month
if IsBisextil then
feb=29
else
feb=28
endif
//get the last day of the current month
if month=1 or month=3 or month=5 or month=7 or month=10 or month=12 then
lastdayofmonth = call "#get_lastdayofmonth"[year,month,31]
elsif month=4 or month=6 or month=8 or month=9 or month=11 then
lastdayofmonth = call "#get_lastdayofmonth"[year,month,30]
elsif month=2 then
lastdayofmonth = call "#get_lastdayofmonth"[year,month,feb]
endif
return lastdayofmonth
This code above need this other function (saved as an indicator named “#get_lastdayofmonth”).
//what is the day of week?
if myMonth >= 3 then
D = (((23*myMonth)/9) + myDay + 4 + myYear + (myYear/4) - (myYear/100) + (myYear/400) - 2) mod 7
else
z = myYear - 1
D = (((23*myMonth)/9) + myDay + 4 + myYear + (z/4) - (z/100) + (z/400) ) mod 7
endif
lastday=myDay
if D=6 then
lastday=myDay-1
elsif D=0 then
lastday=myDay-2
endif
return lastday
So in your strategy, you’ll have to code something like:
lastdayofmonth = CALL "#lastdayofmonth"
//buy the last day of the month
if day=lastdayofmonth then
buy 1 contract at market
endif
//sell at 3rd day of the next month
if longonmarket and day>=3 then
sell at market
endif
Many thanks Nicolas, that’s helped me get to grips with things!
BelParticipant
New
Hi 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 🙁
BelParticipant
New
Hi 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.