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)
마켓 지오메트리
HelperFunctionsLibrary   "HelperFunctions" 
A collection of my most used functions
 apply_smoothing() 
Apply one of Pine Script's built-in smoothing functions to a series
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: 
CommonMarkupLibrary   "CommonMarkup" 
Provides functions for chart markup, such as indicating recession bands.
 markRecessionBands(showBands, lineY, labelY) 
  Mark vertical bands and show recession band labels if argument showBands is true. Example "markRecessionBands(bar_index ,3.0"
  Parameters:
     showBands : - show vertical recession bands when true. Functionally equiv to no op when false
     lineY : - y-axis value for line positioning
     labelY : - y-axis value for label positioning
@return true - always answers the value of showBands
divergenceLibrary   "divergence" 
divergence: divergence algorithm with top and bottom kline tolerance
 regular_bull(series, series, simple, simple, simple, simple, simple)  regular_bull: regular bull divergence, lower low src but higher low osc
  Parameters:
     series : float src: the source series
     series : float osc: the oscillator index
     simple : int lbL: look back left
     simple : int lbR: look back right
     simple : int rangeL: min look back range
     simple : int rangeU: max look back range
     simple : int tolerance: the number of tolerant klines
  Returns: array:  
 hidden_bull(series, series, simple, simple, simple, simple, simple)  hidden_bull: hidden bull divergence, higher low src but lower low osc
  Parameters:
     series : float src: the source series
     series : float osc: the oscillator index
     simple : int lbL: look back left
     simple : int lbR: look back right
     simple : int rangeL: min look back range
     simple : int rangeU: max look back range
     simple : int tolerance: the number of tolerant klines
  Returns: array:  
 regular_bear(series, series, simple, simple, simple, simple, simple)  regular_bear: regular bear divergence, higher high src but lower high osc
  Parameters:
     series : float src: the source series
     series : float osc: the oscillator index
     simple : int lbL: look back left
     simple : int lbR: look back right
     simple : int rangeL: min look back range
     simple : int rangeU: max look back range
     simple : int tolerance: the number of tolerant klines
  Returns: array:  
 hidden_bear(series, series, simple, simple, simple, simple, simple)  hidden_bear: hidden bear divergence, lower high src but higher high osc
  Parameters:
     series : float src: the source series
     series : float osc: the oscillator index
     simple : int lbL: look back left
     simple : int lbR: look back right
     simple : int rangeL: min look back range
     simple : int rangeU: max look back range
     simple : int tolerance: the number of tolerant klines
  Returns: array: 
eHarmonicpatternsExtendedLibrary   "eHarmonicpatternsExtended" 
Library provides an alternative method to scan harmonic patterns. This is helpful in reducing iterations. Republishing as new library instead of existing eHarmonicpatterns because I need that copy for existing scripts.
 scan_xab(bcdRatio, err_min, err_max, patternArray)  Checks if bcd ratio is in range of any harmonic pattern
  Parameters:
     bcdRatio : AB/XA ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 scan_abc_axc(abcRatio, axcRatio, err_min, err_max, patternArray)  Checks if abc or axc ratio is in range of any harmonic pattern
  Parameters:
     abcRatio : BC/AB ratio
     axcRatio : XC/AX ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 scan_bcd(bcdRatio, err_min, err_max, patternArray)  Checks if bcd ratio is in range of any harmonic pattern
  Parameters:
     bcdRatio : CD/BC ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 scan_xad_xcd(xadRatio, xcdRatio, err_min, err_max, patternArray)  Checks if xad or xcd ratio is in range of any harmonic pattern
  Parameters:
     xadRatio : AD/XA ratio
     xcdRatio : CD/XC ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 isHarmonicPattern(x, a, b, c, d, flags, errorPercent)  Checks for harmonic patterns
  Parameters:
     x : X coordinate value
     a : A coordinate value
     b : B coordinate value
     c : C coordinate value
     d : D coordinate value
     flags : flags to check patterns. Send empty array to enable all 
     errorPercent : Error threshold
  Returns:   Array of boolean values which says whether valid pattern exist and array of corresponding pattern names
 isHarmonicProjection(x, a, b, c, flags, errorPercent)  Checks for harmonic pattern projection
  Parameters:
     x : X coordinate value
     a : A coordinate value
     b : B coordinate value
     c : C coordinate value
     flags : flags to check patterns. Send empty array to enable all 
     errorPercent : Error threshold
  Returns:   Array of boolean values which says whether valid pattern exist and array of corresponding pattern names.
 get_prz_range(x, a, b, c, patternArray, errorPercent, start_adj, end_adj)  Provides PRZ range based on BCD and XAD ranges
  Parameters:
     x : X coordinate value
     a : A coordinate value
     b : B coordinate value
     c : C coordinate value
     patternArray : Pattern flags for which PRZ range needs to be calculated
     errorPercent : Error threshold
     start_adj : - Adjustments for entry levels
     end_adj : - Adjustments for stop levels
  Returns:   Start and end of consolidated PRZ range
 get_prz_range_xad(x, a, b, c, patternArray, errorPercent, start_adj, end_adj)  Provides PRZ range based on XAD range only
  Parameters:
     x : X coordinate value
     a : A coordinate value
     b : B coordinate value
     c : C coordinate value
     patternArray : Pattern flags for which PRZ range needs to be calculated
     errorPercent : Error threshold
     start_adj : - Adjustments for entry levels
     end_adj : - Adjustments for stop levels
  Returns:   Start and end of consolidated PRZ range
