UtilityPine Script v6

ta.valuewhen()

Value When

Returns the value of the source series on the bar where the condition was true.

Syntax

Syntax
ta.valuewhen(condition, source, occurrence) → series float

Arguments

ParameterTypeDescription
conditionseries boolCondition that marks relevant bars.
sourceseries int/floatSeries value to recall when condition is true.
occurrencesimple intWhich occurrence of the condition (0 = most recent).

Returns

The value of source when condition was true.

Remarks

This function can cause indicator repainting.

Code Examples

Pine Script v6 Example
//@version=6
indicator("ta.valuewhen")
slow = ta.sma(close, 7)
fast = ta.sma(close, 14)
plot(ta.valuewhen(ta.cross(slow, fast), close, 0))

Trading Applications

Get the price at the last crossover point

Reference historical signal values

Build pattern recognition based on past conditions

Create dynamic support/resistance from past events

Frequently Asked Questions

Generate ta.valuewhen() Code with AI

Skip the manual coding. Use Pineify's AI Coding Agent to generate Pine Script code using ta.valuewhen() and other built-in functions instantly.