kNNLibrary   "kNN" 
Collection of experimental kNN functions. This is a work in progress, an improvement upon my original kNN script: 
The script can be recreated with this library. Unlike the original script, that used multiple arrays, this has been reworked with the new Pine Script matrix features.
To make a kNN prediction, the following data should be supplied to the wrapper:
 
   kNN : filter type. Right now either  Binary  or  Percent .  Binary  works like in the original script: the system stores whether the price has increased (+1) or decreased (-1) since the previous knnStore event (called when either long or short condition is supplied).  Percent  works the same, but the values stored are the difference of prices in percents. That way larger differences in prices would give higher scores.
   k : number k. This is how many nearest neighbors are to be selected (and summed up to get the result).
   skew : kNN minimum difference. Normally, the prediction is done with a simple majority of the neighbor votes. If  skew  is given, then more than a simple majority is needed for a prediction. This also means that there are inputs for which no prediction would be given (if the majority votes are between -skew and +skew). Note that in  Percent  mode more profitable trades will have higher voting power.
   depth : kNN matrix size limit. Originally, the whole available history of trades was used to make a prediction. This not only requires more computational power, but also neglects the fact that the market conditions are changing. This setting restricts the memory matrix to a finite number of past trades.
   price : price series
   long : long condition. True if the long conditions are met, but filters are not yet applied. For example, in my original script, trades are only made on crossings of fast and slow MAs. So, whenever it is possible to go long, this value is set true. False otherwise.
   short : short condition. Same as  long , but for short condition.
   store : whether the inputs should be stored. Additional filters may be applied to prevent bad trades (for example, trend-based filters), so if you only need to consult kNN without storing the trade, this should be set to false.
   feature1 : current value of feature 1. A feature in this case is some kind of data derived from the price. Different features may be used to analyse the price series. For example, oscillator values. Not all of them may be used for kNN prediction. As the current kNN implementation is 2-dimensional, only two features can be used.
   feature2 : current value of feature 2.
 
The wrapper returns a tuple:  [ longOK, shortOK ]. This is a pair of filters. When  longOK  is true, then kNN predicts a long trade may be taken. When shortOK is true, then kNN predicts a short trade may be taken. The kNN filters are returned whenever long or short conditions are met. The trade is supposed to happen when long or short conditions are met and when the kNN filter for the desired direction is true.
 Exported functions :
 knnStore(knn, p1, p2, src, maxrows) 
  Store the previous trade; buffer the current one until results are in. Results are binary: up/down
  Parameters:
     knn : knn matrix
     p1 : feature 1 value
     p2 : feature 2 value
     src : current price
     maxrows : limit the matrix size to this number of rows (0 of no limit)
  Returns: modified knn matrix
 knnStorePercent(knn, p1, p2, src, maxrows) 
  Store the previous trade; buffer the current one until results are in. Results are in percents
  Parameters:
     knn : knn matrix
     p1 : feature 1 value
     p2 : feature 2 value
     src : current price
     maxrows : limit the matrix size to this number of rows (0 of no limit)
  Returns: modified knn matrix
 knnGet(distance, result) 
  Get neighbours by getting k results with the smallest distances
  Parameters:
     distance : distance array
     result : result array
  Returns: array slice of k results
 knnDistance(knn, p1, p2) 
  Create a distance array from the two given parameters
  Parameters:
     knn : knn matrix
     p1 : feature 1 value
     p2 : feature 2 value
  Returns: distance array
 knnSum(knn, p1, p2, k) 
  Make a prediction, finding k nearest neighbours and summing them up
  Parameters:
     knn : knn matrix
     p1 : feature 1 value
     p2 : feature 2 value
     k : sum k nearest neighbors
  Returns: sum of k nearest neighbors
 doKNN(kNN, k, skew, depth, price, long, short, store, feature1, feature2) 
  execute kNN filter
  Parameters:
     kNN : filter type
     k : number k
     skew : kNN minimum difference
     depth : kNN matrix size limit
     price : series
     long : long condition
     short : short condition
     store : store the supplied features (if false, only checks the results without storage)
     feature1 : feature 1 value
     feature2 : feature 2 value
  Returns:   filter output
