Sidechair

matrix.rows()

Browse the reference

Returns how many rows a matrix has right now, which is also one more than the index of its last row.

Try it in the editor

matrix.rows(id) returns the current height of a matrix. matrix.new<float>(3, 4) has 3 rows, and each matrix.add_row or matrix.remove_row call changes the count by one.

The newest row has index matrix.rows(id) - 1, so that value is what matrix.row takes to fetch it. An empty matrix returns 0. A for loop bounded by rows minus 1 then counts down from 0 to -1 instead of being skipped, so test for more than 0 rows first.

Syntax

Pine Script
matrix.rows(id: any matrix type) -> series int
matrix.rows() -> series int

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to count rows in.

Returns

series int: The row count.

Example

Pine ScriptRead the newest rowOpen in editor
//@version=6
indicator("matrix.rows: newest row", overlay = false)
var matrix<float> hist = matrix.new<float>()
matrix.add_row(hist, matrix.rows(hist), array.from(open, close))
newest = matrix.row(hist, matrix.rows(hist) - 1)
plot(array.get(newest, 1), "Newest close")

See also

Runs on Sidechair