MiteTricksLibrary "MiteTricks"
Matrix Global Registry.
Get, Set, automatic growing, universal get/set,
multi-matrix dictionaries, multi-dictionary matrixes..
add slice matrixes of any type, share one common global key registry
pull up an item from a category, and item name ie a table of info.
same cell needs a color, a size, a string, a value, etc..
all of which can be pulled up with the same group id, and key id.
just swap which matrix you pull the value from.
this has a side benefit of non-repainting and recalculating
when pulling values, changing inputs..
makes for very fast/clean usage..
benefit :
floats = value
strings = names
lines = drawn items
table =table of data items for this key
colors = color for line/table/fill,label..
all of those can be pulled with "get(_VALUES,_groupIDX,_keyIDX)" where only the values matrix needs be swapped, and the same item/coordinates remains for all the possible matrixes that item appears in.
also useful as a dictionary/registry for any given type of item,,
and goes very handy with floats/strings/colors/bools with my matrixautotable
very helpful when prototyping or doing development work as a shortcut.
initRegistry()
  Registry inititalizer
  Returns: registry of string matrix type
newbool(optional, optional, optional)
  create bool type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is bool (na)
  Returns: bool matrix of specified size and fill, or blank 2x2 for registry use
newbox(optional, optional, optional)
  create box type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is box (na)
  Returns: box matrix of specified size and fill, or blank 2x2 for registry use
newcolor(optional, optional, optional)
  create color type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is color (na)
  Returns: color matrix of specified size and fill, or blank 2x2 for registry use
newfloat(optional, optional, optional)
  create float type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is float (na)
  Returns: float matrix of specified size and fill, or blank 2x2 for registry use
newint(optional, optional, optional)
  create int type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is int (na)
  Returns: int matrix of specified size and fill, or blank 2x2 for registry use
newlabel(optional, optional, optional)
  create label type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is label (na)
  Returns: label matrix of specified size and fill, or blank 2x2 for registry use
newline(optional, optional, optional)
  create line type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is line (na)
  Returns: line matrix of specified size and fill, or blank 2x2 for registry use
newlinefill(optional, optional, optional)
  create linefill type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is linefill(na)
  Returns: linefill matrix of specified size and fill, or blank 2x2 for registry use
newstring(optional, optional, optional)
  create string type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is string (na)
  Returns: string matrix of specified size and fill, or blank 2x2 for registry use
