Breadth Engine: Percent of stocks below a date

Optuma Forums Optuma Scripting Breadth Engine: Percent of stocks below a date

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #68141
    Louis
    • Topics: 33
    • Replies: 55
    • Posts: 88

    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

    #68146
    Matthew
    • Topics: 5
    • Replies: 609
    • Posts: 614

    Hi,

    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:

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

    Ex2

    #68151
    Louis
    • Topics: 33
    • Replies: 55
    • Posts: 88

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

    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.

    1 user thanked author for this post.
    #68154
    Matthew
    • Topics: 5
    • Replies: 609
    • Posts: 614

    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.

    1 user thanked author for this post.
    #68155
    Louis
    • Topics: 33
    • Replies: 55
    • Posts: 88

    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.

    #68156
    Matthew
    • Topics: 5
    • Replies: 609
    • Posts: 614

    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.

    Ex4

    • This reply was modified 2 weeks ago by Matthew.
    1 user thanked author for this post.
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest