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:
V1 = VALUEWHEN(HIGH(),PIVOT(TYPE=High, MIN=10));
V2 = IF(V1 == V1, 0, V1);
Note that the number in the square brackets eg  is a streamlined way of using an offset, so the  is the previous value, and  is the value 2 periods ago.
Using the IF statement, when the last pivot value V1 is the same as yesterday (V1 == V1) 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).
You must be logged in to reply to this topic.