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.
-
-
09/11/2021 at 12:55 AM #177231
Hello All,
Just jumped on PRT and had a quick look – well more than a quick look but I’m short on basic coding skills tbh.
What I’d like to do is draw in 2 vertical lines:
8.00am
9.00am
I’d like these to be visible on future dates 1sec / tick chart ahead of time.
Barindex gets the job done in dynamic fashion but it’d like to see future vlines on upcoming periods week in adv. Been drawing them in manually, before the session and it becomes a little tedious!
Datetolastbarindex gets this done perfectly, many thanks for having this. However I need to modify the code manually (add future dates). I could do this weekly and would be better than nothing but does a param.(code) exist I can add that will draw these periods in, say for the next week or month perhaps ongoing even.
Please forgive my ignorance on this, it’s baby steps for me right now … 🙂
This is what’s been hacked together so far that works in 1sec interv:
VLines in the future1234567891011121314151617181920212223defparam drawonlastbaronly=truemydate = 20210910080000drawvline(datetobarindex(20210910))style(dottedline,2)drawvline(datetobarindex(20210913))style(dottedline,2)drawvline(datetobarindex(20210914))style(dottedline,2)drawvline(datetobarindex(20210915))style(dottedline,2)drawvline(datetobarindex(20210916))style(dottedline,2)drawvline(datetobarindex(20210917))style(dottedline,2)drawvline(datetobarindex(20210910090000))style(dottedline,2)drawvline(datetobarindex(20210913090000))style(dottedline,2)drawvline(datetobarindex(20210914090000))style(dottedline,2)drawvline(datetobarindex(20210915090000))style(dottedline,2)drawvline(datetobarindex(20210916090000))style(dottedline,2)drawvline(datetobarindex(20210917090000))style(dottedline,2)returnCheers,
INV
09/11/2021 at 10:44 AM #177243You can declare variables to be set using the indicator properties (settings), as from my screenshot.
This is the code (but I suggest that you download the ITF where those variables have already been added):
123456789101112131415161718192021defparam drawonlastbaronly=truedrawvline(datetobarindex(MyDate1))style(dottedline,2)drawvline(datetobarindex(MyDate2))style(dottedline,2)drawvline(datetobarindex(MyDate3))style(dottedline,2)drawvline(datetobarindex(MyDate4))style(dottedline,2)drawvline(datetobarindex(MyDate5))style(dottedline,2)drawvline(datetobarindex(MyDate6))style(dottedline,2)//MyDateA = (MyDate1 * 1000000) + 090000MyDateB = (MyDate2 * 1000000) + 090000MyDateC = (MyDate3 * 1000000) + 090000MyDateD = (MyDate4 * 1000000) + 090000MyDateE = (MyDate5 * 1000000) + 090000MyDateF = (MyDate6 * 1000000) + 090000drawvline(datetobarindex(MyDateA))style(dottedline,2)drawvline(datetobarindex(MyDateB))style(dottedline,2)drawvline(datetobarindex(MyDateC))style(dottedline,2)drawvline(datetobarindex(MyDateD))style(dottedline,2)drawvline(datetobarindex(MyDateE))style(dottedline,2)drawvline(datetobarindex(MyDateF))style(dottedline,2)return1 user thanked author for this post.
09/12/2021 at 12:10 AM #17727009/12/2021 at 12:45 AM #177271Hi Roberto,
I’m not sure 100% but the output to scr is the same as the original post.
I guess I was looking for a bit of code that won’t require me to add dates as we progress through the week manually, the two examples above will cease to plot beyond 2021-09-17 (20210917) for example.
Many thanks again,
inv
09/12/2021 at 7:27 AM #177272I think I got you now.
This will plot Today’s and Tomorrow’s lines at the given hours (not tested):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960defparam drawonlastbaronly=trueMyDate = DateMyDD = DayMyMM = MonthMyYY = Year//// plot today’s lines (add hours)//x = (MyDate * 1000000) + 080000y = (MyDate * 1000000) + 090000drawvline(datetobarindex(x))style(dottedline,2)drawvline(datetobarindex(y))style(dottedline,2)//// plot tomorrow’s lines//// compute tomorrow’s date (could be a new month, even a new year)//// compute the last day of the monthLastDay = 31// it’s max 30 on a few monthsIf MyMM = 4 or MyMM = 6 or MyMM = 9 or MyMM = 11 ThenLastDay = 30Endif// 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// build tomorrow’s dateMyDD = MyDD + 1// if it’s greater than LastDay it’s the next monthIf MyDD > LastDay ThenMyDD = 1MyMM = MyMM + 1// if it’s greater than 12 it’s a new yearIf MyMM > 12 ThenMyMM = MyMM - 12MyYY = MyYY + 1EndifEndif// make sure it’s the same number of digits for days < 10If MyDD < 10 ThenMyDate = (MyYY * 10000) + (MyMM * 1000) + MyDDElseMyDate = (MyYY * 10000) + (MyMM * 100) + MyDDEndif// last step, add hoursx = (MyDate * 1000000) + 080000y = (MyDate * 1000000) + 090000drawvline(datetobarindex(x))style(dottedline,2)drawvline(datetobarindex(y))style(dottedline,2)returnOther days could be added by duplicating the same lines used for Tomorrow’s date (no need to change any of them).
09/12/2021 at 9:14 AM #177274This is the same indicator as above, modified so that it allows to set properties so that the TIMES and the number of DAYS (starting from the current day) can be easily changed.
To plot only ONE line, just set the same TIME for both.
Time can be any value from 000000 to 235959 (240000 doesn’t exist, it’s 000000 the next day). I suggest that you always enter 6 digits for the time , despite the leading 0s will then be dropped.
If you want to stop plotting lines, just use 0 as the number of days (or hide the indicator).
Plot Lines on Future Days1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768defparam drawonlastbaronly=true//Time1 = 080000//Time2 = 090000//NumberOfDays = 2Time1 = max(0,min(235959,Time1))Time2 = max(0,min(235959,Time2))NumberOfDays = max(0,min(999,NumberOfDays))MyDD = DayMyMM = MonthMyYY = Year//DayCount = NumberOfDaysWhile DayCount > 0 DO//// make sure it’s the same number of digits for days < 10If MyDD < 10 ThenMyDate = (MyYY * 10000) + (MyMM * 1000) + MyDDElseMyDate = (MyYY * 10000) + (MyMM * 100) + MyDDEndif// last step, add hoursx = (MyDate * 1000000) + Time1y = (MyDate * 1000000) + Time2//// plot the lines//drawvline(datetobarindex(x))style(dottedline,2)drawvline(datetobarindex(y))style(dottedline,2)//// get ready to build tomorrow’s date, if needed//// compute tomorrow’s date (could be a new month, even a new year)//// 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 plottedWendRETURNImporting the attached ITF file will spare you from having to add variables.
1 user thanked author for this post.
09/12/2021 at 11:18 AM #177293Wow Robert …. exposes my inabilities nicely … !
I’m going to have a closer look here and see if;
1) I get how it’s come together and;
2) see point 1 again … 😉
I’ll post back over the coming days, might take me a while to get my head around it haha
Many thanks again.
09/12/2021 at 12:09 PM #177302Just letting you know Robert …. calc comes out good, added a third and 4th period for completeness of testing but can’t see that far ahead on 1sec inter., still confident all’s good (the 13th and 14th SEP are there).
There’s an info message that says some tweaking could improve perf. – it’s specific to my unit count.
The preview is tiny / blurred below so have posted to imgur too.
Thanks for the ongoing support!
09/12/2021 at 12:40 PM #177306Post JPG/PNG pics, not links.
Thank you.
On very small TFs you can’t go ahead much.
09/12/2021 at 11:22 PM #177352Apologies I dropped a .png in but the image was removed upon post – odd.
Here we go again, hope it survives the process!
Looks blurry in preview again, it’s only 7kb.
edit: yay, it worked this time .. 🙂
1 user thanked author for this post.
09/13/2021 at 1:09 AM #177354Just a quick one Robert – all okay on the small time frame, not being able to go so much ahead, a few days is all that’s needed. Was nicer this morning to not housekeep the opens and with upcoming sessions / tomorrows already in place, I’ve had time for another espresso .. !
Not sure if I’ve looked hard enough quite yet to see whether it’ll maintain the “historical” vlines in place (or drop the previous days) – should know more tomorrow and coming sessions.
Thanks again.
09/13/2021 at 7:53 AM #177359Line 1 prevents historical lines from being still in place.
You can comment it out.
09/13/2021 at 8:40 AM #17736809/13/2021 at 11:14 AM #177411This seems to be a limit when calucating bar indexes using dates.
09/13/2021 at 12:49 PM #177418As a guess not many would find this useful so it mightn’t be a high priority, having said that, the datetolastbar is newish so could be in the pipe maybe 😉
For now a hybrid of the two might work in tandem across both longer and shorter timeframes quite well. As humans we also need to interface with what’s in the tool chest.
Many thanks for all the help, have a safe and good one … 🙂
-
AuthorPosts
Find exclusive trading pro-tools on