Home/Dovee/Function reference

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

NameTypeDescription
conditionbooleanUsually a cross, for example close crosses above st.
sourceseriesUsually high or low of that bar.
occurrenceoptionalint
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

See also