Arrays are dynamic, with limits
Unlike Python lists, Pine arrays have a maximum size set when you create them:
var float[] prices = array.new_float(20) array.push(prices, close) array.shift(prices)
This keeps the last 20 closes. array.push appends to the end, array.shift removes from the front. When the array hits its max size, the oldest element is dropped automatically.
Common array operations
array.size(a), array.get(a, i), array.set(a, i, value), array.sum(a), array.avg(a), array.max(a), array.min(a), array.includes(a, v). The full reference is in the Pine v5 manual.
Why arrays matter in Pine
The vector model gives you all bars at once — but it doesn't give you a way to do something like "the highest high of the last 20 up-bars". For that you push the relevant values into an array and scan it.
Matrices for 2D work
array.new_matrix(rows, cols, initValue) gives you a 2D structure. Useful for portfolio-level indicators, correlation tables, and order-book approximations.
A worked example: rolling high of up-bars
var float[] upCloses = array.new_float(50)
if close > close[1]
array.push(upCloses, close)
if array.size(upCloses) > 50
array.shift(upCloses)
highestUpClose = array.max(upCloses)
plot(highestUpClose)
What to take from this
Arrays and matrices are escape hatches when Pine's vector model doesn't fit. For 90% of CFD indicators you won't need them — but when you do, they are how you keep the script fast instead of looping bar by bar.