ta.valuewhen()
Value When
Returns the value of the source series on the bar where the condition was true.
Syntax
ta.valuewhen(condition, source, occurrence) → series floatArguments
| Parameter | Type | Description |
|---|---|---|
| condition | series bool | Condition that marks relevant bars. |
| source | series int/float | Series value to recall when condition is true. |
| occurrence | simple int | Which 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
//@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
Related Functions
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.
Related Pine Script Functions
ta.barssince() - Bars Since
Learn how to use ta.barssince() in Pine Script. Count bars since a condition was last true.
ta.highest() - Highest Value
Learn how to use ta.highest() in Pine Script. Find the highest value over a lookback period for Donchian Channels.
ta.lowest() - Lowest Value
Learn how to use ta.lowest() in Pine Script. Find the lowest value over a lookback period.
ta.lowestbars() - Lowest Bars Offset
Learn how to use ta.lowestbars() in Pine Script. Find how many bars ago the lowest value occurred.