valuewhen
Remember source from the last bar where condition was true.
Reference/Math & comparisons/Function
valuewhen(condition, source)
Holds that value on later bars until the condition fires again. Use it to keep a signal candle's high, then wait for a later bar to break it. Optional third argument is occurrence (0 = most recent).
Parameters
| Name | Type | Description |
|---|---|---|
condition | boolean | Usually a cross, for example close crosses above st. |
source | series | Usually high or low of that bar. |
occurrenceoptional | int default 0 | 0 is the latest match. |
Return value
series
For developers
- Pine ta.valuewhen.
Example
flipUp = close crosses above supertrend() signalHigh = valuewhen(flipUp, high) when high crosses above signalHigh and barssince(flipUp) > 0 then buy