Representing Two-Dimensional Matrices with Pine Script Arrays
Summary
This document explains how to represent a two-dimensional matrix using Pine Script’s one-dimensional arrays. It stores row and column counts in the first two array elements, followed by row-major data, and provides functions to translate row and column coordinates into array positions. Rows are indexed from the most recent record, matching the author’s stated Pine Script convention.
The function set covers initialization, setting and retrieving individual values, extracting rows or the data body, coordinate conversion, and operations such as adding, removing, inserting, appending, or popping rows and columns. It also includes matrix-oriented operations such as transposition and multiplication, plus printing for inspection. The example describes a general data-structure utility rather than a trading method or empirical result. Its usefulness depends on careful dimension and index handling; the document does not provide performance benchmarks or establish suitability for any specific trading application.
Key ideas
- The matrix is stored in a flat array with row and column counts in a two-value header.
- Matrix elements are laid out row by row, with coordinate helpers mapping them to array indexes.
- The functions support reading, writing, inserting, removing, and appending rows or columns.
- The script includes additional matrix operations and a display helper for inspecting results.
- The document presents an implementation utility without trading evidence or performance evaluation.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.