The high cannot be higher then the highest high, it has to be equal to. Also, the ACC() function doesn’t allow for a date range so we need to use the ACCSINCESIGNAL() function with the signal being when the year changes:
//Get new highs;
H1 = HIGH() >= HIGHESTHIGH(BACKTYPE=Weeks, BARS=52, INCBAR=True);
//Change in year;
Y1=YEARNUM() IsUp;
//Count new highs in each year;
ACCSINCESIGNAL(H1, Y1)
So for SPX there were 26 52 week highs in 2023, and 15 so far this year:
You would need to make sure the Watchlist Date Range was set to Everything first. Then you can add additional lines to Darrens script example to find the value for specific dates.
In this example I’ve set it up to show me the value on the last trading day of 2023:
//Get new highs;
H1 = HIGH() >= HIGHESTHIGH(BACKTYPE=Weeks, BARS=52, INCBAR=True);
//Change in year;
Y1=YEARNUM() IsUp;
//Count new highs in each year;
V1 = ACCSINCESIGNAL(H1, Y1);
//Specific Year 2023
V2 = BARDATE() ;
V3 = STRDATE(DATE=2023-12-29) ;
V4 = V2 == V3;
VALUEWHEN(V1,V4)
You can adjust V3 to any date you are wanting to view the scripts results for.
Your solution to use the last day of each year to create the script work perfectly. The function valuewhen is exact the thing that I am looking for in the past several days.
I found a small anomalie when I try to get the result for the year 2018.
In fact if I use STRDATE(DATE=2018-12-31) the result returns will be 0 for any security. When I modify the date to 2018-12-28, then the script works again.
I don’t know why it happens like this, since my object of learning the market internals is met, so you guys can check this out whenever you want.
I want to clearify that the script works perfectly, the reason that I have difficulty in getting the value for the year 2018 is that the 12-31-2018 was not a trading day in Chinese equites market.
I am very sorry and I will be more careful next time to check everything first.
Thanks for the help from everybody and have a good day.