Breadth Engine: Percent of stocks below a date

Hi guys,

I want to use the breadth engine to determine the percentage of S&P 500 stocks below their March 8th close. I will spare you the details of my attempts. Sorry I cannot figure this seemingly simple script out.

Attached is the chart I would like to duplicate. Please advise.

thank you


I would use the STRDATE() function to mark the specific date I was after, then use VALUEWHEN() to find the Closing price for that date which can be used to compare the current close with.

The final script would look like this:

V1 = STRDATE(DATE=2022-03-08) ;
V2 = BARDATE() ;
V3 = VALUEWHEN(V1 == V2) ;
CLOSE() < V3

When setup in the Breadth module, the value from Tuesday May 3rd matches your chart example of 44.84.


Thank you Matthew! Perfect! I am trying to figure out why your script works and how to apply that understanding to future scripting.

V1 = STRDATE(DATE=2022-03-08) ;
V2 = BARDATE() ;
V3 = VALUEWHEN(V1 == V2) ;
CLOSE() < V3

VALUEWHEN returns a value when a criteria is met. Okay. Why does the BARDATE function not have V1 imbedded? What is V3 in words? Find the value when 03/08/2022 is equal to what? I am missing something. Thank you.

BARDATE() returns an index value. So March 8 for example returns a value of 44,628. Rather than having to know and find that index value, STRDATE() converts that into a standard format of yyyy-mm-dd.

So V1 you select the date you are after.
V2 sets a BARINDEX value for all bars.
V3 says, when the BARINDEX value matches the selected date (March 8) show us the Closing value for that bar.

Thank you for laying that out. Does the BARINDEX value change over time? When I do a SHOWPLOT the value it returns 44,689, but it is a straight line, so I don’t see a value of 44,628 at all. What value is V2 actually setting? Does it change? What is the BARINDEX value for all bars? I don’t understand in V3 what the selected date of 3/8 is actually matching.

If you add a Show View to your chart and setup the script to:


You should see a line sloping up, with each date having its own value.

That is what V2 is setting, it is showing the value for each bar (which is the format bars show a date as by default in Optuma scripting). For March 8 the date value is 44,628

V1 takes a standard date format and converts it to the value scripts can reference. This allows us to mark a specific date on the chart, without having to work out what the date in number / index format is.

V1 == V2 then marks the bar that matches our date selection.