store - larger data storage for complex item typesLibrary "store"
Object/Property Storage System Semi-Simplified. .
It's a helpful toolset while designing UDT's as it remains flexible,
this helps in not having to remap an entire script while tinkering.
Set an object up, and add as man properties as yyou wish.
a property can be one of any pine built in types. so a single
object can contain sa, ohlc each with a color, a float, an assigned int
and those 4 props each have 3 sub-assigned values.
as in demo, the alternating table object has 2 different tables
it's a pseudo more complex wa to create our own flexible
version of a UDT, but that will not ~break~ on library updates
so you can update awa without fear, as this libb will no change
saving ou the hassle of creating UDT's that continually change.
set(dict, _object, _prop, _item)
Add/Updates item to storage. Autoselects subclass dictionary on set
Parameters:
dict : (dictionary) dict.type subdictionary (req for overload)
_object : (string) object name
_prop
_item : () item to set
Returns: item item wwith column/row
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _object, _prop, _item)
Parameters:
dict
_object
_prop
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
set(dict, _index, _item)
Parameters:
dict
_index
_item
get(typedict, _object, _prop)
Get item by object name and property (string)
Parameters:
typedict : (dict) dict.type subdictionary (req for overload)
_object : (string) object name
_prop
Returns: item from storage
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
get(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _object, _prop)
Remove a specific property from an object
Parameters:
typedict : (dict) dict.type subdictionary (req for overload)
_object : (string) object name
_prop
Returns: item from storage
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _object, _prop)
Parameters:
typedict
_object
_prop
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
remove(typedict, _index)
Parameters:
typedict
_index
delete(_dict, _object)
Remove a complete Object and all props
Parameters:
_dict
_object : (string) object name
Returns: item from storage
delete(_dict, _index)
Parameters:
_dict
_index
wipe(_dict, _object, _prop)
Remove Property slot for all 10 item types
Parameters:
_dict : (dictionary) The full dictionary item
_object : (string) object name
_prop
Returns: item from storage
wipe(_dict, _index)
Parameters:
_dict
_index
init(_Objlim, _Proplim)
Create New Dictionary ready to use (9999 size limit - (_objlim +_Proplim) for row/column 0)
# Full dictionary with all types
> start with this
Parameters:
_Objlim : (int) maximum objects (think horizontal)
_Proplim : (int) maximum properties per obj (vertical)
Returns: dictionary typoe object
boxdict
Fields:
keys
items
booldict
Fields:
keys
items
colordict
Fields:
keys
items
floatdict
Fields:
keys
items
intdict
Fields:
keys
items
labeldict
Fields:
keys
items
linedict
Fields:
keys
items
linefilldict
Fields:
keys
items
stringdict
Fields:
keys
items
tabledict
Fields:
keys
items
dictionary
Fields:
boxs
bools
colors
floats
ints
labels
lines
linefills
strings
tables
keys
item
Fields:
objCol
propRow
object
property
actionItem
dictionaries
Dictionar OF dictionaries
Fields:
dicts
[object
Motion▮ FEATURES
Now as library version :)
String-based transition-effects
Performance optimization. Reduced memory consumption up to >90% by kicking the output to the "stdout".
Use marquee- or loader-effect on any possible string location.
Example: UI Price-Ticker
----------------------------------------------------------------------------
Library "Motion"
_getStringMono(_len, _str, _sep)
Parameters:
_len
_str
_sep
marquee(this, _extern, _ws, _subLen, _subStart)
Parameters:
this
_extern
_ws
_subLen
_subStart
transition(this, _subLen, _subStart)
Parameters:
this
_subLen
_subStart
hold(this)
Parameters:
this
keyframe
keyframe A keyframe object.
Fields:
seq
intv
step
length
update_no
frame_no
ltr
hold
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!!
ObjectStackLibrary "ObjectStack"
init()
push()
push()
push()
push()
push()
nextIndex()
nextIndex()
nextIndex()
nextIndex()
nextIndex()
delete()
delete()
delete()
delete()
delete()
cleanOldest()
cleanOldest()
cleanOldest()
cleanOldest()
cleanOldest()
Dictionary/Object LibraryThis Library is aimed to mitigate the limitation of Pinescript having only one structured data type which is only arrays.
It lacks data types like Dictionaries(in Python) or Object (in JS) that are standard for other languages. Tuples do exist, but it hardly solves any problem.
Working only with Arrays could be overwhelming if your codebase is large. I looked for alternatives to arrays but couldn't find any library.
So I coded it myself and it's been working good for me. So I wanted to share it with you all.
What does it do:
==================
If you are familiar with Python or Javascript, this library tries to immimate Object/Dictonary like structure with Key Value Pairs.
For Example:
object= {name:"John Doe", age: 28 , org: "PineCoders"}
And then it also tries to immitate the Array of Objects (I call it Stack)
like this:
stack= Array({name:"John Doe", age: 28 , org: "PineCoders"},
{name:"Adam Smith", age: 32 , org: "PineCoders"},
{name:"Paragjyoti Deka", age: 25 , org: "PineCoders"})
So there are basically two ideas: Objects and Stacks.
But it looks whole different in Pinescript for obvious reasons.
Limitation:
The major limitation I couldn't overcome was that, for all of the values: both input and return values for properties will be of string type.
This is due to the limiation of Pinecsript that there is no way to return a value on a if-else statement dynamically with different data types.
And as the input data type must be explicitly defined when exporting the library functions, only string inputs are allowed.
Now that doesn't mean you won't be able to use integer, float or boolens, you just need to pass the string value for it using str.tostring() method.
And the output for the getter functions will be in strings as well. But I have added some type conversion methods that you could use from this library itself.
From String to Float, String To Integer and String to Boolean: these three methods are included in this library.
So basically the whole library is based on a manipulatiion of Array of strings under the hood.
///////////////
Usage
///////////////
Import the library using this statement:
import paragjyoti2012/STR_Dict_Lib/4 as DictLib
Objects
First define an object using this method:
for eample:
object1= DictLib.init("name=John,age=26,org=")
This is similar to
object1= {name:"John",age:"26", org:""} in JS or Python
Just like we did here in for "org", you can set initital value to "". But remember to pass string values, even for a numerical properties, like here in "age".
You can use "age="+str.tostring(age). If you find it tedious, you can always add properties later on using .set() method.
So it could also be initiated like this
object= DictLib.init("name=John")
and later on
DictLib.set(object1,"age", str.toString(age))
DictLib.set(object1,"org", "PineCoders")
The getter function looks like this
age= DictLib.get(object1,"age")
name=DictLib.get(object1,"name")
The first argument for all methods .get, .set, and .remove is the pointer (name of the object).
///////////////////////////
Array Of Objects (Stacks)
///////////////////////////
As I mentioned earlier, I call the array of objects as Stack.
Here's how to initialize a Stack.
stack= DictLib.initStack(object1)
The .initStack() method takes an object pointer as argument. It simply converts the array into a string and pushes it into the newly created stack.
Rest of all the methods for Stacks, takes the stack pointer as it's first arument.
For example:
DictLib.pushStack(stack,object2)
The second argument here is the object pointer. It adds the object to it's stack. Although it might feel like a two dimentional array, it's actually an one dimentional array with string values.
Under the hood, it looks like this
////////////////////
Methods
////////////////////
For Objects
-------------------
init() : Initializes the object.
params: (string) e.g
returns: The object ( )
example:
object1=DictLib.init("name=John,age=26,org=")
...................
get() : Returns the value for given property
params: (string object_pointer, string property)
returns: string
example:
age= DictLib.get(object1,"age")
.......................
set() : Adds a new property or updates an existing property
params: (string object_pointer, string property, string value)
returns: void
example:
DictLib.set(object1,"age", str.tostring(29))
........................
remove() : Removes a property from the object
params : (string object_pointer, string property)
returns: void
example:
DictLib.set(object1,"org")
........................
For Array Of Objects (Stacks)
-------------------------------
initStack() : Initializes the stack.
params: (string object_pointer) e.g
returns: The Stack
example:
stack= DictLib.initStack(object1)
...................
pushToStack() : Adds an object at at last index of the stack
params: (string stack_pointer, string object_pointer)
returns: void
example:
DictLib.pushToStack(stack,object2)
.......................
popFromStack() : Removes the last object from the stack
params: (string stack_pointer)
returns: void
example:
DictLib.popFromStack(stack)
.......................
insertToStack() : Adds an object at at the given index of the stack
params: (string stack_pointer, string object_pointer, int index)
returns: void
example:
DictLib.insertToStack(stack,object3,1)
.......................
removeFromStack() : Removes the object from the given index of the stack
params: (string stack_pointer, int index)
returns: void
example:
DictLib.removeFromStack(stack,2)
.......................
getElement () : Returns the value for given property from an object in the stack (index must be given)
params: (string stack_pointer, int index, string property)
returns: string
example:
ageFromObject1= DictLib.getElement(stack,0,"age")
.......................
setElement() : Updates an existing property of an object in the stack (index must be given)
params: (string stack_pointer, int index, string property, string value)
returns: void
example:
DictLib.setElement(stack,0,"age", str.tostring(32))
........................
includesElement() : Checks if any object exists in the stack with the given property-value pair
params : (string stack_pointer, string property, string value)
returns : Boolean
example:
doesExist= DictLib.includesElement(stack,"org","PineCoders")
........................
searchStack() : Search for a property-value pair in the stack and returns it's index
params: (stringp stack_pointer, string property, string value)
returns: int (-1 if doesn't exist)
example:
index= DictLib.searchElement(stack,"org","PineCoders")
///////////////////////
Type Conversion Methods
///////////////////////
strToFloat() : Converts String value to Float
params: (string value)
returns: float
example:
floatVal= DictLib.strToFloat("57.96")
.............................
strToInt() : Converts String value to Integer
params: (string value)
returns: int
example:
intVal= DictLib.strToFloat("45")
.............................
strToBool() : Converts String value to Boolean
params: (string value)
returns: boolean
example:
boolVal= DictLib.strToBool("true")
.............................
Points to remember
...............
1. Always pass string values as arguments.
2. The return values will be of type string, so convert them before to avoid typecasting conflict.
3. Horses can't vomit.
More Informations
====================
Yes, You can store this objects and stacks for persisting through the iterations of a script across successive bars.
You just need to set the variable using "var" keyword. Remember this objects and stacks are just arrays,
so any methods and properties an array have it pinescript, would be applicable for objects and stacks.
It can also be used in security functions without any issues for MTF Analysis.
If you have any suggestions or feedback, please comment on the thread, I would surely be happy to help.