# Variables and state

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

Source: https://algobarsx.com/docs/state/

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`.