[e2] Drawing Library :: Horizontal Ray█ OVERVIEW
Library   "e2hray" 
A drawing library that contains the hray() function, which draws a horizontal ray/s with an initial point determined by a specified condition. It plots a ray until it reached the price. The function let you control the visibility of historical levels and setup the alerts.
█ HORIZONTAL RAY FUNCTION
 hray(condition, level, color, extend, hist_lines, alert_message, alert_delay, style, hist_style, width, hist_width) 
  Parameters:
     condition : Boolean condition that defines the initial point of a ray
     level : Ray price level.
     color : Ray color.
     extend : (optional) Default value true, current ray levels extend to the right, if false - up to the current bar.
     hist_lines : (optional) Default value true, shows historical ray levels that were revisited, default is dashed lines. To avoid alert problems set to 'false' before creating alerts.
     alert_message : (optional) Default value string(na), if declared, enables alerts that fire when price revisits a line, using the text specified
     alert_delay : (optional) Default value int(0), number of bars to validate the level. Alerts won't trigger if the ray is broken during the 'delay'.
     style : (optional) Default value 'line.style_solid'. Ray line style.
     hist_style : (optional) Default value 'line.style_dashed'. Historical ray line style.
     width : (optional) Default value int(1), ray width in pixels.
     hist_width : (optional) Default value int(1), historical ray width in pixels.
  Returns: void
█ EXAMPLES
 • Example 1. Single horizontal ray from the dynamic input.
 
//@version=5
indicator("hray() example :: Dynamic input ray", overlay = true)
import e2e4mfck/e2hray/1 as e2draw
inputTime = input.time(timestamp("20 Jul 2021 00:00 +0300"), "Date", confirm = true)
inputPrice = input.price(54, 'Price Level', confirm = true)
e2draw.hray(time == inputTime, inputPrice, color.blue, alert_message = 'Ray level re-test!') 
var label mark = label.new(inputTime, inputPrice, 'Selected point to start the ray', xloc.bar_time)
 
  
 • Example 2. Multiple horizontal rays on the moving averages cross. 
 
//@version=5
indicator("hray() example :: MA Cross", overlay = true)
import e2e4mfck/e2hray/1 as e2draw
float sma1 = ta.sma(close, 20)
float sma2 = ta.sma(close, 50)
bullishCross = ta.crossover( sma1, sma2)
bearishCross = ta.crossunder(sma1, sma2)
plot(sma1, 'sma1', color.purple)
plot(sma2, 'sma2', color.blue)
// 1a. We can use 2 function calls to distinguish long and short sides.
e2draw.hray(bullishCross, sma1, color.green, alert_message = 'Bullish Cross Level Broken!', alert_delay = 10)
e2draw.hray(bearishCross, sma2, color.red,   alert_message = 'Bearish Cross Level Broken!', alert_delay = 10)  
// 1b. Or a single call for both.
// e2draw.hray(bullishCross or bearishCross, sma1, bullishCross ? color.green : color.red) 
 
  
 • Example 3. Horizontal ray at the all time highs with an alert.
 
//@version=5
indicator("hray() example :: ATH", overlay = true)
import e2e4mfck/e2hray/1 as e2draw
var float ath = 0, ath := math.max(high, ath)
bool newAth = ta.change(ath)
e2draw.hray(nz(newAth ), high , color.orange, alert_message = 'All Time Highs Tested!', alert_delay = 10)
 
 
FunctionCosineSimilarityLibrary   "FunctionCosineSimilarity" 
Cosine Similarity method.
 function(sample_a, sample_b)  Measure the similarity of 2 vectors.
  Parameters:
     sample_a : float array, values.
     sample_b : float array, values.
  Returns: float.
 diss(cosim)  Dissimilarity helper function.
  Parameters:
     cosim : float, cosine similarity value (0 > 1)
  Returns: float
FunctionPatternDecompositionLibrary   "FunctionPatternDecomposition" 
Methods for decomposing price into common grid/matrix patterns.
 series_to_array(source, length)  Helper for converting series to array.
  Parameters:
     source : float, data series.
     length : int, size.
  Returns: float array.
 smooth_data_2d(data, rate)  Smooth data sample into 2d points.
  Parameters:
     data : float array, source data.
     rate : float, default=0.25, the rate of smoothness to apply.
  Returns: tuple with 2 float arrays.
 thin_points(data_x, data_y, rate)  Thin the number of points.
  Parameters:
     data_x : float array, points x value.
     data_y : float array, points y value.
     rate : float, default=2.0, minimum threshold rate of sample stdev to accept points.
  Returns: tuple with 2 float arrays.
 extract_point_direction(data_x, data_y)  Extract the direction each point faces.
  Parameters:
     data_x : float array, points x value.
     data_y : float array, points y value.
  Returns: float array.
 find_corners(data_x, data_y, rate)  ...
  Parameters:
     data_x : float array, points x value.
     data_y : float array, points y value.
     rate : float, minimum threshold rate of data y stdev.
  Returns: tuple with 2 float arrays.
 grid_coordinates(data_x, data_y, m_size)  transforms points data to a constrained sized matrix format.
  Parameters:
     data_x : float array, points x value.
     data_y : float array, points y value.
     m_size : int, default=10, size of the matrix.
  Returns: flat 2d pseudo matrix.
FunctionGenerateRandomPointsInShapeLibrary   "FunctionGenerateRandomPointsInShape" 
Generate random vector points in geometric shape (parallelogram, triangle)
 random_parallelogram(vector_a, vector_b)  Generate random vector point in a parallelogram shape.
  Parameters:
     vector_a : float array, vector of (x, y) shape.
     vector_b : float array, vector of (x, y) shape.
  Returns: float array, vector of (x, y) shape.
 random_triangle(vector_a, vector_b)  Generate random vector point in a triangle shape.
  Parameters:
     vector_a : float array, vector of (x, y) shape.
     vector_b : float array, vector of (x, y) shape.
  Returns: float array, vector of (x, y) shape.
eHarmonicpatternsLibrary   "eHarmonicpatterns" 
Library provides an alternative method to scan harmonic patterns. This is helpful in reducing iterations
 scan_xab(bcdRatio, err_min, err_max, patternArray)  Checks if bcd ratio is in range of any harmonic pattern
  Parameters:
     bcdRatio : AB/XA ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 scan_abc_axc(abcRatio, axcRatio, err_min, err_max, patternArray)  Checks if abc or axc ratio is in range of any harmonic pattern
  Parameters:
     abcRatio : BC/AB ratio
     axcRatio : XC/AX ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 scan_bcd(bcdRatio, err_min, err_max, patternArray)  Checks if bcd ratio is in range of any harmonic pattern
  Parameters:
     bcdRatio : CD/BC ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 scan_xad_xcd(xadRatio, xcdRatio, err_min, err_max, patternArray)  Checks if xad or xcd ratio is in range of any harmonic pattern
  Parameters:
     xadRatio : AD/XA ratio
     xcdRatio : CD/XC ratio
     err_min : minimum error threshold
     err_max : maximum error threshold
     patternArray : Array containing pattern check flags. Checks are made only if flags are true. Upon check flgs are overwritten.
 isHarmonicPattern(x, a, c, c, d, flags, errorPercent)  Checks for harmonic patterns
  Parameters:
     x : X coordinate value
     a : A coordinate value
     c : B coordinate value
     c : C coordinate value
     d : D coordinate value
     flags : flags to check patterns. Send empty array to enable all 
     errorPercent : Error threshold
  Returns:   Array of boolean values which says whether valid pattern exist and array of corresponding pattern names
 isHarmonicProjection(x, a, c, c, flags, errorPercent)  Checks for harmonic pattern projection
  Parameters:
     x : X coordinate value
     a : A coordinate value
     c : B coordinate value
     c : C coordinate value
     flags : flags to check patterns. Send empty array to enable all 
     errorPercent : Error threshold
  Returns:   Array of boolean values which says whether valid pattern exist and array of corresponding pattern names
FunctionZigZagMultipleMethodsLibrary   "FunctionZigZagMultipleMethods" 
ZigZag Multiple Methods.
 method(idx)  Helper methods enumeration.
  Parameters:
     idx : int, index of method, range 0 to 4.
  Returns: string
 function(method, value_x, value_y)  Multiple method ZigZag.
  Parameters:
     method : string, default='(MANUAL) Percent price move over X * Y', method for zigzag.
     value_x : float, x value in method.
     value_y : float, y value in method.
  Returns: tuple with:
zigzag float
direction
reverse_line float
realtimeofpivot int
harmonicpatternsLibrary   "harmonicpatterns" 
harmonicpatterns: methods required for calculation of harmonic patterns. These are customised to be used in my scripts. But, also simple enough for others to make use of :)
 isGartleyPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isGartleyPattern: Checks for harmonic pattern Gartley
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Gartley. False otherwise.
 isBatPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isBatPattern: Checks for harmonic pattern Bat
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Bat. False otherwise.
 isButterflyPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isButterflyPattern: Checks for harmonic pattern Butterfly
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Butterfly. False otherwise.
 isCrabPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isCrabPattern: Checks for harmonic pattern Crab
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Crab. False otherwise.
 isDeepCrabPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isDeepCrabPattern: Checks for harmonic pattern DeepCrab
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is DeepCrab. False otherwise.
 isCypherPattern(xabRatio, axcRatio, xadRatio, err_min, err_max)  isCypherPattern: Checks for harmonic pattern Cypher
  Parameters:
     xabRatio : AB/XA
     axcRatio : XC/AX
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Cypher. False otherwise.
 isSharkPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isSharkPattern: Checks for harmonic pattern Shark
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Shark. False otherwise.
 isNenStarPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isNenStarPattern: Checks for harmonic pattern Nenstar
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Nenstar. False otherwise.
 isAntiNenStarPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isAntiNenStarPattern: Checks for harmonic pattern Anti NenStar
  Parameters:
     xabRatio : - AB/XA
     abcRatio : - BC/AB
     bcdRatio : - CD/BC
     xadRatio : - AD/XA
     err_min : - Minumum error threshold
     err_max : - Maximum error threshold
  Returns: True if the pattern is Anti NenStar. False otherwise.
 isAntiSharkPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isAntiSharkPattern: Checks for harmonic pattern Anti Shark
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Anti Shark. False otherwise.
 isAntiCypherPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isAntiCypherPattern: Checks for harmonic pattern Anti Cypher
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Anti Cypher. False otherwise.
 isAntiCrabPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isAntiCrabPattern: Checks for harmonic pattern Anti Crab
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Anti Crab. False otherwise.
 isAntiBatPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isAntiBatPattern: Checks for harmonic pattern Anti Bat
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Anti Bat. False otherwise.
 isAntiGartleyPattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isAntiGartleyPattern: Checks for harmonic pattern Anti Gartley
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Anti Gartley. False otherwise.
 isNavarro200Pattern(xabRatio, abcRatio, bcdRatio, xadRatio, err_min, err_max)  isNavarro200Pattern: Checks for harmonic pattern Navarro200
  Parameters:
     xabRatio : AB/XA
     abcRatio : BC/AB
     bcdRatio : CD/BC
     xadRatio : AD/XA
     err_min : Minumum error threshold
     err_max : Maximum error threshold
  Returns: True if the pattern is Navarro200. False otherwise.
 isHarmonicPattern(x, a, c, c, d, flags, errorPercent)  isHarmonicPattern: Checks for harmonic patterns
  Parameters:
     x : X coordinate value
     a : A coordinate value
     c : B coordinate value
     c : C coordinate value
     d : D coordinate value
     flags : flags to check patterns. Send empty array to enable all 
     errorPercent : Error threshold
  Returns:   Array of boolean values which says whether valid pattern exist and array of corresponding pattern names
LinearRegressionLibraryLibrary   "LinearRegressionLibrary"  contains functions for fitting a regression line to the time series by means of different models, as well as functions for estimating the accuracy of the fit.
 Linear regression algorithms: 
 RepeatedMedian(y, n, lastBar)  applies  repeated median regression  (robust linear regression algorithm) to the input time series within the selected interval.
 Parameters: 
 
 y :: float series, source time series (e.g. close)
 n :: integer, the length of the selected time interval
 lastBar :: integer, index of the last bar of the selected time interval (defines the position of the interval)
 
 Output: 
 
 mSlope :: float, slope of the regression line
 mInter  :: float, intercept of the regression line
 
 TheilSen(y, n, lastBar)  applies the  Theil-Sen estimator  (robust linear regression algorithm) to the input time series within the selected interval.
 Parameters: 
 
 y :: float series, source time series 
 n :: integer, the length of the selected time interval
 lastBar :: integer, index of the last bar of the selected time interval (defines the position of the interval)
 
 Output: 
 
 tsSlope :: float, slope of the regression line
 tsInter  :: float, intercept of the regression line
 
 OrdinaryLeastSquares(y, n, lastBar)  applies the  ordinary least squares  regression (non-robust) to the input time series within the selected interval.
 Parameters: 
 
 y :: float series, source time series 
 n :: integer, the length of the selected time interval
 lastBar :: integer, index of the last bar of the selected time interval (defines the position of the interval)
 
 Output: 
 
 olsSlope :: float, slope of the regression line
 olsInter  :: float, intercept of the regression line
 
 Model performance metrics: 
 metricRMSE(y, n, lastBar, slope, intercept)  returns the  Root-Mean-Square Error (RMSE)  of the regression. The better the model, the lower the RMSE.
 Parameters: 
 
 y :: float series, source time series (e.g. close)
 n :: integer, the length of the selected time interval
 lastBar :: integer, index of the last bar of the selected time interval (defines the position of the interval)
 slope :: float, slope of the evaluated linear regression line
 intercept :: float, intercept of the evaluated linear regression line
 
 Output: 
 
 rmse :: float, RMSE value
 
 metricMAE(y, n, lastBar, slope, intercept)  returns the  Mean Absolute Error (MAE)  of the regression. MAE is is similar to RMSE but is less sensitive to outliers. The better the model, the lower the MAE.
 Parameters: 
 
 y :: float series, source time series
 n :: integer, the length of the selected time interval
 lastBar :: integer, index of the last bar of the selected time interval (defines the position of the interval)
 slope :: float, slope of the evaluated linear regression line
 intercept :: float, intercept of the evaluated linear regression line
 
 Output: 
 
 mae :: float, MAE value
 
 metricR2(y, n, lastBar, slope, intercept)  returns the  coefficient of determination (R squared)  of the regression. The better the linear regression fits the data (compared to the sample mean), the closer the value of the R squared is to 1.
 Parameters: 
 
 y :: float series, source time series
 n :: integer, the length of the selected time interval
 lastBar :: integer, index of the last bar of the selected time interval (defines the position of the interval)
 slope :: float, slope of the evaluated linear regression line
 intercept :: float, intercept of the evaluated linear regression line
 
 Output: 
 
  Rsq :: float, R-sqared score
 
 Usage example:
 