MATH
fibo_levelsLibrary   "Fibo_levels" 
Calculate Fibo levels from any 2 levels. Your need know only 2 price of 2 levels for calculate any level of Fibo: function 'fibo_lvl', 
or calculate array of price Fibo levels : function 'fibo_lvls'
 fibo_lvl(fibo_lvl1, price1, fibo_lvl2, price2, calc_level) 
  Parameters:
     fibo_lvl1 : First of any level of fibo from 0 to 1 (example 0.236)
     price1 : Price for 1th any level (example 2356.1)
     fibo_lvl2 : Second of any level of fibo from 0 to 1 (example 0.382)
     price2 : Price for 2th any level (example 2497.4)
     calc_level : Price for level to calculate (example 0.5)
  Returns: return price for calc_level fibo
 fibo_lvls(bars, time1, time2, fibo_lvl1, price1, fibo_lvl2, price1) 
  Parameters:
     fibo_lvl1 : First of any level of fibo from 0 to 1 (example 0.236)
     price1 : Price for 1th any level (example 2356.1)
     fibo_lvl2 : Second of any level of fibo from 0 to 1 (example 0.382)
     price1 : Price for 2th any level (example 2497.4)
  Returns: array of price for fibo levels : (0.0, 0.118, 0.236, 0.384, 0.5, 0.618, 0.786, 1.0, 1.27,-0.27,1.618,-0.618)
LibIndicadoresUteisLibrary   "LibIndicadoresUteis" 
Collection of useful indicators. This collection does not do any type of plotting on the graph, as the methods implemented can and should be used to get the return of mathematical formulas, in a way that speeds up the development of new scripts. The current version contains methods for stochastic return, slow stochastic, IFR, leverage calculation for B3 futures market, leverage calculation for B3 stock market, bollinger bands and the range of change.
 estocastico(PeriodoEstocastico) 
  Returns the value of stochastic
  Parameters:
     PeriodoEstocastico : Period for calculation basis
  Returns: Float with the stochastic value of the period
 estocasticoLento(PeriodoEstocastico, PeriodoMedia) 
  Returns the value of slow stochastic
  Parameters:
     PeriodoEstocastico : Stochastic period for calculation basis
     PeriodoMedia : Average period for calculation basis
  Returns: Float with the value of the slow stochastic of the period
 ifrInvenenado(PeriodoIFR, OrigemIFR) 
  Returns the value of the RSI/IFR Poisoned of Guima
  Parameters:
     PeriodoIFR : RSI/IFR period for calculation basis
     OrigemIFR : Source of RSI/IFR for calculation basis
  Returns: Float with the RSI/IFR value for the period
 calculoAlavancagemFuturos(margem, alavancagemMaxima) 
  Returns the number of contracts to work based on margin
  Parameters:
     margem : Margin for contract unit
     alavancagemMaxima : Maximum number of contracts to work
  Returns: Integer with the number of contracts suggested for trading
 calculoAlavancagemAcoes(alavancagemMaxima) 
  Returns the number of batches to work based on the margin
  Parameters:
     alavancagemMaxima : Maximum number of batches to work
  Returns: Integer with the amount of lots suggested for trading
 bandasBollinger(periodoBB, origemBB, desvioPadrao) 
  Returns the value of bollinger bands
  Parameters:
     periodoBB : Period of bollinger bands for calculation basis
     origemBB : Origin of bollinger bands for calculation basis
     desvioPadrao : Standard Deviation of bollinger bands for calculation basis
  Returns: Two-position array with upper and lower band values respectively
 theRoc(periodoROC, origemROC) 
  Returns the value of Rate Of Change
  Parameters:
     periodoROC : Period for calculation basis
     origemROC : Source of calculation basis
  Returns: Float with the value of Rate Of Change
BpaLibrary   "Bpa" 
TODO: library of Brooks Price Action concepts
 isBreakoutBar(atr, high, low, close, open, tail, size) 
  TODO: check if the bar is a breakout based on the specified conditions
  Parameters:
     atr : TODO: atr value
     high : TODO: high price
     low : TODO: low price
     close : TODO: close price 
     open : TODO: open price
     tail : TODO: decimal value for a percent that represent the size of the tail of the bar that cant be preceeded to be considered strong close
     size : TODO: decimal value for a percent that represents by how much the breakout bar should be bigger than others to be considered one
  Returns: TODO: boolean value, true if breakout bar, false otherwise
TradingWolfLibaryLibrary   "TradingWolfLibary" 
 getMA(int, string) 
  Gets a Moving Average based on type
  Parameters:
     int : length The MA period
     string : maType The type of MA
  Returns: A moving average with the given parameters
 minStop(float, simple, float, string) 
  Calculates and returns Minimum stop loss
  Parameters:
     float : entry price (Close if calculating on the entry candle)
     simple : int Calculate how many bars back to look at swings
     float : Minimum Stop Loss allowed (Should be x 0.01) if input
     string : Direciton of trade either "Long" or "Short"
  Returns: Stop Loss Value
