Skip to content
Algo Trade Analytics Docs

matrix.add_row() - Pine Script Function

Inserts a new row at the row index of the id matrix.

matrix.add_row(id, row, array_id) → void
NameTypeDescription
idany matrix typeThe matrix object’s ID (reference).
  • Indexing of rows and columns starts at zero. Rather than add rows to an empty matrix, it is far more efficient to declare a matrix with explicit dimensions and fill it with values.
//@version=6
indicator("`matrix.add_row()` Example 2")
if barstate.islastconfirmedhistory // Create an empty matrix object. var m = matrix.new<int>() // Create an array with values `1` and `2`. var a =
array.from(1, 2) // Add the `a` array as the first row of the empty matrix. matrix.add_row(m, 0, a) // Display matrix elements. var t =
table.new(position.top_right, 2, 2, color.green) table.cell(t, 0, 0, "Matrix elements:") table.cell(t, 0, 1, str.tostring(m))