PINE LIBRARY
Pattern

Library  "Pattern"
Pattern object definitions and functions. Easily draw and keep track of patterns, legs, and points.
Supported pattern types:
Type Leg validation # legs
"xabcd" Direction 3 or 4 (point D not required)
"zigzag" Direction >= 2
"free" None >= 2
Summary of exported types and associated methods/functions:
type point A point on the chart (x,y)
draw_label() Draw a point label
erase_label() Erase a point label
type leg A pattern leg (i.e. point A to point B)
leg_init() Initialize/instantiate a leg
draw() Draw a leg
erase() Erase a leg
leg_getLineTerms() Get the slope and y-intercept of a leg
leg_getPrice() Get price (Y) at a given bar index (X) within a leg
type pattern A pattern (set of at least 2 connected legs)
pattern_init() Initialize/instantiate a pattern
draw() Draw a pattern
erase() Erase a pattern
*See bottom of the script for example usage*
erase_label(this)
Delete the point label
Parameters:
this (point): Point
Returns: Void
draw_label(this, position, clr, transp, txt_clr, txt, tooltip, size)
Draw the point label
Parameters:
this (point): Point
position (string)
clr (color)
transp (float)
txt_clr (color)
txt (string)
tooltip (string)
size (string)
Returns: line
leg_init(a, b, prev, next, line)
Initialize a pattern leg
Parameters:
a (point): Point A (required)
b (point): Point B (required)
prev (leg): Previous leg
next (leg): Next leg
line (line): Line
Returns: New instance of leg object
erase(this)
Delete the pattern leg
Parameters:
this (leg): Leg
Returns: Void
erase(this)
Delete the pattern lines
Parameters:
this (pattern): Pattern
Returns: Void
draw(this, clr, style, transp, width)
Draw the pattern leg
Parameters:
this (leg): Leg
clr (color): Color
style (string): Style ("solid", "dotted", "dashed", "arrowleft", "arrowright")
transp (float): Transparency
width (int): Width
Returns: line
draw(this, clr, style, transp, width)
Draw the pattern
Parameters:
this (pattern): Pattern
clr (color): Color
style (string): Style ("solid", "dotted", "dashed", "arrowleft", "arrowright")
transp (float): Transparency
width (int): Width
Returns: line[]
leg_getLineTerms(this)
Get the slope and y-intercept of a leg
Parameters:
this (leg): Leg
Returns: [slope, y-intercept]
leg_getPrice(this, index)
Get the price (Y) at a given bar index (X) within the leg
Parameters:
this (leg): Leg
index (int): Bar index
Returns: Price (float)
pattern_init(legs, tp, name, subType, pid)
Initialize a pattern object from a given set of legs
Parameters:
legs (array<leg>): Array of pattern legs (required)
tp (string): Pattern type ("zigzag", "xabcd", or "free". dft = "free")
name (string): Pattern name
subType (string): Pattern subtype
pid (string): Pattern Identifier string
Returns: New instance of pattern object, if one was successfully created
pattern_init(points, tp, name, subType, pid)
Initialize a pattern object from a given set of points
Parameters:
points (array<point>)
tp (string): Pattern type ("zigzag", "xabcd", or "free". dft = "free")
name (string): Pattern name
subType (string): Pattern subtype
pid (string): Pattern Identifier string
Returns: New instance of pattern object, if one was successfully created
point
A point on the chart (x,y)
Fields:
x (series int): Bar index (x coordinate)
y (series float)
label (series label)
leg
A pattern leg (point A to point B)
Fields:
a (point): Point A
b (point)
deltaX (series int)
deltaY (series float)
prev (leg)
next (leg)
retrace (series float)
line (series line)
pattern
A pattern (set of at least 2 connected legs)
Fields:
legs (array<leg>)
type (series string)
subType (series string)
name (series string)
pid (series string)
Pattern object definitions and functions. Easily draw and keep track of patterns, legs, and points.
Supported pattern types:
Type Leg validation # legs
"xabcd" Direction 3 or 4 (point D not required)
"zigzag" Direction >= 2
"free" None >= 2
Summary of exported types and associated methods/functions:
type point A point on the chart (x,y)
draw_label() Draw a point label
erase_label() Erase a point label
type leg A pattern leg (i.e. point A to point B)
leg_init() Initialize/instantiate a leg
draw() Draw a leg
erase() Erase a leg
leg_getLineTerms() Get the slope and y-intercept of a leg
leg_getPrice() Get price (Y) at a given bar index (X) within a leg
type pattern A pattern (set of at least 2 connected legs)
pattern_init() Initialize/instantiate a pattern
draw() Draw a pattern
erase() Erase a pattern
*See bottom of the script for example usage*
erase_label(this)
Delete the point label
Parameters:
this (point): Point
Returns: Void
draw_label(this, position, clr, transp, txt_clr, txt, tooltip, size)
Draw the point label
Parameters:
this (point): Point
position (string)
clr (color)
transp (float)
txt_clr (color)
txt (string)
tooltip (string)
size (string)
Returns: line
leg_init(a, b, prev, next, line)
Initialize a pattern leg
Parameters:
a (point): Point A (required)
b (point): Point B (required)
prev (leg): Previous leg
next (leg): Next leg
line (line): Line
Returns: New instance of leg object
erase(this)
Delete the pattern leg
Parameters:
this (leg): Leg
Returns: Void
erase(this)
Delete the pattern lines
Parameters:
this (pattern): Pattern
Returns: Void
draw(this, clr, style, transp, width)
Draw the pattern leg
Parameters:
this (leg): Leg
clr (color): Color
style (string): Style ("solid", "dotted", "dashed", "arrowleft", "arrowright")
transp (float): Transparency
width (int): Width
Returns: line
draw(this, clr, style, transp, width)
Draw the pattern
Parameters:
this (pattern): Pattern
clr (color): Color
style (string): Style ("solid", "dotted", "dashed", "arrowleft", "arrowright")
transp (float): Transparency
width (int): Width
Returns: line[]
leg_getLineTerms(this)
Get the slope and y-intercept of a leg
Parameters:
this (leg): Leg
Returns: [slope, y-intercept]
leg_getPrice(this, index)
Get the price (Y) at a given bar index (X) within the leg
Parameters:
this (leg): Leg
index (int): Bar index
Returns: Price (float)
pattern_init(legs, tp, name, subType, pid)
Initialize a pattern object from a given set of legs
Parameters:
legs (array<leg>): Array of pattern legs (required)
tp (string): Pattern type ("zigzag", "xabcd", or "free". dft = "free")
name (string): Pattern name
subType (string): Pattern subtype
pid (string): Pattern Identifier string
Returns: New instance of pattern object, if one was successfully created
pattern_init(points, tp, name, subType, pid)
Initialize a pattern object from a given set of points
Parameters:
points (array<point>)
tp (string): Pattern type ("zigzag", "xabcd", or "free". dft = "free")
name (string): Pattern name
subType (string): Pattern subtype
pid (string): Pattern Identifier string
Returns: New instance of pattern object, if one was successfully created
point
A point on the chart (x,y)
Fields:
x (series int): Bar index (x coordinate)
y (series float)
label (series label)
leg
A pattern leg (point A to point B)
Fields:
a (point): Point A
b (point)
deltaX (series int)
deltaY (series float)
prev (leg)
next (leg)
retrace (series float)
line (series line)
pattern
A pattern (set of at least 2 connected legs)
Fields:
legs (array<leg>)
type (series string)
subType (series string)
name (series string)
pid (series string)
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.