Optuma Forums Optuma Scripting VALUEWHEN and NONZERO functions

This topic contains 0 replies, has 1 voice, and was last updated by Darren Darren 1 year, 1 month ago.

Viewing 1 post (of 1 total)
  • Author
  • #39207
    • Topics: 28
    • Replies: 131
    • Posts: 159

    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:




    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:


    V2 = IF(V1 == V1[1], 0, V1);


    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).



    • This topic was modified 1 year, 1 month 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

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.