How Pine Script runs (every bar, every tick) · Pine Script EP 02 #shorts

How does a Pine Script actually run? You write it; TradingView’s servers run it (Pine is cloud-based) and your screen shows the result. On historical bars the script executes once per bar, from the first bar of the dataset to the last — 10,000 bars means 10,000 runs, and every run sees its own bar plus the history (close[1], close[2]…). On the live (realtime) bar it executes again on every price update: before each update its values roll back, and they are committed only when the bar closes. That is why a script can look different in history and live (barstate.isconfirmed / barstate.isrealtime).

The demo (the same 4 lines as EP 01):
//@version=6
indicator(“Demo · 20-bar average”, overlay = true)
avg = ta.sma(close, 20)
plot(avg)

Pine Script EP 02. Save it · Next: EP 03 — what is inside a script.

Educational example.

Your rules. Coded. · marketalgobot.com
https://marketalgobot.com

#pinescript #tradingview #coding #learntocode #marketalgobot