//////////////////////////////////////////////////////////////// //////////////// ma sorter / Array sorting function ////////////////// ////////////////////////////////////////////////////////////////
This script gives an example how you can sort the items in one array, by using the values in another array.
In the example here, we want to sort moving averages of different lengths by there values as we don't have mixed arrays (yet) in Pinescript, one solution could be to store this in 2 arrays:
- one (string) array to store the ma names - one (float) array to store the ma values
The "f_sort_by_array( )" function in this script allows you to sort the ma names by using the ma values and sorts the two arrays together, as if the were one 2D matrix, where the rows are sorted.
With the "f_sort_by_array" function, both the (string) array1 and array2 are sorted by the values of array2, the function returns the two sorted arrays.
IMPORTANT NOTE: the output has to be stored in TWO NEW (sorted) ARRAYS, Pinescript doesn't allow function arguments to be modified by the function itself this is why the output goes to ma_names_sorted and not ma_names !!!!
Feel free to use this function in your scripts to get more contorl over your arrays.
Gr, JD.
סקריפט קוד פתוח
ברוח TradingView אמיתית, היוצר של הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יכולים לבדוק ולאמת את הפונקציונליות שלו. כל הכבוד למחבר! למרות שאתה יכול להשתמש בו בחינם, זכור שפרסום מחדש של הקוד כפוף לכללי הבית שלנו.
לגישה מהירה לגרף, הוסף את הסקריפט הזה למועדפים שלך - למד עוד כאן.
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.
ברוח TradingView אמיתית, היוצר של הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יכולים לבדוק ולאמת את הפונקציונליות שלו. כל הכבוד למחבר! למרות שאתה יכול להשתמש בו בחינם, זכור שפרסום מחדש של הקוד כפוף לכללי הבית שלנו.
לגישה מהירה לגרף, הוסף את הסקריפט הזה למועדפים שלך - למד עוד כאן.
Disclaimer. I AM NOT A FINANCIAL ADVISOR. THESE IDEAS ARE NOT ADVICE AND ARE FOR EDUCATION PURPOSES ONLY. ALWAYS DO YOUR OWN RESEARCH! JD.
You can contact me for info/access in PM or on Telegram: @jduyck PLS, DON'T ASK FOR ACCESS IN THE COMMENT SECTION!
גם על:
כתב ויתור
המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.