ta.valuewhen
Read a series as it stood when a condition last held, or the nth time before.
ta.valuewhen(condition, source, occurrence)The value the source had when the condition was last true (or the nth previous time it was true).
Parameters
A series parameter takes a value on every bar. A constant parameter must be known before the first bar, such as a number or an input.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
condition | Series | bool | - | - | When to sample. |
source | Series | number | - | - | The series to sample. |
occurrence | Constant | number | 0 | 0 to 255 | 0 = the most recent occurrence, 1 = the one before it. |
Output
| Name | Type |
|---|---|
value | number |
Warm-up and missing values
- Warm-up
- 1 bar.
- Missing values
- na until the condition has been true
occurrence + 1times.
Example
ta.valuewhen(ta.crossover(close, ma), close, 0)cross = ta.crossover(close, ta.sma(close, 20))
plot(ta.valuewhen(cross, close, 0), "Close at cross")