ValueWhen() Function

Author: Optuma Team Last updated: Apr 21, 2020 22:57

The VALUEWHEN() function can be used to calculate the open, high, low, or close price or indicator value when a certain technical condition occurs. It can also be used with the BarDate/StrDate function to get a value as of a specific date.

For example, to find out the closing price of a stock when the 50MA last crossed below the 200MA:

V1 = MA(BARS=50, CALC=Close) CrossesBelow MA(BARS=200, CALC=Close);  
VALUEWHEN(V1)

To find the high price on the day of the cross:

V1 = MA(BARS=50, CALC=Close) CrossesBelow MA(BARS=200, CALC=Close);  
VALUEWHEN(HIGH(), V1)

To find the value of the MA50 when they crossed:

V1 = MA(BARS=50, CALC=Close) CrossesBelow MA(BARS=200, CALC=Close);  
VALUEWHEN(MA(BARS=50, CALC=Close), V1)

To find the RSI(14) value when they crossed:

V1 = MA(BARS=50, CALC=Close) CrossesBelow MA(BARS=200, CALC=Close);  
VALUEWHEN(RSI(BARS=14), V1)

To find the value of the last 10 bar pivot high:

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

To find the RSI value on a specific date, eg March 23rd 2020:

D1 = BARDATE()==STRDATE(DATE=2020-03-23);  
VALUEWHEN(RSI(BARS=14), D1)