latch
Keep a state on between an entry signal and an exit signal, such as a trend that is active.
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.
| Name | Kind | Type | Default | Range | Description |
|---|---|---|---|---|---|
set | Series | bool | - | - | The condition that turns the flag on. |
reset | Series | bool | - | - | The condition that turns the flag off. |
Output
| Name | Type |
|---|---|
value | bool |
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
latch(ta.crossover(close, ma), ta.crossunder(close, ma))ma = ta.sma(close, 20)
active = latch(ta.crossover(close, ma), ta.crossunder(close, ma))
plot(active ? 1 : 0, "Active")