Sidechair

matrix.is_antidiagonal()

Browse the reference

Returns true when every item off the anti-diagonal, from top right to bottom left, is zero.

Try it in the editor

The anti-diagonal runs from the top-right corner to the bottom-left corner. [[0, 5], [7, 0]] passes, [[0, 5], [7, 1]] fails because of the 1 at the bottom right, and the 3 by 3 grid [[0, 0, 1], [0, 2, 0], [3, 0, 0]] passes.

Items on the anti-diagonal may take any value; every other item must be 0. A square matrix is needed for that corner-to-corner line to be meaningful.

Syntax

Pine Script
matrix.is_antidiagonal(id: matrix<int/float>) -> series bool
matrix.is_antidiagonal() -> series bool

Arguments

NameTypeDefaultDescription
idmatrix<int/float>requiredThe matrix whose items outside the top-right to bottom-left diagonal are checked for zero.

Returns

  • series bool: true when every item off the anti-diagonal is zero, otherwise false.
  • series bool: true when the receiving matrix is anti-diagonal, otherwise false.

Example

Pine ScriptExchange matrixOpen in editor
//@version=6
indicator("matrix.is_antidiagonal: exchange", overlay = false)
matrix<float> m = matrix.new<float>(2, 2, 0.0)
matrix.set(m, 0, 1, 1.0)
matrix.set(m, 1, 0, 1.0)
plot(matrix.is_antidiagonal(m) ? 1 : 0, "Anti-diagonal")

See also

Runs on Sidechair