newtable(optional, optional, optional)
  create table type new matrix presized 2x2 for reg
  Parameters:
    optional: row size
    optional: column size
    optional: fill value(default is table (na)
  Returns: table matrix of specified size and fill, or blank 2x2 for registry use
newfrom(INIT_FILL)
  newfrom Matrix full of item input
  Parameters:
    INIT_FILL: item to fill (2x2) the matri and set type. a type(na) works
addrow(m, v)
  addrow Add new row to matrix
  Parameters:
    m: matrix of type being added to
    v: value of type being added to ( best leave NA on string for registry purposes)
addcolumn(matrix, value)
  addcolumn
  Parameters:
    matrix: of type being added to
    value: of type being added to ( best leave NA on string for registry purposes)
get(_VALS, _KEYREG, _GROUP, _KEY)
  get Grabs value and returns single item
  Parameters:
    _VALS: Matrix Values slice
    _KEYREG: Registry values matrix (strings)
    _GROUP: name of group/category or int group key
    _KEY: name of item to fetch from value registry or int key id
  Returns: item 
get(_VALS, _GROUP, _KEY)
  get Grabs value and returns single item
  Parameters:
    _VALS: Matrix Values slice
    _GROUP: name of group/category
    _KEY: name of item to fetch from value registry
getgid(_KEYREG, _GROUP)
  getgid
  Parameters:
    _KEYREG: Reg to pull group id from
    _GROUP: group index int, or string name to get the other missing type
getkid(_KEYREG, _GROUP, _KEY)
  getkid
  Parameters:
    _KEYREG: Reg to pull Key id from
    _GROUP: group index int, or string name
    _KEY: index of string key id to get it's ID int
getkey(_KEYREG, _GROUP, _KEY)
  getkey
  Parameters:
    _KEYREG: Reg to pull Key id from
    _GROUP: group index int, or string name for getting key string
    _KEY: index of string key id to get it's match of other type
set(_VALS, _KEYREG, _GROUP, _KEY, _value)
  set items to reg and matrix container
  Parameters:
    _VALS: Values matrix container
    _KEYREG: Key registry
    _GROUP: (string) Group/Category name
    _KEY: (string) Key for item
    _value: item
  Returns: void
del(_VALS, _KEYREG, _GROUP, _KEY)
  del grroup id
  Parameters:
    _VALS: Matrix Values slice
    _KEYREG: Registry values matrix (strings)
    _GROUP: name of group/category
    _KEY: name of item to Delete from values and key
detached(_GROUP, _KEY, _VALUE)
  detached make detached registry/val matrix
  Parameters:
    _GROUP: Name of first group
    _KEY: Name of first item
    _VALUE: Item of any type, sets the output type too.
 
Arrays
pta_plotLibrary   "pta_plot" 
pta_plot: This library will help you to plot different value. I will keep updating with your requirement
 print_array(array_id, border_color) 
  Display array element as a table.
  Parameters:
     array_id : Id of your array.
     border_color : Color for border (`color.black` is used if no argument is supplied).
  Returns: Display array element in bottom of the pane.
FunctionArrayUniqueLibrary   "FunctionArrayUnique" 
Method for retrieving the unique elements in a array.
for example   would retrieve a array with  ,
the elements retrieved will be sorted by its first seen index in 
parent array.
note: float values have no precision option.
 unique(source) 
  method for retrieving the unique elements in a array.
  Parameters:
     source : array source array to extract elements.
  Returns: array unique elements in the source array.
 unique(source) 
  method for retrieving the unique elements in a array.
  Parameters:
     source : array source array to extract elements.
  Returns: array unique elements in the source array.
 unique(source) 
  method for retrieving the unique elements in a array.
  Parameters:
     source : array source array to extract elements.
  Returns: array unique elements in the source array.
functionStringToMatrixLibrary   "functionStringToMatrix" 
Provides unbound methods (no error checking) to parse a string into a float or int matrix.
 to_matrix_float(str, interval_sep, start_tk, end_tk) 
  Parse a string into a float matrix.
  Parameters:
     str : , string, the formated string to parse.
     interval_sep : , string, cell interval separator token.
     start_tk : , string, row start token.
     end_tk : , string, row end token.
  Returns: matrix, parsed float matrix.
 to_matrix_int(str, interval_sep, start_tk, end_tk) 
  Parse a string into a int matrix.
  Parameters:
     str : , string, the formated string to parse.
     interval_sep : , string, cell interval separator token.
     start_tk : , string, row start token.
     end_tk : , string, row end token.
  Returns: matrix, parsed int matrix.
CyclicRsiLib█ OVERVIEW 
This library is complementary for  Cyclic RSI High Low With Noise Filter. 
 █ CREDITS 
 LoneSomeTheBlue 
 WhenToTrade 
 AlertFrequency() 
  : AlertFrequency
  Parameters:
     : : _string
  Returns: : _freq
 CyclicRSI() 
  : CyclicRSI
  Parameters:
     : : _source, _length, _expression
  Returns: : osc
Credits to WhenToTrade
 AddToZigzag() 
  : AddToZigzag
  Parameters:
     : : _id, value, max_array_size
  Returns: : array.unshift, array.pop
Credits to LonesomeTheBlue
 UpdateZigzag() 
  : UpdateZigzag
  Parameters:
     : : _id, value, max_array_size, dir
  Returns: : AddToZigzag, array.set
Credits to LonesomeTheBlue
 BoolZigzag() 
  : BoolZigzag
  Parameters:
     : : ph, pl, dirchanged, _id, dir
  Returns: : AddToZigzag, UpdateZigzag
Credits to LonesomeTheBlue
 NoiseSwitch() 
  : NoiseSwitch
  Parameters:
     : : _string, _id
  Returns: : FilterNoise
 LineGray() 
  : LineGray
  Parameters:
     : : _id
  Returns: : LineGray
 LabelDir() 
  : LabelDir
  Parameters:
     : : _id, _string, _color, _float
  Returns: : LabelDir
 TernaryLabel() 
  : TernaryLabel
  Parameters:
     : : _dir, _bool1, _bool2, _string1, _string2
  Returns: : str_label
 TernaryColor() 
  : TernaryColor
  Parameters:
     : : _dir, _bool1, _bool2
  Returns: : col_label
getSeries█   OVERVIEW 
This library is a Pine programmer’s tool containing functions that build an array of values meeting specific conditions. Its functions use concepts from our  ConditionalAverages library , but instead of returning a single value, they return an array containing all the values meeting the conditions, which can then be processed as needed. This provides more flexibility to the programmer than a single value.
The "getSeries" name of the library stems from the fact that is uses arrays to build the equivalent of custom series which can then be operated on using array-specific functions in the `array.*` namespace, looped through using a  for...in  structure to implement custom logic, or sent to functions designed to process arrays such as those in these libraries:  ArrayStatistics ,  ArrayOperations ,  arrayutils  or  Averages .
The eight examples illustrated in the library's code showcase the diversity of scenarios where the functions can be used.
 Look first. Then leap.  
█   FUNCTIONS 
The library contains the following functions:
 whenSince(src, whenCond, sinceCond, length) 
  Creates an array containing the `length` last `src` values where `whenCond` is true, since the last occurence of `sinceCond`.
  Parameters:
     src : (series int/float) The source of the values to be included. 
     whenCond : (series bool) The condition determining which values are included. Optional. The default is `true`.
     sinceCond : (series bool) The condition determining when the accumulated series resets. Optional. The default is false, which will not reset. 
     length : (simple int) The number of last values to return. Optional. The default is all values.
  Returns: (float ) The array ID of the accumulated `src` values.
 rollOnTimeWhen(src, timeWindow, cond, minBars) 
  Creates an array of `src` values where `cond` is true, over a moving window of length `timeWindow` milliseconds.
  Parameters:
     src : (series int/float) The source of the values to be included. 
     timeWindow : (simple int) The time duration in milliseconds defining the size of the moving window.
     cond : (series bool) The condition determining which values are included. Optional. The default is `true`.
     minBars : (simple int) The minimum number of values to maintain in the moving window. Optional. The default is 1.
  Returns: (float ) The array ID of the accumulated `src` values.
Note that the functions must be called on each bar to work correctly. They must thus be pre-evaluated before using their results in conditional branches.
utilsLibrary   "utils" 
Few essentials captured together (subset of arrayutils)
 timer(timeStart, endTime) 
  finds difference between two timestamps
  Parameters:
     timeStart : start timestamp
     endTime : end timestamp
  Returns:  
 check_overflow(pivots, barArray, dir) 
  finds difference between two timestamps
  Parameters:
     pivots : pivots array
     barArray : pivot bar array
     dir : direction for which overflow need to be checked
  Returns: bool overflow
 get_trend_series(pivots, length, highLow, trend) 
  finds series of pivots in particular trend
  Parameters:
     pivots : pivots array
     length : length for which trend series need to be checked
     highLow : filter pivot high or low
     trend : Uptrend or Downtrend
  Returns: int  trendIndexes
 get_trend_series(pivots, firstIndex, lastIndex) 
  finds series of pivots in particular trend
  Parameters:
     pivots : pivots array
     firstIndex : First index of the series
     lastIndex : Last index of the series
  Returns: int  trendIndexes
 getConsolidatedLabel(include, labels, separator) 
  Consolidates labels into single string by concatenating it with given separator
  Parameters:
     include : array of conditions to include label or not
     labels : string array of labels
     separator : Separator for concatenating labels
  Returns: string labelText
 getColors(theme) 
  gets array of colors based on theme
  Parameters:
     theme : dark or light theme
  Returns: color  themeColors
rzigzagLibrary   "rzigzag" 
Recursive Zigzag Using Matrix allows to create zigzags recursively on multiple levels. After bit of consideration, decided to make this public.
 zigzag(length, ohlc, numberOfPivots, offset) 
  calculates plain zigzag based on input
  Parameters:
     length : Zigzag Length
     ohlc : Array containing ohlc values. Can also contain custom series
     numberOfPivots : Number of max pivots to be returned
     offset : Offset from current bar. Can be used for calculations based on confirmed bars
  Returns:  
 nextlevel(zigzagmatrix, numberOfPivots) 
  calculates next level zigzag based on present zigzag coordinates
  Parameters:
     zigzagmatrix : Matrix containing zigzag pivots, bars, bar time, direction and level
     numberOfPivots : Number of max pivots to be returned
  Returns: matrix zigzagmatrix
 draw(zigzagmatrix, newPivot, doublePivot, lineColor, lineWidth, lineStyle, showLabel, xloc) 
  draws zigzag based on the zigzagmatrix input
  Parameters:
     zigzagmatrix : Matrix containing zigzag pivots, bars, bar time, direction and level
     newPivot : Flag indicating there is update in the pivots
     doublePivot : Flag containing there is double pivot update on same bar
     lineColor : Zigzag line color
     lineWidth : Zigzag line width
     lineStyle : Zigzag line style
     showLabel : Flag to indicate display pivot labels
     xloc : xloc preference for drawing lines/labels
  Returns:  
 draw(length, ohlc, numberOfPivots, offset, lineColor, lineWidth, lineStyle, showLabel, xloc) 
  calculates and draws zigzag based on zigzag length and source input
  Parameters:
     length : Zigzag Length
     ohlc : Array containing ohlc values. Can also contain custom series
     numberOfPivots : Number of max pivots to be returned
     offset : Offset from current bar. Can be used for calculations based on confirmed bars
     lineColor : Zigzag line color
     lineWidth : Zigzag line width
     lineStyle : Zigzag line style
     showLabel : Flag to indicate display pivot labels
     xloc : xloc preference for drawing lines/labels
  Returns:  
 drawfresh(zigzagmatrix, zigzaglines, zigzaglabels, lineColor, lineWidth, lineStyle, showLabel, xloc) 
  draws fresh zigzag for all pivots in the input matrix.
  Parameters:
     zigzagmatrix : Matrix containing zigzag pivots, bars, bar time, direction and level
     zigzaglines : array to which all newly created lines will be added
     zigzaglabels : array to which all newly created lables will be added
     lineColor : Zigzag line color
     lineWidth : Zigzag line width
     lineStyle : Zigzag line style
     showLabel : Flag to indicate display pivot labels
     xloc : xloc preference for drawing lines/labels
  Returns: 
drawcandlesLibrary   "drawcandles" 
simple utility to draw different candles using box and lines. Quite useful for drawing candles such as zigzag candles or MTF candles
 draw(o, h, l, c, oBar, cBar) 
  draws candles based on ohlc values
  Parameters:
     o : Open Price
     h : High Price
     l : Low Price
     c : Close Price
     oBar : Open Time
     cBar : Close Time
  Returns: void
curveLibrary   "curve" 
Regression array Creator. Handy for weights, Auto Normalizes array while holding curves.
 curve(_size, _power) 
  Curve Regression Values Tool
  Parameters:
     _size : (float) Number of Steps required (float works, future consideration)
     _power : (float) Strength of value decrease
  Returns: (float ) Array of multipliers from 1 downwards to 0.
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!!
arraysLibrary "arrays"
Library contains utility functions using arrays.
delete( arr , index)
  remove an item from array at specific index. Also deletes the item
  Parameters:
    arr: - array from which the item needs to be deleted
    index: - index of item to be deleted
  Returns: void
pop( arr )
  remove the last item from array. Also deletes the item
  Parameters:
    arr: - array from which the last item needs to be removed and deleted
  Returns: void
shift( arr )
  remove an item from array at index 0. Also deletes the item
  Parameters:
    arr: - array from which the first item needs to be removed and deleted
  Returns: void
unshift( arr , val, maxItems)
  add an item to the beginning of an array with max items cap
  Parameters:
    arr: - array to which the item needs to be added at the beginning
    val: - value of item which needs to be added
    maxItems: - max items array can hold. After that, items are removed from the other end
  Returns: resulting array
clear( arr )
  remove and delete all items in an array
  Parameters:
    arr: - array which needs to be cleared
  Returns: void
push( arr , val, maxItems)
  add an item to the end of an array with max items cap
  Parameters:
    arr: - array to which the item needs to be added at the beginning
    val: - value of item which needs to be added
    maxItems: - max items array can hold. After that, items are removed from the starting index
  Returns: resulting array
HarmonicCalculation█ OVERVIEW
This library is complementary for  XABCD Harmonic Pattern Custom Range Interactive 
 PriceDiff() 
  : Price Difference
  Parameters:
     : : price_1, price_2
  Returns: : PriceDiff
 TimeDiff() 
  : Time Difference
  Parameters:
     : : time_1, time_2
  Returns: : TimeDiff
 ReturnIndexOf3Arrays() 
  : Return Index Of 3 Arrays
  Parameters:
     : : id1, id2, id3, _int
  Returns: : ReturnIndexOf3Arrays
 AbsoluteRange() 
  : Price Difference
  Parameters:
     : : price, y, point
  Returns: : AbsoluteRange
 PriceAverage() 
  : To calculate average of 2 prices
  Parameters:
     : : price_1, price_2
  Returns: : PriceAverage
 TimeAverage() 
  : To calculate average of 2 times
  Parameters:
     : : time_1, time_2
  Returns: : TimeAverage
 StringBool() 
  : To show ratio in 3 decimals format
  Parameters:
     : : _value, _bool, _text
  Returns: : StringBool
 PricePercent() 
  : To show Price in percent format
  Parameters:
     : : _price, PriceRef, str_dir
  Returns: : PricePercent
 BoolCurrency() 
  : To show syminfo.currency
  Parameters:
     : : _bool
  Returns: : BoolCurrency
 RatioText() 
  : To show RatioText in 3 decimals format
  Parameters:
     : : _value, _text
  Returns: : RatioText
 RangeText() 
  : To display RangeText in Harmonic Range Format
  Parameters:
     : : _id1, _id2, _int, _text
  Returns: : RangeText
 PriceCurrency() 
  : To show Currency in Price Format
  Parameters:
     : : _bool, _value
  Returns: : PriceCurrency
HarmonicDB█ OVERVIEW 
This library was to showcase database for specifications of Harmonic Patterns using arrays.
 █ CREDITS 
Scott M Carney, author of Harmonic Trading : Volume Three
 animal_db(x) 
  TODO: export animal_db
  Parameters:
     x : TODO: float value is set to default if not necessary
  Returns: TODO: 
DeleteArrayObject█ OVERVIEW 
Delete array object according to array size such as label, line, linefill, box and table.
 █ CREDITS 
 HeWhoMustNotBeNamed
"Swap" - Bool/Position/Value  : Array / Matrix / Var AutoswapLibrary   "swap" 
Side / Boundary Based All Types Swapper
- three automagical types for Arrays, Matrixes, and Variables
-- no signal     : Long/ Short position autoswap
-- true / false  : Boolean based side choice
-- Src / Thresh  : if source is above or  below the threshold
- two operating modes for variables, Holding mode only for arrays/matrixes
-- with two   items, will automatically change between the two caveat is it does not delete table/box/line(fill VAR items automatically)
-- with three items, a neutral is available for NA input or neutral
- one function name for all of them. One import name that's easy to type/remember
-- make life easy for your conditional items.
 side(source, thresh, _a, _b, _c) 
  side    Change outputs based on position or a crossing level
  Parameters:
     source : (float)  OPTIONAL value    input      
     thresh : (float)  OPTIONAL boundary line to cross
     _a : (any)    if Long/True/Above
     _b : (any)    if Short/False/Below
     _c : (any)    OPTIONAL  NOT FOR MTX OR ARR... Neutral Item, if var/varip on a/b it will leave behind, ie, a table or box or line will not erase , if it's a varip you're sending in. 
  Returns: first, second, or third items based on input conditions
Please notify if bugs found.
Thanks.
[LIB] Array / Matrix DisplayLibrary   "ArrayMatrixHUD" 
Show Array or Matrix Elements In Table
For Arrays: Set the number of rows you want the data displayed in and it will generate a table, calculating the columns based on the size of the array being displayed.
For Matrix: It will automatically match the Rows and Columns to the values in the matrix.
 Note: On the left, the table shows the index of the array/matrix value starting at 1. So, to call that value from inside the array, subtract 1 from the index value to the left.  For matrices, keep in mind that the row and column are also starting at one when trying to call a value from the matrix. The numbering of the values on the left is for display purposes only.  
 viewArray(_arrayName, _pos, _txtSize, _tRows) 
  Array Element Display (Supports float, int, string, and bool)
  Parameters:
     _arrayName : ID of Array to be Displayed
     _pos : Position for Table
     _txtSize : Size of Table Cell Text
     _tRows : Number of Rows to Display Data In (columns will be calculated accordingly)
  Returns: A Display of Array Values in a Table
 viewMatrix(_matrixName, _pos, _txtSize) 
  Matrix Element Display (Supports float, int, string, and bool)
  Parameters:
     _matrixName : ID of Matrix to be Displayed
     _pos : Position for Table
     _txtSize : Size of Table Cell Text
  Returns: A Display of Matrix Values in a Table
RecursiveAlertsLibrary   "RecursiveAlerts" 
The library provides options to run alert() calls in loop without worrying about limitations of frequency options.
When an alert statement is called within a loop,
it will fire just once per bar irrespective of how many iterations allowed when fequency is set to alert.freq_once_per_bar or alert.freq_once_per_bar_close
it will fire continuously till it breaks when frequency is set to alert.freq_all
The function helps overcome this issue by using varip key array which resets on every bar
 rAlert(message, key)  Enhanced alert which can be used in loops
  Parameters:
     message : Alert message to be fired
     key : Key to be checked to avoid repetitive alerts
  Returns: array containing id of already fired alerts
Thanks to @theheirophant, @JohnBaron and @LucF for discussions and suggestion which eventually lead to this solution :)
PivotThis library was designed to create three different datasets using Bill Williams fractals. The goal is to spot trends in reversal data and ultimately use these datasets to help predict future price reversals. 
First, the  pivot()  function is used to initialize and populate three separate arrays (high pivot , low pivot , all pivots ). Since each high/low price depends on the bar_index, the bar_index, pivot direction(high/low), and high/low values are compressed into a string to maintain the data's integrity ("__"). Once each string array is populated and organized by bar_index, all three are returned inside a tuple.  The return value must be deconstructed   H,L,A =pivot()  for each array's values to be accessed using  getPivot() . This boilerplate allows for data to be accessed more efficiently in a recursive environment. getPivot() was designed to be used inside of a for or while block to populate matrices for further analyses. Again, getPivot() return values must be exposed through deconstruction.  x,d,y =getPivot().  See code for more details.
 pivot(int XLR)  initializes and populates arrays
 Parameters 
 
 XLR  - number of bars to the left and right that must be lower for a high to be considered a pivotHigh, or vice versa.  This number will drastically change the size and scope of the returned datasets.  smaller values will produce much larger datasets, which might model short term price activity well. In contrast, larger values will produce smaller datasets which might model longer term price activity well.
 
 Returns  - tuple [string ]
 getPivot(string  arrayID, int index)  accesses array data
 Parameters 
 
 arrayID  - the variable name for one of the three arrays returned by pivot().
 index  - the index of the provided array, with 0 being the most recent pivot point. can be set to " i " in a loop to access values recursively
  
 Returns  - tuple
