Sidechair

matrix.add_row()

Browse the reference

Inserts an array as a new row of a matrix, at the end unless you give a position.

Try it in the editor

The array supplies the new row's items and must have as many items as the matrix has columns. Rows from the chosen position downward move one place. Pass row = matrix.rows(m) or leave it out to append.

On an empty matrix the array's length sets the number of columns, which is how a matrix is grown from nothing, one observation per row.

Syntax

Pine Script
matrix.add_row(id: any matrix type, row: series int (optional), array_id: any array type) -> void
matrix.add_row(row: series int (optional), array_id: any array type) -> void

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix that receives the new row. Its row count grows by one.
rowseries intthe end of the matrixIndex of the row. Counts from 0.
array_idany array typerequiredThe array whose items become the new row or column.

Returns

Nothing.

Example

Pine ScriptCollect a row per barOpen in editor
//@version=6
indicator("matrix.add_row: history", overlay = false)
var matrix<float> hist = matrix.new<float>()
matrix.add_row(hist, matrix.rows(hist), array.from(open, close))
plot(matrix.rows(hist), "Rows stored")

See also

Runs on Sidechair