close, high, bar_index and the other built-in
series hold the values of that one bar; the script cannot see later bars.
What a variable is on each bar
A variable you declare with= is created again on every bar, so it starts from its initial value each time. Earlier values stay
reachable through the history operator (x[1], see Referencing previous bars). To
carry a value from one bar to the next, declare it static (see Values that persist across bars).
fresh is 1 on every bar; kept is 1, 2, 3, …
Order inside a run
Statements run top to bottom. A function runs when it is called, and a block only when its condition holds on that bar. A top-levelplot is evaluated on every bar and draws nothing where its value is na.
History, then the live bar
Each historical bar runs once. The newest bar of a live chart is still forming, so it runs again on every price tick (see Recalculation and confirmation). The first bars givena for anything that needs earlier
bars, such as a 20-bar average on bar 5.