# Series and history

> Every value has a past. Read it without looking ahead.

Source: https://algobarsx.com/docs/series-and-history/

`close` is not one number. It is a series with a value on every bar. Square brackets read earlier bars: `close[1]` is the previous bar's close. A value at a bar never depends on a later bar, and the test suite proves it by rewriting the future and checking the past did not move.

```algobarsx
prev_close = close[1]
range_high = highest(high, 20)[1]
rising = close > close[1] and close[1] > close[2]
recent = was(rsi(close, 14) < 30, within: 5 bars)
steady = held(close > ema(close, 50), for: 3 bars)
since_cross = bars_since(crosses_above(close, ema(close, 50)))
safe = nz(close[500], close)
```

- [`was`](https://algobarsx.com/docs/ref-fn-conditions/#ref-was) is true if a condition was true at some point in recent bars. [`held`](https://algobarsx.com/docs/ref-fn-conditions/#ref-held) is true if it has been true for consecutive bars.
- [`crosses_above`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses-above), [`crosses_below`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses-below) and [`crosses`](https://algobarsx.com/docs/ref-fn-conditions/#ref-crosses) detect crossings. [`starts`](https://algobarsx.com/docs/ref-fn-conditions/#ref-starts) and [`ends`](https://algobarsx.com/docs/ref-fn-conditions/#ref-ends) are true on the bar a condition becomes true or stops being true.
- [`bars_since`](https://algobarsx.com/docs/ref-fn-conditions/#ref-bars-since) counts bars since a condition was last true.
- Reading further back than the data goes gives `na`. [`nz`](https://algobarsx.com/docs/ref-fn-missing-values/#ref-nz) supplies a fallback.
- Reading forward is an error, not a bug waiting to happen: *“close[-1] would read a future bar. History counts back from the current bar: close[1] is the previous bar.”* ([AS0203](https://algobarsx.com/docs/diag-names-and-types/#AS0203))
- Indicator calls update on every bar, even when their line sits in a branch that did not run, so a reading is never stale.

Built-in price series: `open high low close volume time hl2 hlc3 ohlc4`, plus facts about the bar such as `bar.index`, `bar.confirmed` and `bar.range`. See [Bar variables](https://algobarsx.com/docs/ref-var-bars/).