intersectLibrary   "intersect" 
Find Line Intersection X/Y coordinates.
Simple to use, will find intersection if it exists on the segments
if the line segments do not cross on segment, an 'na' value will be returned
if you plot  new items with the output coords,  they still plot.  
avoid this by  setting a na(x)   condition before plotting new items
 get(l1, l2, ( optional _round) ) 
  line intersection coordinates
  Parameters:
     l1 : (line)  first  line
     l2 : (line)  second line
     _round : True to make an INT for plotting
    if not used, will not round ( overload loophole)
  Returns:    with x as int if bool is used
na_skip_highestLibrary   "na_skip_highest" 
Finds the highest historic value over len bars but skip na valued bars (eg, off days). In other words, this will ensure we find the highest value over len bars with a real value, and if there are any na bars in-between, we skip over but the loop will continue. This allows to mimic calculations on markets with off days (eg, weekends).
 na_skip_highest(src, len) 
  Finds the highest historic value over len bars but skip na valued bars (eg, off days). In other words, this will ensure we find the highest value over len bars with a real value, and if there are any na bars in-between, we skip over but the loop will continue. This allows to mimic calculations on markets with off days (eg, weekends).
  Parameters:
     src : series float source (eg, close)
     len : int length, number of recent bars to consider in the window to find the highest value
  Returns: highest float highest value found over the len window
KernelFunctionsLibrary   "KernelFunctions" 
This library provides non-repainting kernel functions for Nadaraya-Watson estimator implementations. This allows for easy substitution/comparison of different kernel functions for one another in indicators. Furthermore, kernels can easily be combined with other kernels to create newer, more customized kernels. Compared to Moving Averages (which are really just simple kernels themselves), these kernel functions are more adaptive and afford the user an unprecedented degree of customization and flexibility.
 rationalQuadratic(_src, _lookback, _relativeWeight, _startAtBar) 
  Rational Quadratic Kernel - An infinite sum of Gaussian Kernels of different length scales.
  Parameters:
     _src :  The source series.
     _lookback :  The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
     _relativeWeight :  Relative weighting of time frames. Smaller values result in a more stretched-out curve, and larger values will result in a more wiggly curve. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel.
     _startAtBar :  Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
  Returns: yhat  The estimated values according to the Rational Quadratic Kernel.
 gaussian(_src, _lookback, _startAtBar) 
  Gaussian Kernel - A weighted average of the source series. The weights are determined by the Radial Basis Function (RBF).
  Parameters:
     _src :  The source series.
     _lookback :  The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
     _startAtBar :  Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
  Returns: yhat  The estimated values according to the Gaussian Kernel.
 periodic(_src, _lookback, _period, _startAtBar) 
  Periodic Kernel - The periodic kernel (derived by David Mackay) allows one to model functions that repeat themselves exactly.
  Parameters:
     _src :  The source series.
     _lookback :  The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
     _period :  The distance between repititions of the function.
     _startAtBar :  Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
  Returns: yhat  The estimated values according to the Periodic Kernel.
 locallyPeriodic(_src, _lookback, _period, _startAtBar) 
  Locally Periodic Kernel - The locally periodic kernel is a periodic function that slowly varies with time. It is the product of the Periodic Kernel and the Gaussian Kernel.
  Parameters:
     _src :  The source series.
     _lookback :  The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
     _period :  The distance between repititions of the function.
     _startAtBar :  Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
  Returns: yhat  The estimated values according to the Locally Periodic Kernel.
ahpuhelperLibrary   "ahpuhelper" 
Helper Library for Auto Harmonic Patterns UltimateX. It is not meaningful for others. This is supposed to be private library. But, publishing it to make sure that I don't delete accidentally. Some functions may be useful for coders.
 insert_open_trades_table_column(showOpenTrades, table_id, column, colors, values, intStatus, harmonicTrailingStartState, lblSizeOpenTrades) 
  add data to open trades table column
  Parameters:
     showOpenTrades : flag to show open trades table
     table_id : Table Id
     column : refers to pattern data
     colors : backgroud and text color array
     values : cell values
     intStatus : status as integer
     harmonicTrailingStartState : trailing Start state as per configs
     lblSizeOpenTrades : text size
  Returns: nextColumn
 populate_closed_stats(ClosedStatsPosition, bullishCounts, bearishCounts, bullishRetouchCounts, bearishRetouchCounts, bullishSizeMatrix, bearishSizeMatrix, bullishRR, bearishRR, allPatternLabels, flags, rowMain, rowHeaders) 
  populate closed stats for harmonic patterns
  Parameters:
     ClosedStatsPosition : Table position for closed stats
     bullishCounts : Matrix containing bullish trade stats
     bearishCounts : Matrix containing bearish trade stats
     bullishRetouchCounts : Matrix containing bullish trade stats for those which retouched entry
     bearishRetouchCounts : Matrix containing bearish trade stats for those which retouched entry
     bullishSizeMatrix : Matrix containing data about size of bullish patterns
     bearishSizeMatrix : Matrix containing data about size of bearish patterns
     bullishRR : Matrix containing Risk Reward data of bullish patterns
     bearishRR : Matrix containing Risk Reward data of bearish patterns
     allPatternLabels : array containing pattern labels
     flags : display flags
     rowMain : Pattern header data
     rowHeaders : header grouping data
  Returns: void
 get_rr_details(patternTradeDetails, harmonicTrailingStartState, disableTrail, breakEvenTrail) 
  calculate and return risk reward based on targets and stops
  Parameters:
     patternTradeDetails : array containing stop, entry and targets
     harmonicTrailingStartState : trailing point
     disableTrail : If set, ignores trailing point
     breakEvenTrail : If set, trailing does not go beyond breakeven.
  Returns: nextColumn
fastlog2Library   "fastlog2" 
 Description: 
Returns the approximation of Log2 with the maximal error of: 0.000061011436
 Reference: 
www.anycodings.com
 fastlog2(x) 
  Returns the approximation of Log2 with the maximal error of: 0.000061011436
  Parameters:
     x : float
  Returns: float, log2 of x
combinLibrary   "combin" 
 Description: 
The combin function is a the combination function 
as it calculates the number of possible combinations for two given numbers.
This function takes two arguments: the number and the number_chosen. 
For example, if the number is 5 and the number chosen is 1, 
there are 5 combinations, giving 5 as a result.
 Reference: 
 ideone.com 
 support.microsoft.com 
 combin(n, kin) 
  Returns the number of combinations for a given number of items. Use to determine the total possible number of groups for a given number of items.
  Parameters:
     n : int, The number of items.
     kin : int, The number of items in each combination.
  Returns: int.
FibonacciLibrary   "Fibonacci" 
General Fibonacci functions. Get fib numbers, ratios, etc.
 fib_precise(f, precision) 
  Get the precise Fibonacci ratio, to the specified number of decimal places
  Parameters:
     f : Fibonacci ratio (string, in form #.###)
     precision : Number of decimal places (optional int, dft = 16, max = 32)
  Returns: Precise Fibonacci ratio (float)
 fib_n(n) 
  Calculate the Nth number in the Fibonacci sequence
  Parameters:
     n : Index/number in sequence (int)
  Returns: Fibonacci number (int)
TrigLibrary   "Trig" 
Trigonometric functions
 rt_get_angleAlpha(a, b, c, deg) 
  Get angle α of a right triangle, given the lengths of its sides
  Parameters:
     a : length of leg a (float)
     b : length of leg b (float)
     c : length of hypotenuse (float)
     deg : flag to return angle in degrees (bool - default = false)
  Returns: angle α in radians (or degrees if deg == true)
 rt_get_angleAlphaFromLine(x1, y1, x2, y2, l, deg) 
  Get angle α of a right triangle formed by the given line
  Parameters:
     x1 : x coordinate 1 (int - optional, required if argument l is not specified)
     y1 : y coordinate 1 (float - optional, required if argument l is not specified)
     x2 : x coordinate 2 (int - optional, required if argument l is not specified)
     y2 : y coordinate 2 (float - optional, required if argument l is not specified)
     l : line object (line - optional, required if x1, y1, x2, and y2 agruments are not specified)
     deg : flag to return angle in degrees (bool - default = false)
  Returns: angle α in radians (or degrees if deg == true)
 rt_get_angleBeta(a, b, c, deg) 
  Get angle β of a right triangle, given the lengths of its sides
  Parameters:
     a : length of leg a (float)
     b : length of leg b (float)
     c : length of hypotenuse (float)
     deg : flag to return angle in degrees (bool - default = false)
  Returns: angle β in radians (or degrees if deg == true)
 rt_get_angleBetaFromLine(x1, y1, x2, y2, l, deg) 
  Get angle β of a right triangle formed by the given line
  Parameters:
     x1 : x coordinate 1 (int - optional, required if argument l is not specified)
     y1 : y coordinate 1 (float - optional, required if argument l is not specified)
     x2 : x coordinate 2 (int - optional, required if argument l is not specified)
     y2 : y coordinate 2 (float - optional, required if argument l is not specified)
     l : line object (line - optional, required if x1, y1, x2, and y2 agruments are not specified)
     deg : flag to return angle in degrees (bool - default = false)
  Returns: angle β in radians (or degrees if deg == true)
AlgebraLibrary   "Algebra" 
Algebra functions.
 line_fromXy(x1, y1, x2, y2) 
  Get line slope and y-intercept from coordinates
  Parameters:
     x1 : x coordinate 1 (int - bar index)
     y1 : y coordinate 1 (float - price/value)
     x2 : x coordinate 2 (int - bar index)
     y2 : y coordinate 2 (float - price/value)
  Returns:   of line
 line_getPrice(x, slope, yInt) 
  Get line slope and y-intercept from coordinates
  Parameters:
     x : x coordinate to solve for y (int - bar index)
     slope : slope of line (float)
     yInt : y-intercept of line (float)
  Returns: y (price/value)
L_BetaLibrary   "L_Beta" 
TODO: add library description here
 length() 
 beta() 
 simple_beta() 
 index_selector()
FunctionLAPACKdsyrkLibrary   "FunctionLAPACKdsyrk" 
subroutine part of LAPACK: Linear Algebra Package, 
performs one of the symmetric rank k operations
.
C := alpha*A*A**T + beta*C,   or    C := alpha*A**T*A + beta*C,
.
where alpha and beta are scalars, C is an n by n symmetric matrix
and A is an n by k matrix in the first case and a k by n matrix
in the second case.
.
reference:
netlib.org
 dsyrk(uplo, trans, n, k, alpha, a, lda, beta, c, ldc) 
  performs one of the symmetric rank k operations
.
C := alpha*A*A**T + beta*C,   or    C := alpha*A**T*A + beta*C,
.
where alpha and beta are scalars, C is an n by n symmetric matrix
and A is an n by k matrix in the first case and a k by n matrix
in the second case.
.
  Parameters:
     uplo : string        specifies whether the upper or lower triangular part of 
the array C  is to be  referenced  as follows:
UPLO = 'U' or 'u'   Only the upper triangular part of  C is to be referenced.
UPLO = 'L' or 'l'   Only the lower triangular part of C is to be referenced.
.
     trans : string        specifies the operation to be performed as follows:
TRANS = 'N' or 'n'   C := alpha*A*A**T + beta*C.
TRANS = 'T' or 't'   C := alpha*A**T*A + beta*C.
TRANS = 'C' or 'c'   C := alpha*A**T*A + beta*C.
.
     n : int           specifies the order of the matrix C. N must be at least zero.
     k : int           On entry with:
TRANS = 'N' or 'n', K specifies the number of  columns   of  the   matrix   A.
TRANS = 'T' or 't' or 'C' or 'c',  K  specifies  the  number of rows of the matrix  A.  
K must be at least zero.
.
     alpha : float         scalar.
     a : matrix matrix A.
     lda : int           specifies the first dimension of A.
     beta : float         scalar.
     c : matrix matrix C, is overwritten by the lower triangular part of the updated matrix.
     ldc : int           specifies the first dimension of C
  Returns: void, C is overwritten by the lower triangular part of the updated matrix.
FunctionLAPACKdtrsmLibrary   "FunctionLAPACKdtrsm" 
subroutine in the LAPACK:linear algebra package, used to solve one of the following matrix equations:
op( A )*X = alpha*B,   or   X*op( A ) = alpha*B,
where alpha is a scalar, X and B are m by n matrices, A is a unit, or
non-unit,  upper or lower triangular matrix  and  op( A )  is one  of
op( A ) = A   or   op( A ) = A**T.
The matrix X is overwritten on B.
reference:
netlib.org
 dtrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb) 
  solves one of the matrix equations
