Returns how many rows a matrix has right now, which is also one more than the index of its last row.
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
matrix.rows(id: any matrix type) -> series int
matrix.rows() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any matrix type | required | The matrix to count rows in. |
Returns
series int: The row count.
Example
//@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