ta.valuewhen
Value of source on the bar where condition was true, occurrence times back (0 = most recent).
ta.valuewhen(condition: bool, source: any, occurrence: simple int) -> series any
Parameters
conditionbool: A condition checked on every bar.sourceany: The value to read on the bar where condition was true; any type (float, int, bool, color, ...).occurrencesimple int: Which true bar, counting back: 0 is the most recent, 1 the one before it. A literal or an input; na when there were fewer.
Example
lastCrossPrice = ta.valuewhen(ta.crossover(close, ta.sma(close, 20)), close, 0)