This is a library to add matrix / 2D array functionality to Pinescript. once you import the library at the beginning of your script, you can add all the functions described below just by calling them like you do any other built'in function.
Enjoy, Gr, JD.
PS. if you find functionality or calculation errors in the functions, please let me know, so I can fix them. There are quite a lot of functions, so little mishaps may have slipped in! ;-)
get_nr_of_rows() Returns the number of rows from a 2D matrix
get_nr_of_columns() Returns the number of columns from a 2D matrix
get_size() Returns a tuple with the total number of rows and columns from a 2D matrix
init() 2D matrix init function, builds a 2D matrix with dimensional metadata in first two values and fills it with a default value, the body of the actual matrix data starts at index 2.
from_list() 2D matrix init function, builds a 2D matrix from an existing array by adding dimensional metadata in first two values, the body of the actual matrix data consists of the data of the source array and starts at index 2.
set() Sets values in 2D matrix with (row index, column index) (index for rows and columns both starts at 0 !!)
fill_val() Fills all elements in a 2D matrix with a value
randomize() Fills a 2D matrix with random values//
get() Gets values from 2D matrix with (row index, column index) (index for rows and columns both starts at 0 !!)
copy_slice_body() Cuts off the metadata header and returns the array body, WITHOUT THE DIMENSIONAL METADATA!! do_slice This variable should be set as: - 'false' to only make a copy, changes to the new array copy will NOT ALTER the ORIGINAL - 'true' to make a slice, changes to the new array slice WILL(!) ALTER the ORIGINAL
get_record() Gets /retrieve the values from a ROW/RECORD from a certain row/lookback period, the values are returned as an array
get_row_index() Gets the row nr. in a 2D matrix from 1D index (index for rows and columns both starts at 0 !!)
get_column_index() Gets the column nr. in a 2D matrix from 1D index (index for rows and columns both starts at 0 !!)
get_row_column_index() Gets a tuple with the (row, column) coordinates in 2D matrix from 1D index (index starts at 0 and does not include the header!!)
get_array_index() Gets the 1D index from (row, column) coordinates in 2D matrix (index for row and column both starts at 0 !! Index starts at 0 and does not include the header!!)
remove_rows() Removes one or more rows/records from a 2D matrix (if from_row = to_row, only this row is removed)
remove_columns() Remove one or more columns from a 2D matrix (if from_column = to_column, only this column is removed)
insert_array_of_rows() Insert an array of rows/records at a certain row number in a 2D matrix
add_row() ADDS a ROW/RECORD on the TOP of a sheet, shift the whole list one down and gives the option to REMOVE the OLDEST row/record. (2D version of "unshift" + "pop" but with a whole row at once)
insert_array_of_columns() Insert an array of columns at a certain column number in a 2D matrix
append_array_of_rows() Appends/adds an array of rows/records to the bottom of a 2D matrix
append_array_of_columns() Appends/adds an array of columns to the right side of a 2D matrix
pop_row() Removes / pops and returns the last row/record from a 2D matrix.
pop_column() Removes / pops and returns the last (most right) column from a 2D matrix.
replace()
abs()
add_value() Returns a new matrix with the same value added to all the elements of the source matrix.
addition() Returns a new matrix with the of the elements of one 2D matrix added to every corresponding element of a source 2D matrix.
subtract_value() Returns a new matrix with the same value subtracted from every element of a 2D matrix
subtraction() Returns a new matrix with the values of the elements of one 2D matrix subtracted from every corresponding element of a source 2D matrix.
scalar_multipy() Returns a new matrix with all the elements of the source matrix scaled/multiplied by a scalar value.
transpose() Returns a new matrix with the elements of the source matrix transposed.
multiply_elem() Performs ELEMENT WISE MULTIPLICATION of 2D matrices, returns a new matrix c.
multiply() Performs DOT PROCUCT MULTIPLICATION of 2D matrices, returns a new matrix c.
determinant_2x2() Calculates the determinant of 2x2 matrices.
determinant_3x3() Calculates the determinant of 3x3 matrices.
determinant_4x4() Calculates the determinant of 4x4 matrices.
Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai satu perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman.
Disclaimer. I AM NOT A FINANCIAL ADVISOR. THESE IDEAS ARE NOT ADVICE AND ARE FOR EDUCATION PURPOSES ONLY. ALWAYS DO YOUR OWN RESEARCH! JD.
You can contact me for info/access in PM or on Telegram: @jduyck PLS, DON'T ASK FOR ACCESS IN THE COMMENT SECTION!
Juga pada:
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.