# Average of all stocks below their 252-day highs as a breadth tool

Hi,

In a watchlist I have calculated the distance of each S&P 500 stock from its 252-day closing high with the following script:

```V1 = HIGHESTHIGH(CLOSE(), BARS=252, INCBAR=True) ;
V2 = CLOSE() ;
100 * ((V2 - V1) / V1)```

In the watch list summary row, I selected average above this script column. This is showing the average of all of the 505 stocks are below their 252-day closing highs. Please see attached picture 1.

I want to plot this average value, the average that all stocks are below their 252-day highs, in a breadth tool. I cannot figure out the correct script. I set the breadth action setting to sum and tried to normalize the formula but it doesn’t match the watchlist value:

```V1 = HIGHESTHIGH(CLOSE(), BARS=252, INCBAR=True) ;
V2 = CLOSE() ;
(100 * ((V2 - V1) / V1)) / 505```

Please advise on the way to show this average value from the watchlist in a breadth tool. Thank you as always.

Hi,

You would use the same script as you did on the Watchlist:

V1 = HIGHESTHIGH(CLOSE(), BARS=252, INCBAR=True) ;
V2 = CLOSE() ;
100 * ((V2 - V1) / V1)

There’s no need to account for the number of symbols, the Breadth manager will do that automatically.

Set the Breadth Action to Average and the value generated should match the summary row of the Watchlist.

Hi Matthew. This is what I tried originally, but the values do not match.

The value from the watchlist is 8.41%.
The value from the breadth tool is 16%.

This discrepancy is because in the breadth engine, the average setting divides the result of the script by the total amount of items being checked. 8.41/505 = 16. Please see pictures 1, 2 and 3 attached.

thank you,

Hi,

I can’t work out how you’ve produced a value of -8.41 on the WL summary. When I use the same script between Breadth and WL Average, the values both show -16.074.

If you open the attached WL do you see the same value?

If you do, please attach your workbook for review, or email a copy to [email protected] if you do not want to make the file available publically.

TestWL.owb (169 KB)

Thank you. You workbook looks great. I went back and crated a new watchlist and the average changed to the 16% value. Not sure why this happened, but you saw the picture. I did not change the script, just started a new watchlist.

I am very happy this is now working properly. I am just a little confused. The knowledge base says: “Average - Based on the Sum above, this one divides the result by the total number of members to get an average each day.” https://help.optuma.com/kb/faq.php?id=644. When does this setting perform the division?

Thank you.

Hi,

Glad it’s working now. Not sure where the other value came from, I went through all the options, only thing i can think is it calculated before an EOD update had finished so it was incomplete data, i will need to test further to see if i can replicate.

For your second question, i think it is working as described.

The sum on the WL column is -8,117.3555, divided by the 505 members currently in the list the average value comes to -16.07, matching the breadth and average value produced by the WL header row.

Thank you so much for explaining that. You are a smart guy. Don’t waste too much time checking into it. My computer is old and has poor computing power. I get glitches all of the time where Optuma tells me I have run out of memory and there is this or that error requiring a restart. Thanks again.

Hi Darren and Louis,

I have a question about the “ISMEMBER()” function in the script for the breadth module. Darren, you wrote in another threat that the “ISMEMBER() function only works with true/false conditions, not when calculating averages.”

In the above breadth scripts we calculate averages so the ISMEMBER() makes no sense.

There is now my question/issue: If I set the breadth module property “Membership” to “Current” the historical results are the same as when I set it to “Historical”. If I add the ISMEMBER() function to the breadth script, the results are completely wrong.

But that shouldn’t be the case in my opinion. When I set it to “Historical” and would use/could use the function ISMEMBER() the historical results of the script should be different than setting it to “Current”.

By the way, the same problem occurs when I calculate the average drawdown using the following script:

```// 52 Week Drawdown
DDP(BACKTYPE=Weeks, LOOKBACKBARS=52)```

Thanks and best wishes,
Thomas

Hi Louis,

perhaps the following breadth script is something you are interested in:

```// S&P 500 Members >= 10% below 52-Week High
Var1 = HIGHESTHIGH(CLOSE(), BARS=52, INCBAR=True, BACKTYPE=Weeks) ;
Var2 = CLOSE() ;
Var3 = ((Var2 - Var1) / Var1) * 100 ;
Var4 = Var3 <= -10 ;
Var4```
```// Stock is Member of S&P 500
ISMEMBER(SYMBOLLIST=S&P 500)```

Here is a screenshot of my Breadth module settings:

I think the above scripts are perhaps better suited for what you are looking for.

Best wishes,
Thomas

Hi Thomas,

I believe you can use ISMEMBER() in an Average based breadth, but it needs to be setup differently. In this example the script would be modified to include ISMEMBER this way…

```V1 = HIGHESTHIGH(CLOSE(), BARS=252, INCBAR=True) ;
V2 = CLOSE() ;
V3 = 100 * ((V2 - V1) / V1);
V4 = ISMEMBER(SYMBOLLIST=S&P 500) ;
IF(V4 == 1,V3,0)```

Here’s a comparison of the above script using Historical vs Current memberships (Historical is Blue, Current is Green):

You can see the lines are pretty identical near the recent price action, but differs more and more the further back the breadth goes, as memberships change.