datastructuresLibrary "datastructures"
Collection of complex data structures not generally present as part of pinescript and can be used for collection and transformation of the data
method init(this)
initialise StringSet
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet to be initialised
Returns: current object of StringSet
method add(this, value)
add value to StringSet
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
@value the key of stringset to be set
value (string)
Returns: current object of StringSet
method clear(this)
clear StringSet contents
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
Returns: current object of StringSet
method remove(this, value)
remove value from StringSet
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
@value the key of stringset to be removed
value (string)
Returns: current object of StringSet
method size(this)
get size of the StringSet
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
Returns: size of StringSet map
method isEmpty(this)
check if stringset is empty
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
Returns: true if empty else returns false
method iterator(this)
get values of the StringSet
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
Returns: values of StringSet
method contains(this, value)
check if value is present in StringSet
Namespace types: StringSet
Parameters:
this (StringSet) : StringSet object
value (string)
Returns: true if Value is present. False otherwise
method initialiseCountMap(types, numberOfStates)
Initialise a new map of string to Count
Namespace types: array
Parameters:
types (array) : array of string containing map keys
numberOfStates (int) : number of items to be tracked for each type
Returns: new map() with empty initialisation
method initialiseCountMap(types, numberOfStates)
Initialise a new map of string to Count
Namespace types: map
Parameters:
types (map) : map containing types and configurable boolean flag
numberOfStates (int) : number of items to be tracked for each type
Returns: new map() with empty initialisation
method get(this, key, n)
get count based on primary string key and secondary int key
Namespace types: map
Parameters:
this (map) : map of string to to Count
key (string) : primary key
n (int) : secondary key
Returns: derived count from map of map
method get(this, key, n)
get array of int associated with key and n
Namespace types: map
Parameters:
this (map) : map of string to to MapToInts
key (string) : primary string key
n (int) : secondary int key
Returns: derived array of int for the given key combination
method get(this, key, n)
get array of float associated with key and n
Namespace types: map
Parameters:
this (map) : map of string to to MapToFloats
key (string) : primary string key
n (int) : secondary int key
Returns: derived array of float
method get(this, key)
get values of Ints based on key
Namespace types: map
Parameters:
this (map) : map of string to Ints
key (string) : string key
Returns: values inside Ints object associated in the map
method set(this, key, n, value)
set count for specific primary and secondary key
Namespace types: map
Parameters:
this (map) : map of string to to Count
key (string) : primary string key
n (int) : secondary int key
value (int) : the new count value to be set
Returns: updated value for key and n
method increment(this, key, n)
increment count for specific primary and secondary key
Namespace types: map
Parameters:
this (map) : map of string to to Count
key (string) : primary string key
n (int) : secondary int key
Returns: incremented value
method increment(this, key, n)
intcrement the value of Ints based on key and n (secondary key)
Namespace types: map
Parameters:
this (map) : map of string to Ints
key (string) : string key
n (int) : secondary int key
Returns: incremented nth object of Ints associated with key
method initialiseIntsMap(types, numberOfStates)
Initialise a new map of string to Map to Ints
Namespace types: array
Parameters:
types (array) : array of string containing map keys
numberOfStates (int) : number of items to be tracked for each type
Returns: new map() with empty initialisation
method initialiseIntsMap(types, numberOfStates)
Initialise a new map of string to Map to Ints
Namespace types: map
Parameters:
types (map) : map with boolean flag
numberOfStates (int) : number of items to be tracked for each type
Returns: new map() with empty initialisation
method initialiseFloatsMap(types, numberOfStates)
Initialise a new map of string to Map to Floats
Namespace types: array
Parameters:
types (array) : array of string containing map keys
numberOfStates (int) : number of items to be tracked for each type
Returns: new map() with empty initialisation
method initialiseFloatsMap(types, numberOfStates)
Initialise a new map of string to Map to Floats
Namespace types: map
Parameters:
types (map) : map with boolean flag
numberOfStates (int) : number of items to be tracked for each type
Returns: new map() with empty initialisation
method initialiseMapOfInts(types, numberOfStates)
Initialise map of two dimentional Ints based on types and number of states
Namespace types: array
Parameters:
types (array) : types array for which a new Map to Ints to be created
numberOfStates (int) : number of states for which the Ints needs to be initialised
Returns: new map of string to two dimension array of int (Ints)
method initialiseMapOfInts(types, numberOfStates)
Initialise map of two dimentional Ints based on types and number of states
Namespace types: map
Parameters:
types (map) : types map for which a new Map to Ints to be created along with bool flag
numberOfStates (int) : number of states for which the Ints needs to be initialised
Returns: new map of string to two dimension array of int (Ints)
StringSet
Set implementation using map
Fields:
strSet (map) : map of string to bool
Count
type containing map of int to int
Fields:
count (map) : map of int to int used for counting
Ints
custom type to enable array of array of int
Fields:
values (array) : int array
Floats
custom type to enable array of array of float
Fields:
values (array) : float array
MapToInts
type containing map of int to int array
Fields:
vmap (map) : map of int to Ints used as counting collection
MapToFloats
type containing map of int to float array
Fields:
vmap (map) : map of int to Floats used as floating stat collection
Datastructure
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
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
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!!