FunctionIntrabarCrossValueLibrary   "FunctionIntrabarCrossValue" 
 intrabar_cross_value(a, b, step)  Find the minimum difference of a intrabar cross and return its median value.
  Parameters:
     a : float, series a.
     b : float, series b.
     step : float, step to iterate x axis, default=0.01
  Returns: float
BitcoinHalvingLibrary   "BitcoinHalving" 
Displays where Bitcoin's halvings have been
 getDates()  List of Bitcoin halving dates
  Returns: array with timestamp dates
 isHalvingDay()  Checks if the current day is a halving day
  Returns: bool
matrixautotableLibrary   "matrixautotable" 
Automatic Table from Matrixes with pseudo correction for na values and default color override for missing values. uses overloads in cases of cheap float only, with additional addon for strings next, then cell colors, then text colors, and tooltips last..  basic size and location are auto, include the template to speed this up...
 TODO  : make bools version
 
var string  group_table    = ' Table'
var int     _tblssizedemo  = input.int    ( 10 )
string      tableYpos      = input.string ( 'middle'    , '↕'               , inline = 'place' , group = group_table, options= )
string      tableXpos      = input.string ( 'center'    , '↔'               , inline = 'place' , group = group_table, options= , tooltip='Position on the chart.')
int         _textSize      = input.int    ( 1           , 'Table Text Size' , inline = 'place' , group = group_table)
var matrix  _floatmatrix     = matrix.new  (_tblssizedemo, _tblssizedemo,  0            ) 
var matrix _stringmatrix     = matrix.new (_tblssizedemo, _tblssizedemo,  'test'       ) 
var matrix  _bgcolormatrix    = matrix.new  (_tblssizedemo, _tblssizedemo,  color.white  ) 
var matrix  _textcolormatrix  = matrix.new  (_tblssizedemo, _tblssizedemo,  color.black  ) 
var matrix _tooltipmatrix    = matrix.new (_tblssizedemo, _tblssizedemo,  'tool'       ) 
// basic table ready to go with the aboec matrixes (replace in your code)
//   for demo purpose, random colors, random nums, random na vals
if barstate.islast
    varip _xsize = matrix.rows    (_floatmatrix) -1
    varip _ysize = matrix.columns (_floatmatrix) -1
    for _xis = 0  to _xsize  -1  by 1
        for _yis  = 0 to _ysize  -1 by 1
            _randomr = int(math.random(50,250))
            _randomg = int(math.random(50,250))
            _randomb = int(math.random(50,250))
            _randomt = int(math.random(10,90 ))
            bgcolor  = color.rgb(250 - _randomr, 250 - _randomg, 250 - _randomb, 100 - _randomt )
            txtcolor = color.rgb(_randomr, _randomg, _randomb, _randomt                         )
            matrix.set(_bgcolormatrix    ,_yis,_xis, bgcolor )
            matrix.set(_textcolormatrix  ,_yis,_xis, txtcolor)
            matrix.set(_floatmatrix      ,_yis,_xis, _randomr)
            
            // random na
            _ymiss = math.floor(math.random(0, _yis))
            _xmiss = math.floor(math.random(0, _xis))
            matrix.set( _floatmatrix     ,_ymiss,  _xis, na)
            matrix.set( _stringmatrix    ,_ymiss,  _xis, na)
            matrix.set( _bgcolormatrix   ,_ymiss,  _xis, na)
            matrix.set( _textcolormatrix ,_ymiss,  _xis, na)
            matrix.set( _tooltipmatrix   ,_ymiss,  _xis, na)
