Skip to content
Algo Trade Analytics Docs

matrix.median() - Pine Script Function

The function calculates the median (“the middle” value) of matrix elements.

matrix.median(id) → series float
NameTypeDescription
idmatrix<int/float>A matrix object.
  • Note that na elements of the matrix are not considered when calculating the median.
//@version=6
indicator("`matrix.median()` Example")// Create a 2x2 matrix.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 median of the matrix.x = matrix.median(m)
plot(x, 'Median of the matrix')