VALUEWHEN and NONZERO functions

Optuma Forums Optuma Scripting VALUEWHEN and NONZERO functions

This topic contains 0 replies, has 1 voice, and was last updated by Darren Darren 3 months, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #39207
    Darren
    Darren
    • Topics: 13
    • Replies: 51
    • Posts: 64

    The VALUEWHEN function can be used to calculate the price or indicator value when a certain technical condition occurs, such as the price of the previous pivot high:

     

    VALUEWHEN(HIGH(),PIVOT(MIN=10, TYPE=High))

     

    But what if we wanted to know the value of the previous pivot high, before the last one? This is where we can use the NONZERO function, combined with an offset:

     

    V1 = VALUEWHEN(HIGH(),PIVOT(TYPE=High, MIN=10));
    V2 = IF(V1 == V1[1], 0, V1);
    NONZERO(V2)[1]

     

    Note that the number in the square brackets eg [1] is a streamlined way of using an offset, so the [1] is the previous value, and [2] is the value 2 periods ago.

    Using the IF statement, when the last pivot value V1 is the same as yesterday (V1 == V1[1]) then set V2 to zero, but if it has changed use the value of V1.

    The NONZERO function gives  the last value when V1 wasn’t 0 ie. in our case, when the pivot last changed. In this example the watchlist columns show the values of the last 3 pivot highs, and the two Show Views plots V2 when the new pivot occurs (in red) and value of those pivot changes using the NONZERO function (in green).

    Capture

     

    • This topic was modified 3 months, 3 weeks ago by Darren Darren.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

Pin It on Pinterest

Share This