op( A )*X = alpha*B,   or   X*op( A ) = alpha*B,
where alpha is a scalar, X and B are m by n matrices, A is a unit, or
non-unit,  upper or lower triangular matrix  and  op( A )  is one  of
op( A ) = A   or   op( A ) = A**T.
The matrix X is overwritten on B.
  Parameters:
     side : string       , On entry, SIDE specifies whether op( A ) appears on the left or right of X as follows:
SIDE = 'L' or 'l'   op( A )*X = alpha*B.
SIDE = 'R' or 'r'   X*op( A ) = alpha*B.
     uplo : string       , specifies whether the matrix A is an upper or lower triangular matrix as follows:
UPLO = 'U' or 'u'   A is an upper triangular matrix.
UPLO = 'L' or 'l'   A is a lower triangular matrix.
     transa : string       , specifies the form of op( A ) to be used in the matrix multiplication as follows:
TRANSA = 'N' or 'n'   op( A ) = A.
TRANSA = 'T' or 't'   op( A ) = A**T.
TRANSA = 'C' or 'c'   op( A ) = A**T.
     diag : string       , specifies whether or not A is unit triangular as follows:
DIAG = 'U' or 'u'   A is assumed to be unit triangular.
DIAG = 'N' or 'n'   A is not assumed to be unit triangular.
     m : int          , the number of rows of B. M must be at least zero.
     n : int          , the number of columns of B. N must be at least zero.
     alpha : float        , specifies the scalar alpha. When alpha is zero then A is not referenced and B need not be set before entry.
     a : matrix, Triangular matrix.
     lda : int          , specifies the first dimension of A.
     b : matrix, right-hand side matrix B, and on exit is overwritten by the solution matrix X.
     ldb : int          , specifies the first dimension of B.
  Returns: void, modifies matrix b.
