matrix.avg() - Pine Script Function
matrix.avg()
Section titled “matrix.avg()”Overview
Section titled “Overview”The function calculates the average of all elements in the matrix.
Syntax
Section titled “Syntax”matrix.avg(id) → series floatParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
| id | matrix<int/float> | A matrix object. |
Returns
Section titled “Returns”The average value from the id matrix.
Examples
Section titled “Examples”Example 1
Section titled “Example 1”//@version=6indicator("`matrix.avg()` Example")// Create a 2x2 matrix.var m = matrix.new<int>(2, 2, na)// Fill the matrix with values.matrix.set(m, 0, 0, 1)matrix.set(m, 0, 1, 2)matrix.set(m, 1, 0, 3)matrix.set(m, 1, 1, 4)// Get the average value of the matrix.var x = matrix.avg(m)plot(x, 'Matrix average value')