// import here
import kaigouthro/matrixautotable/1 as mtxtbl
// and render table.. 
mtxtbl.matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _textcolormatrix, _tooltipmatrix, _textSize   ,tableYpos   ,tableXpos)
 
 matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _textcolormatrix, _tooltipmatrix, _textSize, tableYpos, tableXpos)  matrixtable
  Parameters:
     _floatmatrix :  float vals
     _stringmatrix :  string
     _bgcolormatrix :  color
     _textcolormatrix : color
     _tooltipmatrix :  string
     _textSize : int
     tableYpos : string
     tableXpos : string
 matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _textcolormatrix, _textSize, tableYpos, tableXpos)  matrixtable
  Parameters:
     _floatmatrix :  float vals
     _stringmatrix :  string
     _bgcolormatrix :  color
     _textcolormatrix : color
     _textSize : int
     tableYpos : string
     tableXpos : string
 matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _txtdefcol, _textSize, tableYpos, tableXpos)  matrixtable
  Parameters:
     _floatmatrix :  float vals
     _stringmatrix :  string
     _bgcolormatrix :  color
     _txtdefcol : color
     _textSize : int
     tableYpos : string
     tableXpos : string
 matrixtable(_floatmatrix, _stringmatrix, _txtdefcol, _bgdefcol, _textSize, tableYpos, tableXpos)  matrixtable
  Parameters:
     _floatmatrix :  float vals
     _stringmatrix :  string
     _txtdefcol : color
     _bgdefcol : color
     _textSize : int
     tableYpos : string
     tableXpos : string
 matrixtable(_floatmatrix, _txtdefcol, _bgdefcol, _textSize, tableYpos, tableXpos)  matrixtable
  Parameters:
     _floatmatrix :  float vals
     _txtdefcol : color
     _bgdefcol : color
     _textSize : int
     tableYpos : string
     tableXpos : string
