Williams %R, anchoring a date in a script/formula

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

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:

//Specify date
D1 = BARDATE()==STRDATE(DATE=2020-03-23);
//Get %WR when D1 is true


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

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:

//Get fixed date Bardate value;
D1 = BARDATE()==STRDATE(DATE=2020-02-19);
//Calculate time since date;
//Use time since for the lookback period;

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.


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?

//Specify Fixed Date Of Covid Low 
D1 = BARDATE() = STRDATE(DATE=2020-03-20) ; 
//Calculate Time Since Covid Low Date 
//Use Time Since Signal For ROC Lookback 

thank you

Hi Louis,

Instead of using ROC() use the CHANGE() function and that will allow you to select a fixed date to calculate from.

Thank you, Darren! Worked perfectly.