Skip to content
Algo Trade Analytics Docs

ta.valuewhen() - Pine Script Function

Returns the value of the source series on the bar where the condition was true on the nth most recent occurrence.

ta.valuewhen(condition, source, occurrence) → series color
NameTypeDescription
conditionseries boolThe condition to search for.
  • This function requires execution on every bar. It is not recommended to use it inside a for or while loop structure, where its behavior can be unexpected. Please note that using this function can cause indicator repainting.
//@version=6
indicator("ta.valuewhen")
slow = ta.sma(close, 7)fast = ta.sma(close, 14)// Get value of `close` on second most recent cross
plot(ta.valuewhen(ta.cross(slow, fast), close, 1))