LibraryPrivateUsage001This is a public library that include the functions explained below. The libraries are considered public domain code and permission is not required from the author if you reuse these functions in your open-source scripts
Array
Gann Angle Table Calculator PlotterThis indicator was build upon based on Gann Angle and Gann Multiplier as refered of The Tunnel Thru The Air Or Looking Back From 1940, written by WD Gann .
Credits to FaizHebat for calculation.
Indicator features :
1. Font size from tiny to huge.
2. Table position.
3. Color for cell table and plot can be input or reversed.
4. Plot can be show or hide and also price can be track.
5. Able show currency and decimal price.
6. Gann table and Calculation table can show or hide.
7. Each Gann point can be hide including plot and calculation.
8. For desktop display only, not for mobile.
Pros :
1. Can be used as single or more indicator. (Chart show 2 same indicator with different setup)
Cons :
1. Price must be input before selecting any Gann Point.
FAQ
1. Credits
WD Gann , The Tunnel Thru The Air Or Looking Back From 1940
FaizHebat
2. Code Usage
Free to use for personal usage.
Positive direction with Currency and Decimal
Positive direction with Currency and Decimal
Volume Profile Auto [line]This project is about:
- VPSV
- array.new_line()
- array.new_box()
VPSV (pine) is one of the rare features that draws lines/figures BETWEEN bars
It doesn't run on Pine script, which makes it possible to do such things.
I wanted to have something similar while a restriction of Pine script is the impossibility to draw between bars, the only way I could think of is by using line width
In this script the higher timeframe is started with several lines (left) and a box, this box goes further until the higher timeframe ends.
During the creation of the box, each candle (lower timeframe) in this box (higher timeframe - period) is checked for position and volume, the volume is added to the left line, so when you see a thicker line, this means at that level there is more volume traded.
One of the big differences with other volume profiles is that many look back to a previous period, here when a period starts, the lines collect data - volume until the period ends, it is especially very visible in very low TF's (seconds)
This is my first script with array.new_line() - array.new_box(), which is a very nice Pine feature!
I hope this script can be helpful to see the possibilities
Settings:
'Parts' -> amount of lines (left of box)
5 Parts:
15 Parts:
25 Parts:
50 Parts:
'Max Width' -> Sets the max width of the lines
'Automatic Settings' -> Sets the higher time frame automatically, see the tooltip ⓘ for more info
The yellow line is the max volume line of that period, last period has a red line (POC), also referring the max.
Cheers!
[CLX][#03] Object-Stack (Labels/Lines/Boxes)This script shows an example of how to manage objects (lines/labels/boxes) and prevent the need of garbage collecting and missing objects.
You only have to push your object into the right array.
*_FIXED (left-lock) or *_FORWARD (right-lock)
We hope you enjoy it! 🎉
CRYPTOLINX - jango_blockchained 😊👍
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely.
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold cryptolinx TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script.
Harmonic Trading Ratios Educational (Source Code)This table indicator was intended as educational purpose only for Harmonic Trading Ratios.
The ratios are used for Harmonic AB=CD and XAB=CD.
Ratio calculation are shown for Retracement and Projection based Primary, Primary Derived, Secondary Derived and Secondary Derived Extreme.
Primary Retracement : 0.618
Primary Projection : 1.618
Please take note that Secondary Derived Extreme is only available for Projection.
Indikator berjadual bertujuan sebagai pendidikan sahaja untuk Harmonic Trading Ratios.
Ratio digunakan untuk Harmonic AB=CD and XAB=CD.
Pengiraan ratio untuk Retracement and Projection adalah berdasarkan Primary, Primary Derived, Secondary Derived dan Secondary Derived Extreme.
Primary Retracement : 0.618
Primary Projection : 1.618
Sila ambil perhatian bahawa Secondary Derived Extreme adalah untuk Projection sahaja.
The values shown in table was based on Harmonic Trading: Volume One, Page 18 written by Scott M Carney.
Nilai yang ditunjukkan dalam jadual adalah berdasarkan buku Harmonic Trading: Volume One, Page 18 ditulis oleh Scott M Carney.
Indicator features :
1. List Harmonic Trading Ratios including calculation.
2. Show and draw individual Harmonic Trading Ratio.
3. For desktop display only, not for mobile.
Kemampuan indikator :
1. Senarai Harmonic Trading Ratios termasuk pengiraan.
2. Memapar dan melukis Harmonic Trading Ratio secara berasingan.
3. Untuk paparan desktop sahaja, bukan untuk mobile.
FAQ
1. Credits / Kredit
Scott M Carney,
Scott M Carney, Harmonic Trading: Volume One
2. Code Usage / Penggunaan Kod
Free to use for personal usage but credits are most welcomed especially for credits to Scott M Carney.
Bebas untuk kegunaan peribadi tetapi kredit adalah amat dialu-alukan terutamanya kredit kepada Scott M Carney.
Display for Bullish / Bearish Retracement
Paparan untuk Bullish / Bearish Retracement
Display for Primary Retracement and Primary Projection
Paparan untuk Primary Retracement and Primary Projection
Display for Secondary Derived Extreme Retracement and Secondary Derived Extreme Projection
Paparan untuk Secondary Derived Extreme Retracement and Secondary Derived Extreme Projection
[CLX][#02] Registry (type-based)This script only provides a basic __setter and __getter registration function with a type-based limitation.
We don't want to blow the code with additional conditions. The suggestion was to get the basic functionality.
Benefits:
- Get/set/update global-like variables between functions
- No init needed. You can call a entry before you set it.
Get-Functions:
- f_reg_getInt(_key)
- f_reg_getFloat(_key)
- f_reg_getBool(_key)
- f_reg_getString(_key)
- f_reg_getColor(_key)
- f_reg_getLabel(_key)
- f_reg_getLine(_key)
Set-Functions:
- f_reg_setInt(_key, _value)
- f_reg_setFloat(_key, _value)
- f_reg_setBool(_key, _value)
- f_reg_setString(_key, _value)
- f_reg_setColor(_key, _value)
- f_reg_setLabel(_key, _value)
- f_reg_setLine(_key, _value)
Feel free to contribute for an extended version. :)
We hope you enjoy it! 🎉
CRYPTOLINX - jango_blockchained 😊👍
Disclaimer:
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely.
The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script. In exchange for using the script, you agree not to hold dgtrd TradingView user liable for any possible claim for damages arising from any decision you make based on use of the script.
Harmonic Pattern Table (Source Code)This table indicator was intended as helper / reference for using XABCD Pattern.
Indikator berjadual bertujuan sebagai bantuan / rujukan untuk kegunaan XABCD Pattern.
The values shown in table was based on Harmonic Trading Volume 3: Reaction vs. Reversal written by Scott M Carney.
Nilai yang ditunjukkan dalam jadual adalah berdasarkan buku Harmonic Trading Volume 3: Reaction vs. Reversal ditulis oleh Scott M Carney.
Indicator features :
1. List Harmonic Patterns.
2. Font size small for mobile app and font size normal for desktop.
Kemampuan indikator :
1. Senarai Harmonic Pattern.
2. Saiz font kecil untuk mobile app dan saiz size normal untuk desktop.
FAQ
1. Credits / Kredit
Scott M Carney,
Scott M Carney, Trading Volume 3: Reaction vs. Reversal
2. Code Usage / Penggunaan Kod
Free to use for personal usage but credits are most welcomed especially for credits to Scott M Carney.
Bebas untuk kegunaan peribadi tetapi kredit adalah amat dialu-alukan terutamanya kredit kepada Scott M Carney.
Default Settings.
Setting asal.
Setting for selected Harmonic Pattern (Example : Bat)
Setting untuk pilihan Harmonic Pattern (Contoh : Bat)
Setting for show Harmonic Pattern only (Example : Bat)
Setting untuk nama Harmonic Pattern sahaja(Contoh : Bat)
MYX Bursa IPO Listing Table (Source Code)This indicator intended for Malaysia Market only for Initial Public Offering (IPO) refer to Bursa Malaysia
Indikator ini adalah untuk pasaran Malaysia sahaja untuk Tawaran Awam Permulaan (IPO) rujuk kepada Bursa Malaysia
Indicator features :
1. List similar symbol or counter based on year including total.
2. Font size small for mobile app and font size normal for desktop.
Kemampuan indikator :
1. Senarai simbol atau kaunter yang terlibat mengiku tahun termasuk jumlah.
2. Saiz font kecil untuk mobile app dan saiz size normal untuk desktop.
FAQ
1. Code Usage / Penggunaan Kod
Free to use for personal usage but credits are most welcomed.
Not for business / commercial usage, any damage or lialibity are not my resposibility.
Bebas untuk kegunaan peribadi tetapi kredit adalah amat dialu-alukan.
Bukan untuk kegunaan perniagaan / komersil, sebarang kerosakan atau liability adalah di luar tanggungjawab saya.
2. Update Frequency / Frekuensi
Anytime after official update by Bursa Malaysia.
Bila-bila masa selepas kemaskini rasmi oleh Bursa Malaysia
3. Symbol/Counter not showing / Simbol/kaunter tiada
Symbol/counter not longer exist or not yet updated.
Simbol/kaunter telah tersenarai keluar atau belum dikemaskini.
4. Why table overlap with chart ? To avoid this, click indicator > Visual Order > Send to Front.
Kenapa table bertindih dengan carta ? Untuk mengatasi ini, klik indikator > Visual Order > Send to Front.
All Setting enabled.
Semua seting diaktifkan.
Small Font setting enabled, suitable for mobile app.
Setting font kecil diaktifkan., sesuai untuk mobile app.
Setting by year.
Setting mengikut tahun.
MYX Delisted PN17 GN13 Auto Detect (Source Code)This indicator intended for Malaysia Market only for auto detect delisted companies (PN17, GN13) refer to Bursa Malaysia
Indikator ini adalah untuk pasaran Malaysia sahaja untuk automatik mengenalpasti senarai syarikat terkeluar rujuk kepada Bursa Malaysia
Indicator features :
1. Able to detect stock and warrant.
2. List similar symbol or counter including total.
3. Font size small for mobile app and font size normal for desktop.
4. Show date updated by Bursa Malaysia.
Kemampuan indikator :
1. Boleh mengenal pasti saham dan waran.
2. Senarai simbol atau kaunter yang terlibat termasuk jumlah.
3. Saiz font kecil untuk mobile app dan saiz size normal untuk desktop.
4. Memaparkan tarikh kemaskini oleh Bursa Malaysia.
Date Updated / Tarikh Kemaskini : 14/7/2021
FAQ
1. Credits / Kredit
LucF & PineCoders
2. Code Usage / Penggunaan Kod
Free to use for personal usage but credits are most welcomed.
Not for business / comercial usage, any damage or lialibity are not my resposibility.
Bebas untuk kegunaan peribadi tetapi kredit adalah amat dialu-alukan.
Bukan untuk kegunaan perniagaan / komersil, sebarang kerosakan atau liability adalah di luar tanggungjawab saya.
3. Update Frequency / Frekuensi
Anytime after official update by Bursa Malaysia.
Bila-bila masa selepas kemaskini rasmi oleh Bursa Malaysia
4. Symbol/Counter not showing / Simbol/kaunter tiada
Symbol/counter not longer exist or not yet updated.
Simbol/kaunter telah tersenarai keluar atau belum dikemaskini.
Single layout with font size normal
Satu layout dengan saiz font normal
Double layout with small font size (Left : Stock, Right : Warrant)
Dua layout dengan font saiz normal (Kiri : Saham, Kanan : Waran)
Pinescript - Common Label & Line Array Functions Library by RRBPinescript - Common Label & Line Array Functions Library by RagingRocketBull 2021
Version 1.0
This script provides a library of common array functions for arrays of label and line objects with live testing of all functions.
Using this library you can easily create, update, delete, join label/line object arrays, and get/set properties of individual label/line object array items.
You can find the full list of supported label/line array functions below.
There are several libraries:
- Common String Functions Library
- Standard Array Functions Library
- Common Fixed Type Array Functions Library
- Common Label & Line Array Functions Library
- Common Variable Type Array Functions Library
Features:
- 30 array functions in categories create/update/delete/join/get/set with support for both label/line objects (45+ including all implementations)
- Create, Update label/line object arrays from list/array params
- GET/SET properties of individual label/line array items by index
- Join label/line objects/arrays into a single string for output
- Supports User Input of x,y coords of 5 different types: abs/rel/rel%/inc/inc% list/array, auto transforms x,y input into list/array based on type, base and xloc, translates rel into abs bar indexes
- Supports User Input of lists with shortened names of string properties, auto expands all standard string properties to their full names for use in functions
- Live Output for all/selected functions based on User Input. Test any function for possible errors you may encounter before using in script.
- Output filters: hide all excluded and show only allowed functions using a list of function names
- Output Panel customization options: set custom style, color, text size, and line spacing
Usage:
- select create function - create label/line arrays from lists or arrays (optional). Doesn't affect the update functions. The only change in output should be function name regardless of the selected implementation.
- specify num_objects for both label/line arrays (default is 7)
- specify common anchor point settings x,y base/type for both label/line arrays and GET/SET items in Common Settings
- fill lists with items to use as inputs for create label/line array functions in Create Label/Line Arrays section
- specify label/line array item index and properties to SET in corresponding sections
- select label/line SET function to see the changes applied live
Code Structure:
- translate x,y depending on x,y type, base and xloc as specified in UI (required for all functions)
- expand all shortened standard property names to full names (required for create/update* from arrays and set* functions, not needed for create/update* from lists) to prevent errors in label.new and line.new
- create param arrays from string lists (required for create/update* from arrays and set* functions, not needed for create/update* from lists)
- create label/line array from string lists (property names are auto expanded) or param arrays (requires already expanded properties)
- update entire label/line array or
- get/set label/line array item properties by index
Transforming/Expanding Input values:
- for this script to work on any chart regardless of price/scale, all x*,y* are specified as % increase relative to x0,y0 base levels by default, but user can enter abs x,price values specific for that chart if necessary.
- all lists can be empty, contain 1 or several items, have the same/different lengths. Array Length = min(min(len(list*)), mum_objects) is used to create label/line objects. Missing list items are replaced with default property values.
- when a list contains only 1 item it is duplicated (label name/tooltip is also auto incremented) to match the calculated Array Length
- since this script processes user input, all x,y values must be translated to abs bar indexes before passing them to functions. Your script may provide all data internally and doesn't require this step.
- at first int x, float y arrays are created from user string lists, transformed as described below and returned as x,y arrays.
- translated x,y arrays can then be passed to create from arrays function or can be converted back to x,y string lists for the create from lists function if necessary.
- all translation logic is separated from create/update/set functions for the following reasons:
- to avoid redundant code/dependency on ext functions/reduce local scopes and to be able to translate everything only once in one place - should be faster
- to simplify internal logic of all functions
- because your script may provide all data internally without user input and won't need the translation step
- there are 5 types available for both x,y: abs, rel, rel%, inc, inc%. In addition to that, x can be: bar index or time, y is always price.
- abs - absolute bar index/time from start bar0 (x) or price (y) from 0, is >= 0
- rel - relative bar index/time from cur bar n (x) or price from y0 base level, is >= 0
- rel% - relative % increase of bar index/time (x) or price (y) from corresponding base level (x0 or y0), can be <=> 0
- inc - relative increment (step) for each new level of bar index/time (x) or price (y) from corresponding base level (x0 or y0), can be <=> 0
- inc% - relative % increment (% step) for each new level of bar index/time (x) or price (y) from corresponding base level (x0 or y0), can be <=> 0
- x base level >= 0
- y base level can be 0 (empty) or open, close, high, low of cur bar
- single item x1_list = "50" translates into:
- for x type abs: "50, 50, 50 ..." num_objects times regardless of xloc => x = 50
- for x type rel: "50, 50, 50 ... " num_objects times => x = x_base + 50
- for x type rel%: "50%, 50%, 50% ... " num_objects times => x_base * (1 + 0.5)
- for x type inc: "0, 50, 100 ... " num_objects times => x_base + 50 * i
- for x type inc%: "0%, 50%, 100% ... " num_objects times => x_base * (1 + 0.5 * i)
- when xloc = xloc.bar_index each rel*/inc* value in the above list is then subtracted from n: n - x to convert rel to abs bar index, values of abs type are not affected
- x1_list = "0, 50, 100, ..." of type rel is the same as "50" of type inc
- x1_list = "50, 50, 50, ..." of type abs/rel/rel% produces a sequence of the same values and can be shortened to just "50"
- single item y1_list = "2" translates into (ragardless of yloc):
- for y type abs: "2, 2, 2 ..." num_objects times => y = 2
- for y type rel: "2, 2, 2 ... " num_objects times => y = y_base + 2
- for y type rel%: "2%, 2%, 2% ... " num_objects times => y = y_base * (1 + 0.02)
- for y type inc: "0, 2, 4 ... " num_objects times => y = y_base + 2 * i
- for y type inc%: "0%, 2%, 4% ... " num_objects times => y = y_base * (1 + 0.02 * i)
- when yloc != yloc.price all calculated values above are simply ignored
- y1_list = "0, 2, 4" of type rel% is the same as "2" with type inc%
- y1_list = "2, 2, 2" of type abs/rel/rel% produces a sequence of the same values and can be shortened to just "2"
- you can enter shortened property names in lists. To lookup supported shortened names use corresponding dropdowns in Set Label/Line Array Item Properties sections
- all shortened standard property names must be expanded to full names (required for create/update* from arrays and set* functions, not needed for create/update* from lists) to prevent errors in label.new and line.new
- examples of shortened property names that can be used in lists: bar_index, large, solid, label_right, white, left, left, price
- expanded to their corresponding full names: xloc.bar_index, size.large, line.style_solid, label.style_label_right, color.white, text.align_left, extend.left, yloc.price
- all expanding logic is separated from create/update* from arrays and set* functions for the same reasons as above, and because param arrays already have different types, implying the use of final values.
- all expanding logic is included in the create/update* from lists functions because it seemed more natural to process string lists from user input directly inside the function, since they are already strings.
Creating Label/Line Objects:
- use study max_lines_count and max_labels_count params to increase the max number of label/line objects to 500 (+3) if necessary. Default number of label/line objects is 50 (+3)
- all functions use standard param sequence from methods in reference, except style always comes before colors.
- standard label/line.get* functions only return a few properties, you can't read style, color, width etc.
- label.new(na, na, "") will still create a label with x = n-301, y = NaN, text = "" because max default scope for a var is 300 bars back.
- there are 2 types of color na, label color requires color(na) instead of color_na to prevent error. text_color and line_color can be color_na
- for line to be visible both x1, x2 ends must be visible on screen, also when y1 == y2 => abs(x1 - x2) >= 2 bars => line is visible
- xloc.bar_index line uses abs x1, x2 indexes and can only be within 0 and n ends, where n <= 5000 bars (free accounts) or 10000 bars (paid accounts) limit, can't be plotted into the future
- xloc.bar_time line uses abs x1, x2 times, can't go past bar0 time but can continue past cur bar time into the future, doesn't have a length limit in bars.
- xloc.bar_time line with length = exact number of bars can be plotted only within bar0 and cur bar, can't be plotted into the future reliably because of future gaps due to sessions on some charts
- xloc.bar_index line can't be created on bar 0 with fixed length value because there's only 1 bar of horiz length
- it can be created on cur bar using fixed length x < n <= 5000 or
- created on bar0 using na and then assigned final x* values on cur bar using set_x*
- created on bar0 using n - fixed_length x and then updated on cur bar using set_x*, where n <= 5000
- default orientation of lines (for style_arrow* and extend) is from left to right (from bar 50 to bar 0), it reverses when x1 and x2 are swapped
- price is a function, not a line object property
Variable Type Arrays:
- you can't create an if/function that returns var type value/array - compiler uses strict types and doesn't allow that
- however you can assign array of any type to another array of any type creating an arr pointer of invalid type that must be reassigned to a matching array type before used in any expression to prevent error
- create_any_array2 uses this loophole to return an int_arr pointer of a var type array
- this works for all array types defined with/without var keyword and doesn't work for string arrays defined with var keyword for some reason
- you can't do this with var type vars, only var type arrays because arrays are pointers passed by reference, while vars are actual values passed by value.
- you can only pass a var type value/array param to a function if all functions inside support every type - otherwise error
- alternatively values of every type must be passed simultaneously and processed separately by corresponding if branches/functions supporting these particular types returning a common single type result
- get_var_types solves this problem by generating a list of dummy values of every possible type including the source type, tricking the compiler into allowing a single valid branch to execute without error, while ignoring all dummy results
Notes:
- uses Pinescript v3 Compatibility Framework
- uses Common String Functions Library, Common Fixed Type Array Functions Library, Common Variable Type Array Functions Library
- has to be a separate script to reduce the number of local scopes/compiled file size, can't be merged with another library.
- lets you live test all label/line array functions for errors. If you see an error - change params in UI
- if you see "Loop too long" error - hide/unhide or reattach the script
- if you see "Chart references too many candles" error - change x type or value between abs/rel*. This can happen on charts with 5000+ bars when a rel bar index x is passed to label.new or line.new instead of abs bar index n - x
- create/update_label/line_array* use string lists, while create/update_label/line_array_from_arrays* use array params to create label/line arrays. "from_lists" is dropped to shorten the names of the most commonly used functions.
- create_label/line_array2,4 are preferable, 5,6 are listed for pure demonstration purposes only - don't use them, they don't improve anything but dramatically increase local scopes/compiled file size
- for this reason you would mainly be using create/update_label/line_array2,4 for list params or create/update_label/line_array_from_arrays2 for array params
- all update functions are executed after each create as proof of work and can be disabled. Only create functions are required. Use update functions when necessary - when list/array params are changed by your script.
- both lists and array item properties use the same x,y_type, x,y_base from common settings
- doesn't use pagination, a single str contains all output
- why is this so complicated? What are all these functions for?
- this script merges standard label/line object methods with standard array functions to create a powerful set of label/line object array functions to simplify manipulation of these arrays.
- this library also extends the functionality of Common Variable Type Array Functions Library providing support for label/line types in var type array functions (any_to_str6, join_any_array5)
- creating arrays from either lists or arrays adds a level of flexibility that comes with complexity. It's very likely that in your script you'd have to deal with both string lists as input, and arrays internally, once everything is converted.
- processing user input, allowing customization and targeting for any chart adds a whole new layer of complexity, all inputs must be translated and expanded before used in functions.
- different function implementations can increase/reduce local scopes and compiled file size. Select a version that best suits your needs. Creating complex scripts often requires rewriting your code multiple times to fit the limits, every line matters.
P.S. Don't rely too much on labels, for too often they are fables.
List of functions*:
* - functions from other libraries are not listed
1. Join Functions
Labels
- join_label_object(label_, d1, d2)
- join_label_array(arr, d1, d2)
- join_label_array2(arr, d1, d2, d3)
Lines
- join_line_object(line_, d1, d2)
- join_line_array(arr, d1, d2)
- join_line_array2(arr, d1, d2, d3)
Any Type
- any_to_str6(arr, index, type)
- join_any_array4(arr, d1, d2, type)
- join_any_array5(arr, d, type)
2. GET/SET Functions
Labels
- label_array_get_text(arr, index)
- label_array_get_xy(arr, index)
- label_array_get_fields(arr, index)
- label_array_set_text(arr, index, str)
- label_array_set_xy(arr, index, x, y)
- label_array_set_fields(arr, index, x, y, str)
- label_array_set_all_fields(arr, index, x, y, str, xloc, yloc, label_style, label_color, text_color, text_size, text_align, tooltip)
- label_array_set_all_fields2(arr, index, x, y, str, xloc, yloc, label_style, label_color, text_color, text_size, text_align, tooltip)
Lines
- line_array_get_price(arr, index, bar)
- line_array_get_xy(arr, index)
- line_array_get_fields(arr, index)
- line_array_set_text(arr, index, width)
- line_array_set_xy(arr, index, x1, y1, x2, y2)
- line_array_set_fields(arr, index, x1, y1, x2, y2, width)
- line_array_set_all_fields(arr, index, x1, y1, x2, y2, xloc, extend, line_style, line_color, width)
- line_array_set_all_fields2(arr, index, x1, y1, x2, y2, xloc, extend, line_style, line_color, width)
3. Create/Update/Delete Functions
Labels
- delete_label_array(label_arr)
- create_label_array(list1, list2, list3, list4, list5, d)
- create_label_array2(x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- create_label_array3(x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- create_label_array4(x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- create_label_array5(x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- create_label_array6(x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- update_label_array2(label_arr, x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- update_label_array4(label_arr, x_list, y_list, str_list, xloc_list, yloc_list, style_list, color1_list, color2_list, size_list, align_list, tooltip_list, d)
- create_label_array_from_arrays2(x_arr, y_arr, str_arr, xloc_arr, yloc_arr, style_arr, color1_arr, color2_arr, size_arr, align_arr, tooltip_arr, d)
- create_label_array_from_arrays4(x_arr, y_arr, str_arr, xloc_arr, yloc_arr, style_arr, color1_arr, color2_arr, size_arr, align_arr, tooltip_arr, d)
- update_label_array_from_arrays2(label_arr, x_arr, y_arr, str_arr, xloc_arr, yloc_arr, style_arr, color1_arr, color2_arr, size_arr, align_arr, tooltip_arr, d)
Lines
- delete_line_array(line_arr)
- create_line_array(list1, list2, list3, list4, list5, list6, d)
- create_line_array2(x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- create_line_array3(x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- create_line_array4(x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- create_line_array5(x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- create_line_array6(x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- update_line_array2(line_arr, x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- update_line_array4(line_arr, x1_list, y1_list, x2_list, y2_list, xloc_list, extend_list, style_list, color_list, width_list, d)
- create_line_array_from_arrays2(x1_arr, y1_arr, x2_arr, y2_arr, xloc_arr, extend_arr, style_arr, color_arr, width_arr, d)
- update_line_array_from_arrays2(line_arr, x1_arr, y1_arr, x2_arr, y2_arr, xloc_arr, extend_arr, style_arr, color_arr, width_arr, d)
Pinescript - Standard Array Functions Library by RRBStandard Array Functions Library by RagingRocketBull 2021
Version 1.0
This script provides a library of every standard Pinescript array function for live testing with all supported array types.
You can find the full list of supported standard array functions below.
There are several libraries:
- Common String Functions Library
- Common Array Functions Library
- Standard Array Functions Library
Features:
- Supports all standard array functions (30+) with all possible array types* (* - except array.new* functions and label, line array types)
- Live Output for all/selected functions based on User Input. Test any function for possible errors you may encounter before using in script.
- Output filters: show errors, hide all excluded and show only allowed functions using a list of function names
- Console customization options: set custom text size, color, page length, line spacing
Notes:
- uses Pinescript v3 Compatibility Framework
- uses Common String Functions Library
- has to be a separate script to reduce the number of local scopes in Common Array Function Library, there's no way to merge these scripts into a single library.
- lets you live test all standard array functions for errors. If you see an error - change params in UI
- array types that are not supported by certain functions and producing a compilation error were disabled with "error" showing up as result
- if you see "Loop too long" error - hide/unhide or reattach the script
- doesn't use pagination, a single str contains all output
- for most array functions to work (except push), an array must be defined with at least 1 pre-existing dummy element 0.
- array.slice and array.fill require from_index < to_index otherwise error
- array.join only supports string arrays, and delimiter must be a const string, can't be var/input. Use join_any_array to join any array type into string. You can also use tostring() to join int, float arrays.
- array.sort only supports int, float arrays. Use sort_any_array from the Common Array Function Library to sort any array type.
- array.sort only sorts values, doesn't preserve indexes. Use sort_any_array from the Common Array Function Library to sort any array while preserving indexes.
- array.concat appends string arrays in reverse order, other array types are appended correctly
- array.covariance requires 2 int, float arrays of the same size
- tostring(flag) works only for internal bool vars, flag expression can't depend on any inputs of any type, use bool_to_str instead
- you can't create an if/function that returns var type value/array - compiler uses strict types and doesn't allow that
- however you can assign array of any type to another array of any type creating an arr pointer of invalid type that must be reassigned to a matching array type before used in any expression to prevent error
- source_array and create_any_array2 use this loophole to return an int_arr pointer of a var type array
- this works for all array types defined with/without var keyword. This doesn't work for string arrays defined with var keyword for some reason
- you can't do this with var type vars, this can be done only with var type arrays because they are pointers passed by reference, while vars are the actual values passed by value.
- wrapper functions solve the problem of returning var array types. This is the only way of doing it when the top level arr type is undefined.
- you can only pass a var type value/array param to a function if all functions inside support every type - otherwise error
- alternatively values of every type must be passed simultaneously and processed separately by corresponding if branches/functions supporting these particular types returning a common single result type
- get_var_types solves this problem by generating a list of dummy values of every possible type including the source type, allowing a single valid branch to execute without error
- examples of functions supporting all array types: array.size, array.get, array.push. Examples of functions with limited type support: array.sort, array.join, array.max, tostring
- unlike var params/global vars, you can modify array params and global arrays directly from inside functions using standard array functions, but you can't use := (it only works for local arrays)
- inside function always work with array.copy to prevent accidental array modification
- you can't compare arrays
- there's no na equivalent for arrays, na(arr) doesn't work
P.S. A wide array of skills calls for an even wider array of responsibilities
List of functions:
- array.avg(arr)
- array.clear(arr)
- array.concat(arr1, arr2)
- array.copy(arr)
- array.covariance(arr1, arr2)
- array.fill(arr, value, index_from, index_to)
- array.get(arr, index)
- array.includes(arr, value)
- array.indexof(arr, value)
- array.insert(arr, index, value)
- array.join(arr, delimiter)
- array.lastindexof(arr, value)
- array.max(arr)
- array.median(arr)
- array.min(arr)
- array.mode(arr)
- array.pop(arr)
- array.push(arr, value)
- array.range(arr)
- array.remove(arr, index)
- array.reverse(arr)
- array.set(arr, index, value)
- array.shift(arr)
- array.size(arr)
- array.slice(arr, index_from, index_to)
- array.sort(arr, order)
- array.standardize()
- array.stdev(arr)
- array.sum(arr)
- array.unshift(arr, value)
- array.variance(arr)
Correlation MeterThis script calculates the covariance and correlation coefficient between two markets using arrays.
Lookback: How many bars to perform the calculation on.
Source: Price source to calculate the correlation on.
Reference Market: The reference market to compare to the current market.
It's a simple indicator, but very useful for determining how correlated your preferred markets to trade are.
A correlation reading of +1.0 means the markets are perfectly positively correlated, a reading of -1.0 means they are perfectly negatively correlated.
If you're not sure what correlation & covariance are then Google the terms with "Investopedia" added to the end - they have some great definitions and examples.
For traders this can be useful for deciding how much risk to spread across two markets that have a high correlation, or how to hedge existing positions by trading a negatively correlated market.
For investors this can be useful for building a truly diversified portfolio.
If a market has a high positive correlation, the black line will stay above zero most of the time. If a market has a high negative correlation, the black line will stay below zero most of the time.
A market with no or little correlation will bounce between the two or hover around zero most of the time.
The example market above is comparing Apple's weekly price action to the S&P500's over the past 20 weeks. It has a high positive correlation as the black line is above zero most of the time.
Good luck with your trading!
Pinescript Selection Sort Using ArraysThe selection sort algorithm sorts an array by repeatedly finding the smallest element from unsorted array and pushing it to the beginning. Two subarrays are maintained during the execution of the script. One of the subarrays is in a sorted state while the other is in a sorted state. After each iteration of the for loop the sorted list is searched for the next correct element which is then pushed onto the sorted subarray.
Worst case performance : О(n^2) comparisons and O(n)swaps
Best case performance : O(n^2) comparisons and O(n) Swaps
Average performance: О(n^2) comparisons and O(n) Swaps
Worst-case space complexity:О(n) total, O(1) auxiliary
The Pseudocode is given below
procedure selection sort
list : array of items
n : size of list
for i = 1 to n - 1
/* set current element as minimum*/
min = i
/* check the element to be minimum */
for j = i+1 to n
if list < list then
min = j;
end if
end for
/* swap the minimum element with the current element*/
if indexMin != i then
swap list and list
end if
end for
end procedure
Examples of Rolling Average Using Automated AnchoringIn this study, I present a method to expose NaN values to development environment.
This exposure allows NaN values to be used by methods in scripts.
I also show how to use values, even NaN values, as anchors from which statistics can be computed from.
I demonstrate how to do this with constants and variables in methods for computing the cumulative/rolling average of a series.
I also show how to calculate the cumulative/rolling average from the start of a ticker series using the aforementioned methods.
Each method has a description on how some of their parts work as well as their constraints.
Method #1 - Can only be used for computing the rolling average on the ticker series.
Method #2 - The simple moving average from the Pine Script reference.
- Can be used to calculate the rolling average of the ticker series and number values of a series.
- This method seems to cause an error when there are many bars in the series.
Method #3 - The most versatile method due to the use of computing the rolling average using an array.
- Timeout will occur when computing the rolling average of an entire ticker series which is long.
- Timeout has not occurred when computing a rolling average of a series from NaN or non-NaN anchor points even when the series is long.
This is an attempt to get around the constraints of the built-in sma(source, length) function in which length cannot be dynamically adjusted.
Other Pine Script functions have that constraint which we can get around by defining our own functions.
Joined and Sliced String ArrayUsing the new Pine Script array built-ins to join string elements together for label text. The array is sliced to remove extraneous elements.
Pivot Support / Resistance Panel [JV]Hello Traders,
First all of thanks to LonesomeTheBlue for making me grasp arrays, a wonderful addition to Pine Script.
This indicator uses arrays to find Pivot Points and mark them as Support / Resistance.
It displays an info panel with the latest values.
This code was written using the following standards:
• PineCoders Coding Conventions for Pine: www.pinecoders.com
Configurable options:
Up to 6 Support / Resistance Levels.
Pivot Lookback Period.
Panel Color.
Text Color.
Panel Offset.
Panel Size.
Enjoy!
function: Array DownsamplingA low cost function to down sample a array.
specially useful for pattern recognition algorithms.
Array SMACalcuating SMA on an Array
In this script i show you how to calculate SMA on an array.
Several values are plotted just for illustration.
Steps to follow:
- make sure you have an array with values (source array)
- create a blank array (pref. with the same size)
- call the function array_sma
This function fills the empty array with the SMA values of the source array.
Advancing Declining OscillatorYet another Array indicator, simple, but efficient which i call ADO. The indicator acts as a COUNTER of when CLOSE closes above OPEN and vice versa based on specified look back period in settings.
If we have more Closes above Opens, obviously the indicator will be above ZERO and GREEN, otherwise RED.
Optional to smooth it by EMA (true by default).
Like if you Like and Enjoy!
Truncated Bandpass Filter and Bandpass Filter - Dr. John EhlersWith the arrival of the blessed gifts of arrays from TV, I now present the REAL "Truncated Bandpass Filter" indicator employing PSv4.0 upon initial release, originally formulated by the magnificent mathemagician Dr. John Ehlers for TASC - July 2020 Traders Tips. Don't be bamboozled by the other incorrect truncated bandpass filters found on TV, those published with an erroneous haste that preceded Pine array availability. More information about these bandpass filters can be acquired with a simple search for this indicator's white paper, entitled "TRUNCATED INDICATORS by John F. Ehlers", on his site in the educational reference section.
This actually contains two indicators, one being the truncated bandpass, the other being a two pole bandpass which is also found in my Voss implementation. The two pole bandpass is primarily for comparison of both types, but as you can see, they share common code within both, one being truncated and the other not. I modified Ehlers' original truncation formulation by allowing the capability to alter the truncation period using two distinct methods. I will explain very briefly that the purpose of a truncated "infinite impulse response" filter is to dampen it's response. Truncation techniques aren't limited to only bandpass filters, "some" other IIR filters, but not all, may benefit from this as well.
Lastly this is a miniature starter lesson by example of how the new native Pine array functions may be used, along with other various methods such as `var` to improve computational efficiency on the cloud servers. Yep, native Pine arrays just doubled the "Power of Pine" by exponential magnitudes of power into the dimension of what I would now term as the "Immense Power of Pine" . The next generation capability of programming extremely advanced indicators has now successfully arrived on mothership Earth, right on TradingView's front lawn. Who would of known?? This is brought to you in part by the devoted voluntary efforts of the most skilled poetic programmers on TV, the likes of which most extraterrestrial alien programmers would fear. Ladies and Gents, YOU KNOW WHO YOU ARE. Wink, wink!
NOTICE: You have absolute freedom to use this source code any way you see fit within your new Pine projects. You don't have to ask for my permission to reuse these functions in your published scripts, simply because I have better things to do than answer requests for the reuse of the tbpf() and bpf() functions. Sufficient accreditation regarding this script and compliance with "TV's House Rules" regarding code reuse, is as easy as copying the functions in their entirety as is. Fair enough? Good!
Features List Includes:
Dark Background - Easily disabled in indicator Settings->Style for "Light" charts or with Pine commenting
AND a few more... Why list them, when you have the source code to explore!
When available time provides itself, I will consider your inquiries, thoughts, and concepts presented below in the comments section, should you have any questions or comments regarding this indicator. When my indicators achieve more prevalent use by TV members, I may implement more ideas when they present themselves as worthy additions. Have a profitable future everyone!
Low - High Simple TrackerYet another "Low - High" indicator using the new Pine Script Arrays.
The indicator uses the latests Lows and Highs to plot a trend line and reversal/slowdown.
More detailed explanation inside the script.
Enjoy!
Green - Up Trending
Red - Down Trending
White - Slow Down/Reversal might occur.
Made for educational purposes of how to use Arrays, yet can be very useful.