columnsLibrary "columns"
Error Tolerant Matrix Setter/Getter Operations. Easy ways to add/remove items into start and end of Columns as well as arrays to grow and shrink matrix.
if mismatched sizes occur the typified NA value will be there to prevent catastrophic crashing.
Rows and Columns are split into 2 libraries due to limitations on number of exports as well as ease of style (columns.shift(), rows.pop() )
pop(_matrix)
do pop last Column off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of Last Column, removing it from matrix
shift(_matrix)
do shift the first Column off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of First Column, removing it from matrix
get(_matrix, _clmnNum)
retrieve specific Column of matrix
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
Returns: Array of selected Column number, leaving in place
push(_matrix, _clmnNum, _item)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_item : Item to Push on Column
Returns: shifted item from Column start
push(_matrix, _array)
add single item onto end of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to Push on Matrix
Returns: Void
unshift(_matrix, _clmnNum, _item)
slide single item into start of Column remove last
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_item : Item to Unshift on Column
Returns: popped item from Column end
unshift(_matrix, _array)
add single item into first Column of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift into Matrix
Returns: Void
set(_matrix, _clmnNum, _array)
replace an array to an existing Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_array : Array to place in Matrix
Returns: Column that was replaced
insert(_matrix, _clmnNum, _array)
insert an array to a new Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_array : Array to place in Matrix
Returns: void
slideDown(_matrix, _array)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_array : Array to push to Matrix
Returns: shifted first Column
slideUp(_matrix, _array)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift to Matrix
Returns: poppeed last Column
pullOut(_matrix, _clmnNum)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
Returns: removed selected Column
Datastructure
rowsLibrary "rows"
Error Tolerant Matrix Setter/Getter Operations. Easy ways to add/remove items into start and end of rows as well as arrays to grow and shrink matrix.
if mismatched sizes occur the typified NA value will be there to prevent catastrophic crashing.
columns and rows are split into 2 libraries due to limitations on number of exports as well as ease of style (columns.shift(), rows.pop() )
pop(_matrix)
do pop last row off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of Last row, removing it from matrix
shift(_matrix)
do shift the first row off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of First row, removing it from matrix
get(_matrix, _rowNum)
retrieve specific row of matrix
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
Returns: Array of selected row number, leaving in place
push(_matrix, _rowNum, _item)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_item : Item to Push on Row
Returns: shifted item from row start
push(_matrix, _array)
add single item onto end of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to Push on Matrix
Returns: Void
unshift(_matrix, _rowNum, _item)
slide single item into start of row remove last
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_item : Item to Unshift on Row
Returns: popped item from row end
unshift(_matrix, _array)
add single item into first row of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift into Matrix
Returns: Void
set(_matrix, _rowNum, _array)
replace an array to an existing row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_array : Array to place in Matrix
Returns: row that was replaced
insert(_matrix, _rowNum, _array)
insert an array to a new row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_array : Array to place in Matrix
Returns: void
slideDown(_matrix, _array)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_array : Array to push to Matrix
Returns: shifted first row
slideUp(_matrix, _array)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift to Matrix
Returns: popped last row
pullOut(_matrix, _rowNum)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
Returns: removed selected row
Simple HashmapA very simple Hashmap in Pinescript version 4
It uses two arrays one to store indices and one to store values
currently this only supports keys of type int and values of type floats.
index array: (20, 30, 80, 90)
value array: (9.1,8.1,6.5,3.5)
You can access the value 9.1 by using the key 20.
No fancy hash functions were used just a very simple practical mechanism.
Object: object oriented programming made possible! Hash map's in Pinescript?? Absolutely
This Library is the first step towards bringing a much needed data structure to the Pine Script community.
"Object" allows Pine coders to finally create objects full or unique key:value pairs, which are converted to strings and stored in an array. Data can be stored and accessed using dedicated get and set methods.
The workflow is simple, but has a few nuances:
0. Import this library into your project; you can give it whatever alias you'd like (I'll be using obj)
1. Create your first object using the obj.new() method and assign it a variable or "ID".
2. Use the object's ID as the first argument into the obj.set() method, for the key and value there's one extra step required. They must be added as arguments to the appropriate prop_() method.
Note: While objects in this library technically only store data as strings, any primitive data type can be converted to a string before being stored, meaning that one object can hold data from multiple types at once. There's a trade off though..Pine Script requires that all exported function parameters have pre-defined types, meaning that as convenient as it would be to have a single method for storing and returning data of every type, it's not currently possible. Instead there are functions to add properties for each individual type, which are then converted to strings automatically (the original type is flagged and stored along with the data). Furthermore, since switch/if statements can only return values of the same type, there must also be "get" methods which correspond with each type. Again, a single "get" method which auto-detects the returned value's type was the goal but it's just not currently possible. Instead each get method is only allowed to return a value of its own type. No worries though, all the "get" methods will throw errors if they can't access the data you're trying to access. In that error message, you'll be informed exactly which "get" method you need to use if you ever lose track of what type of data you should be returning.
3. The second argument for obj.set() method is the obj.prop_() method. You just plug in your key as a string and your value and you're done. Easy as that.
Please do not skip this step, properties must be formatted correctly for data to be stored and accessed correctly
4. Obj.get_ (s: string, f: float, b: bool, i: int) methods are even easier, just choose whichever method will return the data type you need, then plug in your ID, and key and that's it. Objects will output data of the same type they were stored as!
There's a short example at the end of the script if you'd like to see more!
prop_string(string: key, string: value)
returns property formatted to string and flagged as string type
prop_float(string: key, float: value)
returns property formatted to string and flagged as float type
prop_bool(string: key, bool: value)
returns property formatted to string and flagged as bool type
prop_int(string: key, int: value)
returns property formatted to string and flagged as int type
Support for lines and shapes coming soon!
new()
returns an empty object
set(string : ID, string: property)
adds new property to object
get_f(string : ID, string: key)
returns float values
get_s(string : ID, string: key)
returns string values
get_b(string : ID, string: key)
returns boolean values
get_i(string : ID, string: key)
returns int values
More methods like Obj.remove(), Obj.size(), Obj.fromString, Obj.fromArray, Obj.toJSON, Obj.keys, & Obj.values coming very soon!!