talib.valuewhen

Reads source from the bar on which condition was true, going back as far as occurrence says. occurrence is a simple int, not a series, so it is fixed for the run of the script and cannot be varied bar by bar.

talib.valuewhen(series bool condition, series float source, simple int occurrence) → series float
ParameterTypeRequiredDescription
conditionseries boolyesThe test that selects which bar to read from.
sourceseries floatyesThe series whose value is read.
occurrencesimple intyesWhich past occurrence to use. A simple int, so it cannot change from bar to bar.

Returns series float — A series float: the value taken from the selected bar.

indicator("Close at the start of the session")
plot(talib.valuewhen(session.isfirst, close, 1))

See also talib.alma · talib.atr · talib.barssince

Part of the function index.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade