matrix.sum() - Pine Script Function
matrix.sum()
Section titled “matrix.sum()”Overview
Section titled “Overview”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).
Syntax
Section titled “Syntax”matrix.sum(id1, id2) → matrix<int>Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id1 | matrix | First matrix object. |
Returns
Section titled “Returns”A new matrix object containing the sum of id2 and id1.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`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))