Variables and state

Values recalculated each bar, and values that survive between bars.

A plain assignment such as trend_up = close > ema(close, 50) is worked out again on every bar. A state value is set once and keeps whatever you last put in it, which is how you count things or remember a price.

AlgoBarsX
state triggers = 0
state last_entry: price = na
when close > open:
triggers += 1
last_entry = close
on day change:
triggers = 0

You can annotate a type when the default does not say enough: state last_entry: price = na.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account