Series and history
Every value has a past. Read it without looking ahead.
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.
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)wasis true if a condition was true at some point in recent bars.heldis true if it has been true for consecutive bars.crosses_above,crosses_belowandcrossesdetect crossings.startsandendsare true on the bar a condition becomes true or stops being true.bars_sincecounts bars since a condition was last true.- Reading further back than the data goes gives
na.nzsupplies 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)
- 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.