mZigzagLibrary   "mZigzag" 
Matrix implementation of zigzag to allow further possibilities. 
Main advantage of this library over previous zigzag methods is that you can attach any number of indicator/oscillator information to zigzag
 calculate(length, ohlc, indicatorHigh, indicatorLow, numberOfPivots)  calculates zigzag and related information
  Parameters:
     length : is zigzag length
     ohlc : array of OHLC values to be used for zigzag calculation
     indicatorHigh : Array of indicator values calculated based on high price of OHLC
     indicatorLow : Array of indicators values calculated based on low price of OHLC
     numberOfPivots : Number of pivots to be returned
  Returns: pivotMatrix Matrix containing zigzag pivots, pivot bars, direction, ratio, and indicators added via indicatorHigh/indicatorLow
newZG is true if a new pivot is added to array
doubleZG is true if last calculation returned two new pivots (Happens on extreme price change)
 draw(length, ohlc, indicatorLabels, indicatorHigh, indicatorLow, numberOfPivots, lineColor, lineWidth, lineStyle, showHighLow, showRatios, showIndicators)  draws zigzag and related information
  Parameters:
     length : is zigzag length
     ohlc : array of OHLC values to be used for zigzag calculation
     indicatorLabels : Array of name of indicators passed
     indicatorHigh : Array of indicator values calculated based on high price of OHLC
     indicatorLow : Array of indicators values calculated based on low price of OHLC
     numberOfPivots : Number of pivots to be returned
     lineColor : zigzag line color. set to blue by default
     lineWidth : zigzag line width. set to 1 by default
     lineStyle : zigzag line style. set to line.style_solid by default
     showHighLow : show HH, HL, LH, LL labels
     showRatios : show pivot retracement ratios from previous zigzag
     showIndicators : show indicator values
  Returns: pivotMatrix Matrix containing zigzag pivots, pivot bars, direction, ratio, and indicators added via indicatorHigh/indicatorLow
zigzaglines array of zigzag lines
zigzaglabels array of zigzag labels






















