Skip to content
Algo Trade Analytics Docs

matrix.sum() - Pine Script Function

The function returns a new matrix resulting from the sum of two matrices id1 and id2, or of an id1 matrix and an id2 scalar (a numerical value).

matrix.sum(id1, id2) → matrix<int>
NameTypeDescription
id1matrixFirst matrix object.

A new matrix object containing the sum of id2 and id1.

//@version=6
indicator("`matrix.sum()` Example 2")// For efficiency, execute this code only once.
if barstate.islastconfirmedhistory // Create a 2x3 matrix with values `4`.
var m1 = matrix.new<float>(2, 3, 4) // Create a new matrix containing the sum of the `m1` matrix with the "int" value `1`.
var m2 = matrix.sum(m1, 1) // Display using a table.
var t = table.new(position.top_right, 1, 2, color.green)
table.cell(t, 0, 0, "Sum of a matrix and a scalar:")
table.cell(t, 0, 1, str.tostring(m2))