keyed value types with pseudo-dict - Methods Library "key_vals"
a set of primitive single-type key/value items, and pseudo-dictionaries
The dictionaries are single arrays of items, each item has a key and value.
The library is 100% methods. add, remove, get and set items by key.
It provides methods to get all the keys, values or items in the dict as arrays.
For those familiar with python, it's similar, but typified.. and the brackets are round.
example syntax.. using floats, the same functions exist for Int, Bool and String
new float_item
new (‘demo’, 1.0 )
set the key of a float_item
float_item.key (‘demo’)
get the key of a float_item
float_item.key ()
set the value of a float_item
float_item.val (1.5)
get the value of a float_item
float_item.val ()
get the number of items in a dict
float_dict.count ()
set an item to a dict by key ( add / update)
float_dict.set ( ‘demo’, 2.0 )
remove an item from a dict by key (changes index, but this is about keys, not ids)
float_dict.remove ( ‘demo’ )
get an item from a dict array
array.get (1 )
get an item from a dict by key
float_dict.get ( ‘demo’ )
get an item from a dict by id (remember, ids change if removed by key) mainlyy an internal function
float_dict.get ( 1)
return all keys as string
float_dict.get_keys()
return all values as float
float_dict.get_values()
return all items as float
float_dict.get_items()
create a new float dict in the multi dict and return the index of it
multi_dict.add_float_dict()
get the float dict at index 0 from the multi dict
multi_dict.get_float_dict( 0)
set an item in a float dict in a multi dict
multi_dict.set_float( ‘demo’, 2.0 )
get an item from a float dict in a multi dict
multi_dict.get_float( ‘demo’ )
float_item
float_item
Fields:
key : (string)
val : (float)
next : (float_item)
float_dict
float_dict
Fields:
content
int_item
int_item
Fields:
key : (string)
val : (int)
next : (int_item)
int_dict
int_dict
Fields:
content
string_item
string_item
Fields:
key : (string)
val : (string)
next : (string_item)
string_dict
string_dict
Fields:
content
bool_item
bool_item
Fields:
key : (string)
val : (bool)
next : (bool_item)
bool_dict
bool_dict
Fields:
content
multi_dict
multi_dict
Fields:
f_dicts
f_registry
i_dicts
i_registry
s_dicts
s_registry
b_dicts
b_registry
new(key, val)
new
Parameters:
key : string
val : float
new(key, val)
Parameters:
key
val
new(key, val)
Parameters:
key
val
new(key, val)
Parameters:
key
val
key(this, key)
key
Parameters:
this : float_item
key : string
key(this)
key
Parameters:
this : float_item
key(this, key)
Parameters:
this
key
key(this)
Parameters:
this
key(this, key)
Parameters:
this
key
key(this)
Parameters:
this
key(this, key)
Parameters:
this
key
key(this)
Parameters:
this
val(this)
val
Parameters:
this : float_item
val(this, val)
val
Parameters:
this : float_item
val : float
val(this)
Parameters:
this
val(this, val)
Parameters:
this
val
val(this)
Parameters:
this
val(this, val)
Parameters:
this
val
val(this)
Parameters:
this
val(this, val)
Parameters:
this
val
count(dict)
count
Parameters:
dict : float_dict
count(dict)
Parameters:
dict
count(dict)
Parameters:
dict
count(dict)
Parameters:
dict
get(dict, index)
get
Parameters:
dict : float_dict
index : int
get(dict, index)
get
Parameters:
dict : float_dict
index : int
get(d, key)
Parameters:
d
key
get(dict, index)
Parameters:
dict
index
get(dict, index)
Parameters:
dict
index
get(d, key)
Parameters:
d
key
get(dict, index)
Parameters:
dict
index
get(dict, index)
Parameters:
dict
index
get(d, key)
Parameters:
d
key
get(dict, index)
Parameters:
dict
index
get(dict, index)
Parameters:
dict
index
get(d, key)
Parameters:
d
key
set(d, key, val)
set
Parameters:
d : float_dict
key : string
val : float
set(d, key, val)
Parameters:
d
key
val
set(d, key, val)
Parameters:
d
key
val
set(d, key, val)
Parameters:
d
key
val
get_keys(d)
Parameters:
d
get_keys(d)
Parameters:
d
get_keys(d)
Parameters:
d
get_keys(d)
Parameters:
d
get_values(d)
Parameters:
d
get_values(d)
Parameters:
d
get_values(d)
Parameters:
d
get_values(d)
Parameters:
d
get_items(d)
Parameters:
d
get_items(d)
Parameters:
d
get_items(d)
Parameters:
d
get_items(d)
Parameters:
d
remove(dict, key)
Parameters:
dict
key
remove(dict, key)
Parameters:
dict
key
remove(dict, key)
Parameters:
dict
key
remove(dict, key)
Parameters:
dict
key
create_multi_dict()
add_float_dict(this)
Parameters:
this
add_int_dict(this)
Parameters:
this
add_string_dict(this)
Parameters:
this
add_bool_dict(this)
Parameters:
this
get_float_dict(this, index)
Parameters:
this
index
get_float_dict(this, key)
Parameters:
this
key
get_int_dict(this, index)
Parameters:
this
index
get_int_dict(this, key)
Parameters:
this
key
get_string_dict(this, index)
Parameters:
this
index
get_string_dict(this, key)
Parameters:
this
key
get_bool_dict(this, index)
Parameters:
this
index
get_bool_dict(this, key)
Parameters:
this
key
set_float(this, key, val)
Parameters:
this
key
val
set_int(this, key, val)
Parameters:
this
key
val
set_string(this, key, val)
Parameters:
this
key
val
set_bool(this, key, val)
Parameters:
this
key
val
Datastorage
Data structure map[string, float]The script shows a workaround for map in pine-script via drawings.
There are few restrictions with them:
1. The size of the map cannot be more that amount of allowed drawings (about 40 by now)
2. Because the map shares the space of drawings throughout the whole script, using drawings with the map must be careful, with handly creating and removing of each drawing, because otherwise pine's garbage collector might break the stack. I'd recommend not using more drawings with the map.
3. setters and getters must be called on every bar, because of implementation of functions in pine there are inner serieses, which must be updated on every bar. So wherever you have a setter or getter in the code - it must be called on every bar. But if it's just an update, then you should pass 'false' as a param of the funtion.
The script shows a way to work with the map: filling it with some tickers and values for each of it and then plot the value if the symbol on the chart equals to one of the tickers in the map.
And there are some examples of updating of the value and removing of the item from the map.