ta.valuewhen() - Pine Script Function
ta.valuewhen()
Section titled “ta.valuewhen()”Overview
Section titled “Overview”Returns the value of the source series on the bar where the condition was true on the nth most recent occurrence.
Syntax
Section titled “Syntax”ta.valuewhen(condition, source, occurrence) → series colorParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| condition | series bool | The condition to search for. |
Remarks
Section titled “Remarks”- 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.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("ta.valuewhen")slow = ta.sma(close, 7)fast = ta.sma(close, 14)// Get value of `close` on second most recent crossplot(ta.valuewhen(ta.cross(slow, fast), close, 1))