Optuma Forums › Optuma Scripting › Williams %R, anchoring a date in a script/formula
Tagged: timesincesignal, STRDATE, ValueWhen, Bardate, $BARS
- This topic has 6 replies, 3 voices, and was last updated 4 months ago by
Louis.
-
AuthorPosts
-
April 21, 2020 at 9:58 pm #57705
James
- Topics: 16
- Replies: 11
- Posts: 27
Hi, I would like to anchor the date in a Williams %R column script instead of having to manually calculate the number of days since a certain event.
Thanks, Jamie
-
This topic was modified 2 years ago by
Darren.
April 21, 2020 at 11:03 pm #57707Darren
- Topics: 70
- Replies: 788
- Posts: 858
Hi Jamie,
You can do this using a combination of BarDate, StrDate, and ValueWhen functions. User the BarDate/StrDate to specify the date, and then nest the WR() function in the ValueWhen. The following in a watchlist shows the WR% value as of March 23rd 2020, ie -97.46 for XLF:
123456//Specify dateD1 = BARDATE()==STRDATE(DATE=2020-03-23);//Get %WR when D1 is trueVALUEWHEN(WR(BARS=10), D1)April 29, 2020 at 12:36 am #57823James
- Topics: 16
- Replies: 11
- Posts: 27
Hi Darren, thanks for your response. Is there a way to fix the date in WR like you can in the RIC function? Example: I want to calculate WR from 2/19/20. As of now, I have to manually count the days since 2/19 and input into WR function. As of today it would be 47 BARS so I would use WR(BARS=47). Can I fix the BARS to a date?
Thanks, Jamie
April 29, 2020 at 7:23 pm #57845Darren
- Topics: 70
- Replies: 788
- Posts: 858
Hi Jamie,
Ah sorry I understand now! The WR() function doesn’t have a fixed date option, but by calculating the time since a specific date we can use it in a $BARS variable within the WR() function. Use this in a Show View:
12345678//Get fixed date Bardate value;D1 = BARDATE()==STRDATE(DATE=2020-02-19);//Calculate time since date;$BARS = TIMESINCESIGNAL(D1);//Use time since for the lookback period;WR(BARS=$BARS)Currently it’s been 48 trading days since Feb 19th, so the green plot matches the 48 Period WR tool. Tomorrow the green line will automatically update to 49 periods.
January 14, 2022 at 8:54 am #67259Louis
- Topics: 33
- Replies: 55
- Posts: 88
Hi Darren,
I am having a problem using the above script with a ROC. Please see my version of the script below. Pictures attached. I made sure the watchlist is covering a date range of more than 1 year since the fixed date is almost 2 years. How can I get this to work?
12345678//Specify Fixed Date Of Covid LowD1 = BARDATE() = STRDATE(DATE=2020-03-20) ;//Calculate Time Since Covid Low Date$Bars = TIMESINCESIGNAL(D1) ;//Use Time Since Signal For ROC LookbackROC(Bars=$Bars)thank you
January 14, 2022 at 6:24 pm #67267Darren
- Topics: 70
- Replies: 788
- Posts: 858
Hi Louis,
Instead of using ROC() use the CHANGE() function and that will allow you to select a fixed date to calculate from.
January 15, 2022 at 2:21 am #67271Louis
- Topics: 33
- Replies: 55
- Posts: 88
Thank you, Darren! Worked perfectly.
-
AuthorPosts
- You must be logged in to reply to this topic.