//@version=5
indicator('ExampleLinReg', overlay=true)
// import the library
import tbiktag/LinearRegressionLibrary/1 as linreg
// define the studied interval: last 100 bars
int   Npoints  = 100
int   lastBar   = bar_index
int   firstBar  = bar_index - Npoints
// apply repeated median regression to the closing price time series within the specified interval 
{square bracket}slope, intercept{square bracket} = linreg.RepeatedMedian(close, Npoints, lastBar)
// calculate the root-mean-square error of the obtained linear fit
rmse = linreg.metricRMSE(close, Npoints, lastBar, slope, intercept)
// plot the line and print the RMSE value
float y1   = intercept
float y2   = intercept + slope * (Npoints - 1)
if barstate.islast
{indent} line.new(firstBar,y1, lastBar,y2)
{indent} label.new(lastBar,y2,text='RMSE = '+str.format("{0,number,#.#}", rmse))
FunctionGeometricLineDrawingsLibrary   "FunctionGeometricLineDrawings" 
 array_delete_all_lines(lines)  deletes all lines in array.
  Parameters:
     lines : line array, array with line objects to delete.
  Returns: void.
 triangle(sample_x, sample_y, xloc, extend, color, style, width)  Draw a Triangle with 3 vector2D(x, y) coordinates.
  Parameters:
     sample_x : int array, triangle sample data X coordinate values.
     sample_y : float array, triangle sample data Y coordinate values.
     xloc : string, defaultoptions=xloc.bar_index, xloc.bar_time. 
     extend : string, default=extend.none,  options=(extend.none, extend.right, extend.left, extend.both).
     color : color, default= 
     style : options line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_left, line.style_arrow_right, line.style_arrow_both
     width : width in pixels.
  Returns: line array
 trapezoid(sample_x, sample_y, xloc, extend, color, style, width)  Draw a Trapezoid with 4 vector2D(x, y) coordinates:
  Parameters:
     sample_x : int array, trapezoid sample data X coordinate values.
     sample_y : float array, trapezoid sample data Y coordinate values.
     xloc : string, defaultoptions=xloc.bar_index, xloc.bar_time. 
     extend : string, default=extend.none,  options=(extend.none, extend.right, extend.left, extend.both).
     color : color, default= 
     style : options line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_left, line.style_arrow_right, line.style_arrow_both
     width : width in pixels.
  Returns: line array
CreateAndShowZigzagLibrary   "CreateAndShowZigzag" 
Functions in this library creates/updates zigzag array and shows the zigzag
 getZigzag(zigzag, prd, max_array_size)  calculates zigzag using period
	Parameters:
 	 zigzag : is the float array for the zigzag (should be defined like "var zigzag = array.new_float(0)"). each zigzag points contains 2 element: 1. price level of the zz point 2. bar_index of the zz point
	 prd : is the length to calculate zigzag waves by highest(prd)/lowest(prd)
	 max_array_size : is the maximum number of elements in zigzag, keep in mind each zigzag point contains 2 elements, so for example if it's 10 then zigzag has 10/2 => 5 zigzag points  
	Returns: dir that is the current direction of the zigzag
 showZigzag(zigzag, oldzigzag, dir, upcol, dncol)  this function shows zigzag
	Parameters:
 	 zigzag : is the float array for the zigzag (should be defined like "var zigzag = array.new_float(0)"). each zigzag points contains 2 element: 1. price level of the zz point 2. bar_index of the zz point
	 oldzigzag : is the float array for the zigzag, you get copy the zigzag array to oldzigzag by "oldzigzag = array.copy(zigzay)" before calling get_zigzag() function
	 dir : is the direction of the zigzag wave
	 upcol : is the color of the line if zigzag direction is up
	 dncol : is the color of the line if zigzag direction is down 
	Returns: null
