Tomorrow's date
Forums › ProRealTime English forum › ProBuilder support › Tomorrow's date
- This topic has 29 replies, 4 voices, and was last updated 5 years ago by dburgh.
Tagged: Business days, date, date math
-
-
03/29/2019 at 3:01 PM #9501103/30/2019 at 3:57 PM #95105
I’m still working on it, to check calculations.
04/01/2019 at 8:11 PM #9525504/01/2019 at 8:27 PM #95256Not yet, I’m trying to write a new algorithm.
In the meantime you can use OpenDayOfWeek (or DayOfweek if you prefer the DoW at the closure of the candlestick), which works finely. Mine was just a replacement.
04/01/2019 at 8:29 PM #9525704/01/2019 at 8:34 PM #95258I’ll post the code as soon as I have a correct version.
04/02/2019 at 3:38 AM #95272This version works fine after Jan. 31st, 2011:
GetDayOfWeek v.2123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566// (Works fine after Jan. 31st, 2011)////input: DATEMyDay, MyMonth, MyYear = CALL "UnpackDate"[OpenDate]//--------------------------------------------------------------------------// A - calculate the YEAR Codeyy = MyYear MOD 100y1 = (yy - (yy MOD 4)) / 4y2 = y1 + MyDayMySum = y2 + yy//--------------------------------------------------------------------------// B - calculate the LEAP YEAR CodeLeapYear = CALL "IsLeapYear"[MyYear]//--------------------------------------------------------------------------// C - calculate the MONTH CodeIF LeapYear THENIF MyMonth = 10 THENMvalue = 0ELSIF MyMonth = 3 OR MyMonth = 11 THENMvalue = 3ELSIF MyMonth = 1 OR MyMonth = 4 OR MyMonth = 7 THENMvalue = 6ELSIF MyMonth = 9 OR MyMonth = 12 THENMvalue = 5ELSIF MyMonth = 5 THENMvalue = 1ELSIF MyMonth = 6 THENMvalue = 4ELSIF MyMonth = 2 OR MyMonth = 8 THENMvalue = 2ENDIFELSEIF MyMonth = 1 OR MyMonth = 10 THENMvalue = 0ELSIF MyMonth = 2 OR MyMonth = 3 OR MyMonth = 11 THENMvalue = 3ELSIF MyMonth = 4 OR MyMonth = 7 THENMvalue = 6ELSIF MyMonth = 9 OR MyMonth = 12 THENMvalue = 5ELSIF MyMonth = 5 THENMvalue = 1ELSIF MyMonth = 6 THENMvalue = 4ELSIF MyMonth = 8 THENMvalue = 2ENDIFENDIFMySum = MySum + Mvalue//--------------------------------------------------------------------------// D - calculate the CENTURY CodeCy = (MyYear - yy) MOD 400IF Cy = 0 THENcc = 6ELSIF Cy = 100 THENcc = 4ELSIF Cy = 200 THENcc = 2ELSEcc = 0ENDIFMySum = MySum + cc//--------------------------------------------------------------------------// E - calculate Day Of Weekd = (MySum MOD 7) + 1 //0=Sun, 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5= Fri, 6=SatRETURN dI tried to use several different methods, but couldn’t find any perfect one, each method turned out to have some faults. This is the most reliable I could write.
04/02/2019 at 11:18 AM #95305Excellent – thank you very much. Is there a reason we have the plus one before the return statement? It produces values: Monday == 2 to Friday == 6 on my end (maybe because I’m in US EST time zone?)
Anyways, I removed the plus one and get values 1-5. Thank you for this!
04/02/2019 at 12:34 PM #95317No reason for +1, I just added it to test what I liked most and forgot to remove it (0-6 is the most common used range).
This morning I tried another slightly different version and still got the same discrepancies:
- up to some date in 2006 everything works in a different way and I get plenty wrong results
- from there on till Jan.2011 the function returns almost always correct results but on some rare occasion sunday (not the other days) is reported incorrectly
from the end of January 2011 everything works fine. I’m giving up!
Have a good day.
04/02/2019 at 12:42 PM #95318So I tried putting together the code to retrieve the trading (business) days left in the month, but it appears to still be counting weekends. Not sure where/what I am missing?
123456789101112131415161718192021DEFPARAM CalculateOnLastBars = 35d,m,y = CALL UnpackDate[date]myDayMax = CALL DayMax[m, y]businessdaysleft = 0FOR count = 1 to myDayMax DOnewdate = date + countd,m,y = CALL UnPackDate[newdate]if d > myDayMax THENBREAKENDIFmyDayOfWeek = CALL GetDayOfWeek[newdate]IF myDayOfWeek >= 1 and myDayOfWeek <= 5 THENbusinessdaysleft = businessdaysleft + 1ENDIFNEXTRETURN businessdaysleft04/02/2019 at 1:44 PM #95329up to some date in 2006 everything works in a different way and I get plenty wrong results
If you check the chart in this post here you can see that the number of candles/bars in any year varies wildly.
https://www.prorealcode.com/topic/how-many-bars-in-a-year-indicator/#post-95091
I can understand some reasons such as the switch from 5 candle weeks to 6 candle weeks and leap years and varying holidays each year and special events that lead to market closures but it appears to me that more is going on than just this. I have the feeling that some of the back test data is not very clean!
04/02/2019 at 2:04 PM #9533104/02/2019 at 2:34 PM #95337I tried to GRAPH all individual elements from July 1979 (how come Eur/usd is quoted since then, but had only been approved on Jan, 1st 1999, 20 years later?!), Day, Month, Year separately and everything is fine, also, DayOfWeek matches the one calculated by eXcel.
I tried several different formulas and ALL of them reported some kind of error. They cannot be ALL erroneous!!!
I must assume that either:
- I did not fully understand the logic behind those formulas (likely to be the main reason)
- PRT use a different way of dealing with integers; actually PRT does support only floating point numbers, so even “i” in a FOR…NEXT iteration is not an integer. This may lead to some unwanted decimal digits being used or dropped when rounding or using MOD. They don’t need much integers for trading, so many basic features found in other programming languages are missing and this may lead to errors when doing some conversions.
But, since from Jan. 17th 2011 the code works fine, well… that’s enough for most cases!
04/02/2019 at 3:08 PM #95342dburgh, I changed a bit your code to make it easier to calculate the remaining business days:
12345678910111213141516171819202122DEFPARAM CalculateOnLastBars = 35d,m,y = CALL UnpackDate[opendate]myDayMax = CALL DayMax[m, y]businessdaysleft = 0myDayOfWeek = CALL GetDayOfWeek[opendate]FOR count = d to myDayMax DO//newdate = date + count//d,m,y = CALL UnPackDate[newdate]//if d > myDayMax THEN//BREAK//ENDIF//myDayOfWeek = CALL GetDayOfWeek[newdate]IF myDayOfWeek >= 1 and myDayOfWeek <= 5 THENbusinessdaysleft = businessdaysleft + 1ENDIFmyDayOfWeek = (myDayOfWeek + 1) MOD 7NEXTRETURN businessdaysleftI also replaced DATE with OPENDATE, since the first one is the date when a candle closes, while the latter when it opens.
In the first case both THURSDAY and FRIDAY report 5, since at the end of the closing daily Thursday candle the date is actually Friday, which is 5, when the next candle closes trading is stopped, so the DayOfWeek is not updated and it will still be 5 also on Friday. OPENDATE works fine.
Moreover, line 8 should start looping from “d”, not from 1.
04/02/2019 at 3:46 PM #95347 -
AuthorPosts
Find exclusive trading pro-tools on