usage:
dtrsm ('L', 'U', 'N', 'N', 5, 3, 1.0, a, 7, b, 6)
BoxLine_LibLibrary   "BoxLine_Lib" 
personal Library for line and box built in functions
 lineXY(x) 
   get x1,y1,x2,y2 in a tuple
  Parameters:
     x : TODO: line
  Returns: tuple of x1,y1,x2,y2
 line(x) 
  Create line with only the y1 value(when line == na) or all
when line != na set x1,y1,x2,y2 individually just 1 or all
- use just the line value to set the x2 to current bar or time will set to time
- will auto pick xloc.bar_index or xloc.bar_time if not used
  Parameters:
     x : (line line,int x1,float y1,int x2,float y2,
string xloc,string extend,color color,string style,int width)
  Returns: Line
 boxXY(x) 
   get left,top,right,bottom in a tuple
  Parameters:
     x :  box
  Returns:  tuple of left,top,right,bottom
 box(x) 
  Create line with only the top,bottom value(when line == na) or all
when box != na set left,top,right,bottom individually just 1 or all
- use just the box value to set the right to current bar or time will set to time
- if right is above a number that a bar_index wouldnt be
  Parameters:
     x : box box,int left,float top,int right,
float bottom,color border_color, int border_width, 
string border_style,string extend,string xloc,
color bgcolor,string text,string text_size, color text_color,
string text_halign,string text_valign,string text_wrap)
  Returns: TODO: Box
HelperFunctionsLibrary   "HelperFunctions" 
A collection of my most used functions
 apply_smoothing() 
Apply one of Pine Script's built-in smoothing functions to a series
calcLibrary   "calc" 
Library for math functions. will expand over time.
 split(_sumTotal, _divideBy, _forceMinimum, _haltOnError) 
  Split a large number into integer sized chunks
  Parameters:
     _sumTotal : (int) Total numbert of items
     _divideBy : (int) Groups to make
     _forceMinimum : (bool) force minimum number 1/group
     _haltOnError : (bool) force error if too few groups
  Returns: int  array of items per group
percentageLibLibrary   "percentageLib" 
: every thing need anout percentage
 getPercentage(entry, exit) 
  : get percentage change of of two value
  Parameters:
     entry : : value of entry price
     exit : : value of exit price
  Returns: : negative or positive value
 applyPercentageNoAddUp(price, percentage) 
  : apply percentage change on value decrease or increase
  Parameters:
     price : : value of price
     percentage : : percentage change can be negative or positive 
  Returns: : return only positive value
 applyPercentageAddUp(price, percentage) 
  : apply percentage change on value decrease or increase
  Parameters:
     price : : value of price
     percentage : : percentage change can be negative or positive 
  Returns: : return only positive value
 reversePercentage(percentage) 
  : get percentage (positive or negative) and return the percentage need to back to previous price
  Parameters:
     percentage : : percentage change can be negative or positive 
  Returns: : return positive/negative value
@example : reversePercentage(10) =>11.11111111111111111111111 , reversePercentage(10) =>9.0909090909090909
 getReversePercentage(price, percentage) 
  : get two prices and return the percentage need to back to previous price
  Parameters:
     price : : value of price
     percentage : : percentage change can be negative or positive 
  Returns: : return only positive value
@example : getReversePercentage(100,90) =>11.11111111111111111111111
 multipeBarTotalPercentage()
xor logical operatorLibrary   "xor" 
 xor(a, b) 
  xor: Exclusive or, or exclusive disjunction is a logical operation that is true if and only if its arguments differ (one is true, the other is false).
  Parameters:
     a : first argument
     b : second argument
  Returns: returns xor (true only if a and b are true, but not both)