LineGetPriceOnLogScaleLibrary   "LineGetPriceOnLogScale" 
This library provides a way to calculate the y-coordinate of a line on a specified bar when the chart scale is Log.
The built-in `line.get_price()` function only works with linear scale and gives incorrect results when the chart is in Log scale.
The library only works with `bar_index` values and `xloc.bar_index`-based lines, `time`-based lines will cause errors to appear.
 coordGetPriceLog(x1, y1, x2, y2, xi)  Calculates the y-coordinate on the specified bar on the logarithmic scale. 
Only coordinates based on bar index are applicable, bar time will throw an error.
	Parameters:
 	 x1 : First X coordinate of a line, index of the bar where the line starts.
	 y1 : First Y coordinate of a line, price on the price scale.
	 x2 : Second X coordinate of a line, index of the bar where the line ends.
	 y2 : Second Y coordinate of a line, price on the price scale.
	 xi : Index of the bar for which the price should be calculated. 
	Returns: Price of the line on the bar specified in `xi`, on the logarithmic scale.
 lineGetPriceLog(_line, xi)  Calculates the y-coordinate on the specified bar for the logarithmic scale. Takes a line.
Only lines drawn based on `xloc.bar_index` are applicable, `xloc.bar_time` will throw and error.
	Parameters:
 	 _line : The line for which the price is calculated.
	 xi : Index of the bar for which the bar should calculate the price. 
	Returns: Price of the line on the bar specified in `xi`, on the logarithmic scale.
MathGeometryCurvesChaikinLibrary   "MathGeometryCurvesChaikin" 
Implements the chaikin algorithm to create a curved path, from assigned points.
 chaikin(points_x, points_y, closed)  Chaikin algorithm method, uses provided points to generate a smoothed path.
	Parameters:
 	 points_x : float array, the x value of points.
	 points_y : float array, the y value of points.
	 closed : bool, default=false, is the path closed or not. 
	Returns: tuple with 2 float arrays.
 smooth(points_x, points_y, iterations, closed)  Iterate the chaikin algorithm, to smooth a sample of points into a curve path.
	Parameters:
 	 points_x : float array, the x value of points.
	 points_y : float array, the y value of points.
	 iterations : int, number of iterations to apply the smoothing.
	 closed : bool, default=false, is the path closed or not. 
	Returns: array of lines.
 draw(path_x, path_y, closed)  Draw the path.
	Parameters:
 	 path_x : float array, the x value of the path.
	 path_y : float array, the y value of the path.
	 closed : bool, default=false, is the path closed or not. 
	Returns: array of lines.
