sabricat

[-_-] Dictionary

The script shows an example implementation of dictionary-like data type which can store key:value pairs (Python style). Both keys and values can have any of the following type:
• string
• integer
• float
• boolean
• color

You can add items of different types to the same dictionary (e.g. key = 12 and value = "value" stored in the same dictionary with key = "key" and value = 0.23).

Under the hood dictionary is a custom Object (see www.tradingview.com/...anguage/Objects.html), that has two array<string> fields (one for storing keys, another for storing values). Keys and values of different types are converted into a string representation when adding a new item to the dictionary. The value is then converted back to certain type (bool/color/etc.) from that string representation when being retrieved. Script also utilises the new Methods (see www.tradingview.com/...anguage/Methods.html).

The following methods are implemented:
• init() -> initialises the array<string> fields of dictionary (without this the script throws an error "Array methods can't be called when ID of array is na"
• set(key, value) -> add a new item to dictionary; if an item for given key already exists - change it to new value
• getS(key) -> get value of string type
• getI(key) -> get value of integer type
• getF(key) -> get value of float type
• getB(key) -> get value of boolean type
• getC(key) -> get value of color type
• remove(key) -> removes item from dictionary
• len() -> get length of dictionary (the number of keys)

I could not make just one "get" function that returns any type of value (color/string/etc.), so instead I created a get function for each value type. Example usage:
• you add a string item: dictionary.set(2, "string here")
• you add a float item: dictionary.set(3, 24.56)
• to retrieve first value (key=2) do this: dictionary.getS(2)
• to retrieve second value (key=3) do this: dictionary.getF(3)
סקריפט קוד פתוח

ברוח TradingView אמיתית, מחבר הסקריפט הזה פרסם אותו בקוד פתוח, כך שסוחרים יכולים להבין ולאמת אותו. כל הכבוד למחבר! אתה יכול להשתמש בו בחינם, אך שימוש חוזר בקוד זה בפרסום כפוף לכללי הבית. אתה יכול להכניס אותו למועדפים כדי להשתמש בו בגרף.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בסקריפ זה בגרף?