Docs

ta.valuewhen

Read a series as it stood when a condition last held, or the nth time before.

itm
ta.valuewhen(condition, source, occurrence)

The value the source had when the condition was last true (or the nth previous time it was true).

Parameters

A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.

NameKindTypeDefaultRangeDescription
conditionSeriesbool--When to sample.
sourceSeriesnumber--The series to sample.
occurrenceConstantnumber00 to 2550 = the most recent occurrence, 1 = the one before it.

Output

NameType
valuenumber

Warm-up and missing values

Warm-up
1 bar.
Missing values
na until the condition has been true occurrence + 1 times.

Example

itm
ta.valuewhen(ta.crossover(close, ma), close, 0)
itm
cross = ta.crossover(close, ta.sma(close, 20))
plot(ta.valuewhen(cross, close, 0), "Close at cross")