Skip to content

ValueWhen() Function

By Optuma Team · Updated 2020-04-21

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)

Choose which categories of cookies you allow. Strictly-necessary cookies are always on. You can change this any time via the "Cookie Settings" link in the footer.

  • Functional

    Remember preferences like dismissed banners and your dark-mode choice.

  • Analytics

    Help us understand how the site is used so we can improve it.

  • Marketing

    Measure our advertising and help us reach people who may be interested in Optuma.