Docs

latch

Keep a state on between an entry signal and an exit signal, such as a trend that is active.

itm
latch(set, reset)

A flag that turns on at a bar where set is true and stays on until a bar where reset is true. When both are true on the same bar the flag is off. An na input counts as false.

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.

NameKindTypeDefaultRangeDescription
setSeriesbool--The condition that turns the flag on.
resetSeriesbool--The condition that turns the flag off.

Output

NameType
valuebool

Warm-up and missing values

Warm-up
1 bar.
Missing values
false until a bar where set is true. An na input reads as false. When both inputs are true on one bar, reset wins.

Example

itm
latch(ta.crossover(close, ma), ta.crossunder(close, ma))
itm
ma = ta.sma(close, 20)
active = latch(ta.crossover(close, ma), ta.crossunder(close, ma))
plot(active ? 1 : 0, "Active")