Recurring Vertical Lines – datetolastbarindex
Forums › ProRealTime English forum › ProBuilder support › Recurring Vertical Lines – datetolastbarindex
- This topic has 40 replies, 2 voices, and was last updated 10 months ago by inverse.
-
-
02/19/2024 at 9:38 AM #228380
Importing the attached ITF file will spare you from having to add variables.
Sorry to be a pain Rob, I’ve hit a wall of sorts and it looks similar to the ITF you kindly provided back in the day (it too hits the same wall when plotting past the end of the old month and into a new month). Not posting this as a bump because I know you have your hands full more so to say there’s a bit of consistency here and it could be a simple one for your IP.
I can plot lines half a dozen different ways (just about) and they work well w/in a given month, it’s only when you lean into the next months plot(s) that it falls over.
I’ve even peeled out the last day of the month compute and it has no effect, so I’m guessing in there is the solution vs DayCount cfg perhaps.
I know the dates are in numeric format and the ‘additional days’ are in integer form but I’ve not been able to push by what appears to be a hard limit (for me). Probably my lack of IP … !
Below is a basic setup that manifests in the same way as the previously linked ITF. Just pushout the NumberOfDays variable past months end and it should break. The ITF linked a few pages back by you will also error. I feel like a bit of a dill not having picked up on it back in the day – would’ve prevented the need to revisit now but it’s now that as I’m putting together a housekeeping guide for family that I’ve come back to it. The historical ITF was extremely helpful in identifying where APAC and EU sessions influence, so many thanks for that input (was foundational for me with PRT).
/rant
Cheers,
inv
Basic vline123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122defparam drawonlastbaronly=true// Define the anchor date (MyDate1), month (MyMM), and year (MyYY)MyDate1 = 20240118 // Assign the anchor date//MyMM = 10 // Assign the month//MyYY = 23 // Assign the year// Initialize the number of days ahead for each subsequent DateNumberOfDays = 00 // Change this value to adjust the number of days aheadNumberOfDays1 = 09 // Change this value to adjust the number of days aheadNumberOfDays2 = 12 // Change this value to adjust the number of days ahead// Calculate subsequent datesMyDateA = MyDate1 + NumberOfDaysMyDateB = MyDate1 + NumberOfDays1MyDateC = MyDate1 + NumberOfDays2//drawvline(datetobarindex(MyDateA))style(dottedline,2)coloured("red")drawvline(datetobarindex(MyDateB))style(dottedline,2)coloured("red")drawvline(datetobarindex(MyDateC))style(dottedline,2)coloured("red")//inc. to POC formatt could be okay and straightup plots vlines where it should//drawvline(datetobarindex(20240215))style(dottedline,2)coloured("red")//drawvline(datetobarindex(202402150000+000000140000))style(dottedline,2)coloured("red")//drawvline(datetobarindex(20240215000000+00000014000000))style(dottedline,2)coloured("red")// Initialize MyDD, MyMM, and MyYYMyDD = DayMyMM = MonthMyYY = Year//DayCount = NumberOfDaysWhile DayCount > 00 DO//// make sure it’s the same number of digits for days < 10//If MyDD < 10 Then //was 10 but needed to go to 0//If MyDD < 00 ThenMyDate = (MyYY * 10000) + (MyMM * 1000) + MyDDElseMyDate = (MyYY * 10000) + (MyMM * 100) + MyDDEndif// 1. compute the last day of the monthLastDay = 31// 2. it’s max 30 on a few monthsIf MyMM = 4 or MyMM = 6 or MyMM = 9 or MyMM = 11 ThenLastDay = 30Endif// 3. it’s max 28 days in February, 29 on a leap yearIf MyMM = 2 ThenLastDay = 28If Year MOD 4 = 0 ThenIf Year MOD 100 = 0 ThenIf Year MOD 400 = 0 ThenLastDay = 29EndifElseLastDay = 29EndifEndifEndif//MyDD = MyDD + 1// 4. if it’s greater than LastDay it’s the next monthIf MyDD > LastDay ThenMyDD = 1MyMM = MyMM + 1// 5. if it’s greater than 12 it’s a new yearIf MyMM > 12 ThenMyMM = MyMM - 12MyYY = MyYY + 1EndifEndif//DayCount = DayCount - 1 //one day has been plottedwendreturn02/19/2024 at 12:56 PM #228393This post (and the following one) https://www.prorealcode.com/topic/need-help-with-date/#post-228150 might be of some help. Still it’s not exactly what you want.
When you have a DATE, you must:
- decompose it into Year, Month and Day
. - calculate the last day of the Month (taking into account leap years) then add the desired number of days to the Day to get a NEW date
. - pack the new YY, MM and DD into a date in the format YYYYMMDD.
.
I coded this snippet (tested against eXcel over a few centuries, roughly 200K days, to test leap years), to add days to any starting date (it can be easily adapted to subtractions):
123456789101112131415161718192021222324252627282930313233343536oldDate = 20210723DD = oldDate MOD 100 //get DAYtempDate = (oldDate - DD) / 100MM = tempDate MOD 100 //get MONTHYY = (tempDate - MM) / 100 //get YEARtempDD = DD + 68 //add 68 days to compute the new datetempX = DDWhile 1 DoLastDay = 31IF MM = 4 OR MM = 6 OR MM = 9 OR MM = 11 THENLastDay = 30ELSIF MM = 2 THENLastDay = 28IF YY MOD 4 = 0 THENIF YY MOD 100 = 0 THENIF YY MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD = tempDD - LastDayMM = MM + 1IF MM > 12 THENYY = YY + 1MM = 1ENDIFtempX = 0WendnewDate = (YY * 10000) + (MM * 100) + tempDD //pack data into a new date1 user thanked author for this post.
02/20/2024 at 12:38 AM #228422Many thanks Rob, your feedback is appreciated!
I’ll have a look when I get a moment, probably closer to weekend, could be sooner, kind of eager to iron this one out or shelve it if need be, yet, I’m ever hopeful it can be sorted … 🙂
02/20/2024 at 1:15 AM #228423Not bad for not having tested it Rob!
Dropped it in a new indicator, defined a vline for ‘olddate’ and ‘newdate’ and it plotted both.
I’ve always thought how weekend data is handled could be a problem, so I’ll POC against some manual calcs I have and see how close it marries.
For now it looks very very good.
02/20/2024 at 7:56 AM #228425123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109oldDate = 20210723DD = oldDate MOD 100 //get DAYtempDate = (oldDate - DD) / 100MM = tempDate MOD 100 //get MONTHYY = (tempDate - MM) / 100 //get YEARtempDD = DD + 99 //add 68 days to compute the new datetempX = DDoldDate1 = 20210823DD1 = oldDate1 MOD 100 //get DAYtempDate1 = (oldDate1 - DD1) / 100MM1 = tempDate1 MOD 100 //get MONTHYY1 = (tempDate1 - MM1) / 100 //get YEARtempDD1 = DD1 + 233 //add 68 days to compute the new datetempX1 = DD1While 1 DoLastDay = 31IF MM = 4 OR MM = 6 OR MM = 9 OR MM = 11 THENLastDay = 30ELSIF MM = 2 THENLastDay = 28IF YY MOD 4 = 0 THENIF YY MOD 100 = 0 THENIF YY MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD = tempDD - LastDayMM = MM + 1IF MM > 12 THENYY = YY + 1MM = 1ENDIFtempX = 0WendWhile 1 DoLastDay = 31IF MM1 = 4 OR MM1 = 6 OR MM1 = 9 OR MM1 = 11 THENLastDay = 30ELSIF MM1 = 2 THENLastDay = 28IF YY1 MOD 4 = 0 THENIF YY1 MOD 100 = 0 THENIF YY1 MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD1 - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD1 = tempDD1 - LastDayMM1 = MM1 + 1IF MM1 > 12 THENYY1 = YY1 + 1MM1 = 1ENDIFtempX1 = 0WendnewDate = (YY * 10000) + (MM * 100) + tempDD //pack data into a new datenewDate1 = (YY1 * 10000) + (MM1 * 100) + tempDD1 //pack data into a new datedrawvline(datetobarindex(olddate))style(dottedline,2)coloured("red")drawvline(datetobarindex(newdate))style(dottedline,2)coloured("red")drawvline(datetobarindex(newdate1))style(dottedline,2)coloured("red")returnThe above works but as you can see it’s a replication of one process to add another single plot, which I’m happy to say works well, so there’s wins here.
Is there another way to do this without replicating large chunks I wonder?
Needing to ‘decompose’ the anchoring date each time is the crux here (thanks for emphasizing this Rob) , so we can ‘add’ too it and create the subsequent day counts, then run though the lastday/date loop to process the plot accordingly.
I can tweak the lastday/date loop, to ‘bundle’ all the dates and years w/in the single loop (I think) but if I wanted 30 of them, wow, I’m hoping there’s an easier way.
I’ll have a go at it again and see if I can compress a little, no doubt it’ll be a right mess but I’ll have a go. Any words of wisdom are welcomed and appreciated.
Cheers,
inv
02/20/2024 at 12:07 PM #228439We can use arrays, but 2 separate indicators are needed, as the whole process need two nested loops, which returns an error:
- MyDateCaller, is the first indicator which contains tha dates to be handled and the number of days to be added; it simply calls the second indicator passing it the two parameters (date + days)
- DateSum, is the second indicator; it gets the two parameters, doing the required math, then returns the newDate to the caller.
MyDateCaller123456789101112131415161718192021// dates are not required to be in any order//$myDate[1] = 20210723$myDate[2] = 20210823$myDate[3] = 20200807$myDate[4] = 20221023$myDate[5] = 20230830$myDate[6] = 0 //set to 0 if not needed$myDate[7] = 20170912//Days2Add = 99//FOR i = 1 TO lastset($myDate)oldDate = $myDate[i]newDate = CALL "DateSum"[oldDate,Days2Add]IF newDate > 0 THENdrawvline(datetobarindex(olddate))style(dottedline,2)coloured("red")drawvline(datetobarindex(newdate))style(dottedline,2)coloured("Green")ENDIFNEXTreturnDateSum12345678910111213141516171819202122232425262728293031323334353637383940newDate = 0IF myDate <> 0 THENoldDate = myDateDD = oldDate MOD 100 //get DAYtempDate = (oldDate - DD) / 100MM = tempDate MOD 100 //get MONTHYY = (tempDate - MM) / 100 //get YEARtempDD = DD + Days2Add //add N days to compute the new datetempX = DDWhile 1 DoLastDay = 31IF MM = 4 OR MM = 6 OR MM = 9 OR MM = 11 THENLastDay = 30ELSIF MM = 2 THENLastDay = 28IF YY MOD 4 = 0 THENIF YY MOD 100 = 0 THENIF YY MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD = tempDD - LastDayMM = MM + 1IF MM > 12 THENYY = YY + 1MM = 1ENDIFtempX = 0WendnewDate = (YY * 10000) + (MM * 100) + tempDD //pack data into a new dateENDIFreturn NewDateonly the indicator MyDateCaller needs to be added to your chart, the other simply needs to be present in the platform, among all other indicators.
You may add as many dates as needed as array elements in the calling indicator.
02/20/2024 at 1:39 PM #228451I don’t know what to say Rob. Thankyou. Honestly wow.
I’ll give this a lookover, so I can do it a bit of justice.
The current setup from, your workings, as I have tweaked it, adds days to a single date as well, as seen further on up above, my last effort, so will try that with myDateCaller, where I’ll have a series of numbers to be added to the date or dates. We count forward random day counts from a single date.
So we’ll have say:
$myDate[1] = 20210723
plus 3 days
plus 12 days
plus 20 days
plus 27 days
We’ll plot these days.
It’s here where I became unglued if you will and had to create multiple DateSums equiv. but here you’re calling it to calc out.
Yes, I think this will do nicely on that front but will I be able to handle the multiple days as above, 3, 12, 20 etc or will I need to call the days as well.
I have a go and let you know how it goes, fingers crossed … 🙂
Many thanks again.
02/20/2024 at 1:53 PM #228453123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208oldDate = 20230227DD = oldDate MOD 100 //get DAYtempDate = (oldDate - DD) / 100MM = tempDate MOD 100 //get MONTHYY = (tempDate - MM) / 100 //get YEARtempDD = DD + 10 //add 10 days to compute the new datetempX = DDDD1 = oldDate MOD 100 //get DAYtempDate1 = (oldDate - DD1) / 100MM1 = tempDate1 MOD 100 //get MONTHYY1 = (tempDate1 - MM1) / 100 //get YEARtempDD1 = DD1 + 20 //add 20 days to compute the new datetempX = DD1DD2 = oldDate MOD 100 //get DAYtempDate2 = (oldDate - DD2) / 100MM2 = tempDate2 MOD 100 //get MonthYY2 = (tempDate2 - MM2) / 100 //get YEARtempDD2 = DD2 + 30 //add 30 days to compute the new datetempX = DD2DD3 = oldDate MOD 100 //get DAYtempDate3 = (oldDate - DD3) / 100MM3 = tempDate3 MOD 100 //get MonthYY3 = (tempDate3 - MM3) / 100 //get YEARtempDD3 = DD3 + 40 //add 40 days to compute the new datetempX = DD3//day1While 1 DoLastDay = 31IF MM = 4 OR MM = 6 OR MM = 9 OR MM = 11 THENLastDay = 30ELSIF MM = 2 THENLastDay = 28IF YY MOD 4 = 0 THENIF YY MOD 100 = 0 THENIF YY MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD = tempDD - LastDayMM = MM + 1IF MM > 12 THENYY = YY + 1MM = 1ENDIFtempX = 0Wend//day2While 1 DoLastDay = 31IF MM1 = 4 OR MM1 = 6 OR MM1 = 9 OR MM1 = 11 THENLastDay = 30ELSIF MM1 = 2 THENLastDay = 28IF YY1 MOD 4 = 0 THENIF YY1 MOD 100 = 0 THENIF YY1 MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD1 - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD1 = tempDD1 - LastDayMM1 = MM1 + 1IF MM1 > 12 THENYY1 = YY1 + 1MM1 = 1ENDIFtempX = 0Wend//day3While 1 DoLastDay = 31IF MM2 = 4 OR MM2 = 6 OR MM2 = 9 OR MM2 = 11 THENLastDay = 30ELSIF MM2 = 2 THENLastDay = 28IF YY2 MOD 4 = 0 THENIF YY2 MOD 100 = 0 THENIF YY2 MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD2 - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD2 = tempDD2 - LastDayMM2 = MM2 + 1IF MM2 > 12 THENYY2 = YY2 + 1MM2 = 1ENDIFtempX = 0Wend//day4While 1 DoLastDay = 31IF MM3 = 4 OR MM3 = 6 OR MM3 = 9 OR MM3 = 11 THENLastDay = 30ELSIF MM3 = 2 THENLastDay = 28IF YY3 MOD 4 = 0 THENIF YY3 MOD 100 = 0 THENIF YY3 MOD 400 = 0 THENLastDay = 29ENDIFELSELastDay = 29ENDIFENDIFENDIFmyRemainder = tempDD3 - LastDayIF myRemainder <= 0 THENbreakENDIFtempDD3 = tempDD3 - LastDayMM3 = MM3 + 1IF MM3 > 12 THENYY3 = YY3 + 1MM3 = 1ENDIFtempX = 0WendThis was the setup, pre your latest reply Rob, you can see how the wheels been re-invented a few times here!
I think we’re headed in the right direction (your last post) and appreciate your time.
02/20/2024 at 4:21 PM #228465Replace the calling indicator MyDateCaller with this one:
1234567891011121314151617181920212223242526$myDate[1] = 20210723$myDate[2] = 20210823$myDate[3] = 20200807$myDate[4] = 20221023$myDate[5] = 20230830$myDate[6] = 20230226$myDate[7] = 20170912$add2date[1] = 99$add2date[2] = 315$add2date[3] = 18$add2date[4] = 65$add2date[5] = 30$add2date[6] = 544$add2date[7] = 210FOR i = 1 TO lastset($myDate)oldDate = $myDate[i]Days2Add = $add2date[i]newDate = CALL "DateSum"[oldDate,Days2Add]IF newDate > 0 THENdrawvline(datetobarindex(olddate))style(dottedline,2)coloured("red")drawvline(datetobarindex(newdate))style(dottedline,2)coloured("Green")ENDIFNEXTreturnI added an array also for the number of days to add to a date. Element 1 of the array $add2date will be added to element 1 of the array $myDate and so on…
1 user thanked author for this post.
02/20/2024 at 8:47 PM #228480Thanks Rob, I’ll give this a go and see how it works.
I was hopeful that we could cfg dates and added nbrs via GUI, which is were you implied earlier on that this will get us to a working solution maybe minus the full GUI capability but everything’s a measure in compromise, so if I can get a workable solution it probably doesn’t matter where I plug the dates into and if the # are kind of static we can housekeep those and we can then focus on ‘ beautification of dates ‘ once I see how it’ll impact workflows but from we are at the moment there’s been huge wins imo, so thanks again.
02/21/2024 at 2:30 AM #228487 - decompose it into Year, Month and Day
-
AuthorPosts
Find exclusive trading pro-tools on