HarmonicPatternLibrary   "HarmonicPattern" 
Functions to detect/check harmonic patterns from provided values.
 line_price_rate(point_c, point_b, point_a)  Compute the price rate of the line AB divided by the the line BC
	Parameters:
 	 point_c : float, the price at point C.
	 point_b : float, the price at point B.
	 point_a : float, the price at point A. 
	Returns: float
 line_time_rate(_c, _b, _a)  Compute the time rate of the line AB divided by the the line BC
	Parameters:
 	 _c : float, the time or bar_index at point C.
	 _b : float, the time or bar_index at point B.
	 _a : float, the time or bar_index at point A. 
	Returns: float
 is_inrange(value, min, max)  Check if value is within min/max range of tolerance.
	Parameters:
 	 value : float, value to check tolerance.
	 min : float, minimum value in range of tolerance.
	 max : float, maximum value in range of tolerance. 
	Returns: bool
 isHarmonicTriangle(rate_cba, margin_of_error)  Check if the rate(s) correspond to pattern ("Harmonic Triangle").
	Parameters:
 	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 is2Tap(rate_cba, margin_of_error)  Check if the rate(s) correspond to pattern ("2Tap", 'Double Top / Bottom').
	Parameters:
 	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 is3Tap(rate_edc, rate_cba, margin_of_error)  Check if the rate(s) correspond to pattern ("3Tap", "Triple Top / Bottom").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 is4Tap(rate_gfe, rate_edc, rate_cba, margin_of_error)  Check if the rate(s) correspond to pattern ("4Tap", "Quadruple Top / Bottom").
	Parameters:
 	 rate_gfe : float, percent rate of the triangle GFE. expects a negative rate.
	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isABCD(rate_cba, rate_dcb, margin_of_error)  Check if the rate(s) correspond to pattern ("AB=CD").
	Parameters:
 	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isBat(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Bat").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isButterfly(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Butterfly").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isGartley(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Gartley").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isCrab(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Crab").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isShark(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Shark").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 is5o(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("5o").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isWolfe(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Wolfe").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 is3Driver(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("3 Driver").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isConTria(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Contracting Triangle").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isExpTria(rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Expanding Triangle").
	Parameters:
 	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
 isHnS(rate_fed, rate_feb, rate_edc, rate_dcb, rate_cba, rate_eda, margin_of_error)  Check if the rate(s) correspond to pattern ("Head and Shoulders").
	Parameters:
 	 rate_fed : float, percent rate of the triangle FED. expects a negative rate.
	 rate_feb : float, percent rate of the triangle FEB. expects a negative rate.
	 rate_edc : float, percent rate of the triangle EDC. expects a negative rate.
	 rate_dcb : float, percent rate of the triangle DCB. expects a negative rate.
	 rate_cba : float, percent rate of the triangle CBA. expects a negative rate.
	 rate_eda : float, percent rate of the triangle EDA. expects a negative rate.
	 margin_of_error : float, percent rate of expected error margin, default 0.05(5%). 
	Returns: bool
Function Square WaveThis is a script to draw a square wave on the chart, with an indicator for current price.
Markets undergoing Dow Jones or Wyckoff Accumulation/Distribution cycles tend to move in such waves, and if the period of the cycles are detected, a signal for accumulation/distribution phases can be created as an early warning.
Useful inputs:
- Average True Range as the wave height.
- Assumed Wave period as the wave duration.
I divided the current price wave by 2 to make the indicator more visually friendly.
GLHF
- DPT
Grid SystemThis script plots a a square composed of 8 equilateral triangles ("grid"). User can set the frequency of calculation/interval by adjusting the 't' parameter. 
Steps for calculating grid: 
1. Find the highest high and lowest low for last 't' periods. 
2. Calculate midpoint for prices during that interval (highest high + lowest low) / 2.
3. Center of the grid = {time , price midpoint}. 
Interpretation: 
 Volatility : If price is volatile for a given period, the area of the grid will expand, since the top and bottom sides are based on the highest high and lowest low for the period. So as range for a given period increases, the grid's area increases.
 Support and resistance : The grid's center line often acts as the support / resistance line. 
 Trend Following : The example chart shows Cognex (CGNX) price using an interval of t=365. When the stock's trend was bullish, the area of the grids became increasingly larger and the y-coordinate of each grid was greater than that of the previous grid. 
[JRL] Murrey Math LinesMurrey Math Lines are support and resistance lines based on geometric mathematical formulas developed by T.
H. Murrey.  MM lines are a derivation of the observations of W.D. Gann.  Murrey's geometry facilitate the use of Gann's theories in a somewhat easier application.  According to Gann's theory, price tends to trend and retrace in 1/8th intervals.  The most important MM line levels are the 0/8, 4/8 and 8/8 levels, which typically provide strong support and resistance points.  The 3/8 and 5/8 levels represent the low and high of the typical trading range.  When price is above the typical trading range, it is considered overbought, and when it is below it is considered oversold. The 2/8 and 6/8 levels provide strong pivot points.
Some of the other Murrey Math indicators on TradingView use different formulas and therefore produce varying results.  I've checked my indicator against MM indicators on other platforms and it is consistent with those indicators.  
This indicator also allows users to switch to alternative timeframes for analysis and it includes labels for the MM lines.  If you have any suggestions or comments, please leave them below.
Cheers! 
[RS]Function - Geometric Line Drawingsfunctions using the new line functions in V4 to draw multiple geometric shapes.






















