Sidechair

matrix.remove_row()

Browse the reference

Deletes a row from a matrix and returns it as an array.

Try it in the editor

The rows below move up. Without a row index the last row is removed. A row index outside the matrix stops the script with an error.

The removed items come back as an array, so a queue of observations can drop its oldest row with matrix.remove_row(m, 0).

Syntax

Pine Script
matrix.remove_row(id: any matrix type, row: series int (optional)) -> array<>
matrix.remove_row(row: series int (optional)) -> array<>

Arguments

NameTypeDefaultDescription
idany matrix typerequiredThe matrix to take a row out of. Its row count drops by one.
rowseries intthe last rowIndex of the row. Counts from 0.

Returns

array<>: An array holding the removed row.

Example

Pine ScriptKeep 10 rowsOpen in editor
//@version=6
indicator("matrix.remove_row: rolling rows", overlay = false)
var matrix<float> hist = matrix.new<float>()
matrix.add_row(hist, matrix.rows(hist), array.from(close, volume))
if matrix.rows(hist) > 10
    matrix.remove_row(hist, 0)
plot(matrix.rows(hist), "Rows kept")

See also

Runs on Sidechair