Example:
true xor true = false
true xor false = true
false xor true = true
false xor false = false
Moving_AveragesLibrary   "Moving_Averages" 
 This library contains majority important moving average functions with int series support. Which means that they can be used with variable length input. For conventional use, please use tradingview built-in ta functions for moving averages as they are more precise. I'll use functions in this library for my other scripts with dynamic length inputs. 
 ema(src, len) 
  Exponential Moving Average (EMA)
  Parameters:
     src : Source
     len : Period
  Returns: Exponential Moving Average with Series Int Support (EMA)
 alma(src, len, a_offset, a_sigma) 
  Arnaud Legoux Moving Average (ALMA)
  Parameters:
     src : Source
     len : Period
     a_offset : Arnaud Legoux offset
     a_sigma : Arnaud Legoux sigma
  Returns: Arnaud Legoux Moving Average (ALMA)
 covwema(src, len) 
  Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
  Parameters:
     src : Source
     len : Period
  Returns: Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
 covwma(src, len) 
  Coefficient of Variation Weighted Moving Average (COVWMA)
  Parameters:
     src : Source
     len : Period
  Returns: Coefficient of Variation Weighted Moving Average (COVWMA)
 dema(src, len) 
  DEMA - Double Exponential Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: DEMA - Double Exponential Moving Average
 edsma(src, len, ssfLength, ssfPoles) 
  EDSMA - Ehlers Deviation Scaled Moving Average
  Parameters:
     src : Source
     len : Period
     ssfLength : EDSMA - Super Smoother Filter Length
     ssfPoles : EDSMA - Super Smoother Filter Poles
  Returns: Ehlers Deviation Scaled Moving Average (EDSMA)
 eframa(src, len, FC, SC) 
  Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
  Parameters:
     src : Source
     len : Period
     FC : Lower Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
     SC : Upper Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
  Returns: Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
 ehma(src, len) 
  EHMA - Exponential Hull Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Exponential Hull Moving Average (EHMA)
 etma(src, len) 
  Exponential Triangular Moving Average (ETMA)
  Parameters:
     src : Source
     len : Period
  Returns: Exponential Triangular Moving Average (ETMA)
 frama(src, len) 
  Fractal Adaptive Moving Average (FRAMA)
  Parameters:
     src : Source
     len : Period
  Returns: Fractal Adaptive Moving Average (FRAMA)
 hma(src, len) 
  HMA - Hull Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Hull Moving Average (HMA)
 jma(src, len, jurik_phase, jurik_power) 
  Jurik Moving Average - JMA
  Parameters:
     src : Source
     len : Period
     jurik_phase : Jurik (JMA) Only - Phase
     jurik_power : Jurik (JMA) Only - Power
  Returns: Jurik Moving Average (JMA)
 kama(src, len, k_fastLength, k_slowLength) 
  Kaufman's Adaptive Moving Average (KAMA)
  Parameters:
     src : Source
     len : Period
     k_fastLength : Number of periods for the fastest exponential moving average
     k_slowLength : Number of periods for the slowest exponential moving average
  Returns: Kaufman's Adaptive Moving Average (KAMA)
 kijun(_high, _low, len, kidiv) 
  Kijun v2
  Parameters:
     _high : High value of bar
     _low : Low value of bar
     len : Period
     kidiv : Kijun MOD Divider
  Returns: Kijun v2
 lsma(src, len, offset) 
  LSMA/LRC - Least Squares Moving Average / Linear Regression Curve
  Parameters:
     src : Source
     len : Period
     offset : Offset
  Returns: Least Squares Moving Average (LSMA)/ Linear Regression Curve (LRC)
 mf(src, len, beta, feedback, z) 
  MF - Modular Filter
  Parameters:
     src : Source
     len : Period
     beta : Modular Filter, General Filter Only - Beta
     feedback : Modular Filter Only - Feedback
     z : Modular Filter Only - Feedback Weighting
  Returns: Modular Filter (MF)
 rma(src, len) 
  RMA - RSI Moving average
  Parameters:
     src : Source
     len : Period
  Returns: RSI Moving average (RMA)
 sma(src, len) 
  SMA - Simple Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Simple Moving Average (SMA)
 smma(src, len) 
  Smoothed Moving Average (SMMA)
  Parameters:
     src : Source
     len : Period
  Returns: Smoothed Moving Average (SMMA)
 stma(src, len) 
  Simple Triangular Moving Average (STMA)
  Parameters:
     src : Source
     len : Period
  Returns: Simple Triangular Moving Average (STMA)
 tema(src, len) 
  TEMA - Triple Exponential Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Triple Exponential Moving Average (TEMA)
 thma(src, len) 
  THMA - Triple Hull Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Triple Hull Moving Average (THMA)
 vama(src, len, volatility_lookback) 
  VAMA - Volatility Adjusted Moving Average
  Parameters:
     src : Source
     len : Period
     volatility_lookback : Volatility lookback length
  Returns: Volatility Adjusted Moving Average (VAMA)
 vidya(src, len) 
  Variable Index Dynamic Average (VIDYA)
  Parameters:
     src : Source
     len : Period
  Returns: Variable Index Dynamic Average (VIDYA)
 vwma(src, len) 
  Volume-Weighted Moving Average (VWMA)
  Parameters:
     src : Source
     len : Period
  Returns: Volume-Weighted Moving Average (VWMA)
 wma(src, len) 
  WMA - Weighted Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Weighted Moving Average (WMA)
 zema(src, len) 
  Zero-Lag Exponential Moving Average (ZEMA)
  Parameters:
     src : Source
     len : Period
  Returns: Zero-Lag Exponential Moving Average (ZEMA)
 zsma(src, len) 
  Zero-Lag Simple Moving Average (ZSMA)
  Parameters:
     src : Source
     len : Period
  Returns: Zero-Lag Simple Moving Average (ZSMA)
 evwma(src, len) 
  EVWMA - Elastic Volume Weighted Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Elastic Volume Weighted Moving Average (EVWMA)
 tt3(src, len, a1_t3) 
  Tillson T3
  Parameters:
     src : Source
     len : Period
     a1_t3 : Tillson T3 Volume Factor
  Returns: Tillson T3
 gma(src, len) 
  GMA - Geometric Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Geometric Moving Average (GMA)
 wwma(src, len) 
  WWMA - Welles Wilder Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Welles Wilder Moving Average (WWMA)
 ama(src, _high, _low, len, ama_f_length, ama_s_length) 
  AMA - Adjusted Moving Average
  Parameters:
     src : Source
     _high : High value of bar
     _low : Low value of bar
     len : Period
     ama_f_length : Fast EMA Length
     ama_s_length : Slow EMA Length
  Returns: Adjusted Moving Average (AMA)
 cma(src, len) 
  Corrective Moving average (CMA)
  Parameters:
     src : Source
     len : Period
  Returns: Corrective Moving average (CMA)
 gmma(src, len) 
  Geometric Mean Moving Average (GMMA)
  Parameters:
     src : Source
     len : Period
  Returns: Geometric Mean Moving Average (GMMA)
 ealf(src, len, LAPercLen_, FPerc_) 
  Ehler's Adaptive Laguerre filter (EALF)
  Parameters:
     src : Source
     len : Period
     LAPercLen_ : Median Length 
     FPerc_ : Median Percentage
  Returns: Ehler's Adaptive Laguerre filter (EALF)
 elf(src, len, LAPercLen_, FPerc_) 
  ELF - Ehler's Laguerre filter
  Parameters:
     src : Source
     len : Period
     LAPercLen_ : Median Length 
     FPerc_ : Median Percentage
  Returns: Ehler's Laguerre Filter (ELF)
 edma(src, len) 
  Exponentially Deviating Moving Average (MZ EDMA)
  Parameters:
     src : Source
     len : Period
  Returns: Exponentially Deviating Moving Average (MZ EDMA)
 pnr(src, len, rank_inter_Perc_) 
  PNR - percentile nearest rank
  Parameters:
     src : Source
     len : Period
     rank_inter_Perc_ : Rank and Interpolation Percentage
  Returns: Percentile Nearest Rank (PNR)
 pli(src, len, rank_inter_Perc_) 
  PLI - Percentile Linear Interpolation
  Parameters:
     src : Source
     len : Period
     rank_inter_Perc_ : Rank and Interpolation Percentage
  Returns: Percentile Linear Interpolation (PLI)
 rema(src, len) 
  Range EMA (REMA)
  Parameters:
     src : Source
     len : Period
  Returns: Range EMA (REMA)
 sw_ma(src, len) 
  Sine-Weighted Moving Average (SW-MA)
  Parameters:
     src : Source
     len : Period
  Returns: Sine-Weighted Moving Average (SW-MA)
 vwap(src, len) 
  Volume Weighted Average Price (VWAP)
  Parameters:
     src : Source
     len : Period
  Returns: Volume Weighted Average Price (VWAP)
 mama(src, len) 
  MAMA - MESA Adaptive Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: MESA Adaptive Moving Average (MAMA)
 fama(src, len) 
  FAMA - Following Adaptive Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Following Adaptive Moving Average (FAMA)
 hkama(src, len) 
  HKAMA - Hilbert based Kaufman's Adaptive Moving Average
  Parameters:
     src : Source
     len : Period
  Returns: Hilbert based Kaufman's Adaptive Moving Average (HKAMA)






















