lib_plot_objects

library wrapping basic builtin object constructors, to be able to do calculations with points/lines/boxes/triangles/polygons via libraries and on securities. inspired by Trendoscope's (

method assert_same_xloc(a, b, test)
checks two points for compatibility, i.e. having the same xloc
Namespace types: Point
Parameters:
a (Point)
b (Point)
test (Test type from robbatt/lib_unit/6)
method assert_same_xloc(a, b, test)
checks two lines for compatibility, i.e. having the same xloc
Namespace types: Line
Parameters:
a (Line)
b (Line)
test (Test type from robbatt/lib_unit/6)
method or_default(args)
checks args oject for being na, if so, provide a default instead
Namespace types: LineArgs
Parameters:
args (LineArgs)
method or_default(args)
checks args oject for being na, if so, provide a default instead
Namespace types: LabelArgs
Parameters:
args (LabelArgs)
method or_default(args)
checks args oject for being na, if so, provide a default instead
Namespace types: BoxArgs
Parameters:
args (BoxArgs)
method or_default(args)
checks args oject for being na, if so, provide a default instead
Namespace types: BoxTextArgs
Parameters:
args (BoxTextArgs)
method x(point, xloc)
automatically returns the correct x coordinate, based on the point's set xloc
Namespace types: Point
Parameters:
point (Point)
xloc (string)
method tostring(this, date_format)
converts object to json representation
Namespace types: Point
Parameters:
this (Point)
date_format (string)
method tostring(this, date_format)
converts object to json representation
Namespace types: Point[]
Parameters:
this (Point[])
date_format (string)
method tostring(this)
converts object to json representation
Namespace types: LineArgs
Parameters:
this (LineArgs)
method tostring(this, date_format)
converts object to json representation
Namespace types: Line
Parameters:
this (Line)
date_format (string)
method tostring(this)
Namespace types: LabelArgs
Parameters:
this (LabelArgs)
method tostring(this, date_format)
Namespace types: Label
Parameters:
this (Label)
date_format (string)
method tostring(this, date_format)
Namespace types: LineFill
Parameters:
this (LineFill)
date_format (string)
method tostring(this)
Namespace types: BoxArgs
Parameters:
this (BoxArgs)
method tostring(this)
Namespace types: BoxTextArgs
Parameters:
this (BoxTextArgs)
method tostring(this, date_format)
Namespace types: Box
Parameters:
this (Box)
date_format (string)
method tostring(this, date_format)
Namespace types: Triangle
Parameters:
this (Triangle)
date_format (string)
method tostring(this, date_format)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
date_format (string)
method tostring(this, date_format)
Namespace types: Polygon
Parameters:
this (Polygon)
date_format (string)
method tostring(this, date_format)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
date_format (string)
method tostring(this, date_format)
Namespace types: Line[]
Parameters:
this (Line[])
date_format (string)
method tostring(this, date_format)
Namespace types: Box[]
Parameters:
this (Box[])
date_format (string)
method tostring(this, date_format)
Namespace types: Triangle[]
Parameters:
this (Triangle[])
date_format (string)
method tostring(this, date_format)
Namespace types: Polygon[]
Parameters:
this (Polygon[])
date_format (string)
method tostring(this, date_format)
Namespace types: PolygonFill[]
Parameters:
this (PolygonFill[])
date_format (string)
method create_center(points)
Namespace types: Point[]
Parameters:
points (Point[])
method create_center(this, other)
Namespace types: Point
Parameters:
this (Point)
other (Point)
method create_center(this)
Namespace types: Line
Parameters:
this (Line)
method create_line(this, other, args)
Namespace types: Point
Parameters:
this (Point)
other (Point)
args (LineArgs)
method create_triangle(this, b, c, args)
Namespace types: Point
Parameters:
this (Point)
b (Point)
c (Point)
args (LineArgs)
method create_triangle(this, c)
Namespace types: Line
Parameters:
this (Line)
c (Point)
method create_box(this, other, txt, args, text_args)
Namespace types: Point
Parameters:
this (Point)
other (Point)
txt (string)
args (BoxArgs)
text_args (BoxTextArgs)
method create_box(this, txt, args, text_args)
Namespace types: Line
Parameters:
this (Line)
txt (string)
args (BoxArgs)
text_args (BoxTextArgs)
method create_polygon(points, args)
Namespace types: Point[]
Parameters:
points (Point[])
args (LineArgs)
method create_polygon(start, others, args)
Namespace types: Point
Parameters:
start (Point)
others (Point[])
args (LineArgs)
method create_fill(this, other, fill_color)
Namespace types: Line
Parameters:
this (Line)
other (Line)
fill_color (color)
method create_fill(this, fill_color)
Namespace types: Triangle
Parameters:
this (Triangle)
fill_color (color)
method create_fill(this, fill_color)
Namespace types: Polygon
Parameters:
this (Polygon)
fill_color (color)
method create_label(this, txt, args, tooltip)
Namespace types: Point
Parameters:
this (Point)
txt (string)
args (LabelArgs)
tooltip (string)
method create_label(this, txt, args, tooltip)
Namespace types: Line
Parameters:
this (Line)
txt (string)
args (LabelArgs)
tooltip (string)
method create_label(this, txt, args, tooltip)
Namespace types: Box
Parameters:
this (Box)
txt (string)
args (LabelArgs)
tooltip (string)
method create_label(this, txt, args, tooltip)
Namespace types: Triangle
Parameters:
this (Triangle)
txt (string)
args (LabelArgs)
tooltip (string)
method create_label(this, txt, args, tooltip)
Namespace types: Polygon
Parameters:
this (Polygon)
txt (string)
args (LabelArgs)
tooltip (string)
method update(this, bar_time, bar_idx, price)
Namespace types: Point
Parameters:
this (Point)
bar_time (int)
bar_idx (int)
price (float)
method update(this, update)
Namespace types: Point
Parameters:
this (Point)
update (Point)
method update(this, point)
Namespace types: Label
Parameters:
this (Label)
point (Point)
method update(this, start, end)
Namespace types: Line
Parameters:
this (Line)
start (Point)
end (Point)
method update(this, left_top, right_bottom)
Namespace types: Box
Parameters:
this (Box)
left_top (Point)
right_bottom (Point)
method update(this, a, b, c)
Namespace types: Triangle
Parameters:
this (Triangle)
a (Point)
b (Point)
c (Point)
method update(this, points)
Namespace types: Polygon
Parameters:
this (Polygon)
points (Point[])
method delete(this)
Namespace types: Line
Parameters:
this (Line)
method delete(this)
Namespace types: Label
Parameters:
this (Label)
method delete(this)
Namespace types: LineFill
Parameters:
this (LineFill)
method delete(this)
Namespace types: Box
Parameters:
this (Box)
method delete(this)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
method delete(this)
Namespace types: Triangle
Parameters:
this (Triangle)
method delete(this)
Namespace types: Polygon
Parameters:
this (Polygon)
method delete(this)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
method delete(this)
Namespace types: Line[]
Parameters:
this (Line[])
method delete(this)
Namespace types: Label[]
Parameters:
this (Label[])
method delete(this)
Namespace types: LineFill[]
Parameters:
this (LineFill[])
method delete(this)
Namespace types: Box[]
Parameters:
this (Box[])
method delete(this)
Namespace types: TriangleFill[]
Parameters:
this (TriangleFill[])
method delete(this)
Namespace types: Polygon[]
Parameters:
this (Polygon[])
method delete(this)
Namespace types: Triangle[]
Parameters:
this (Triangle[])
method delete(this)
Namespace types: PolygonFill[]
Parameters:
this (PolygonFill[])
method draw(this)
Namespace types: Label
Parameters:
this (Label)
method draw(this)
Namespace types: Line
Parameters:
this (Line)
method draw(this)
Namespace types: Box
Parameters:
this (Box)
method draw(this)
Namespace types: Triangle
Parameters:
this (Triangle)
method draw(this)
Namespace types: Polygon
Parameters:
this (Polygon)
method draw(this)
Namespace types: LineFill
Parameters:
this (LineFill)
method draw(this)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
method draw(this)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
Point
Fields:
bar_time (series int): time based x coordinate
bar_idx (series int): bar index based x coordinate
price (series float): price based y coordinate
xloc (series string): To select if x coordinate is represented by bar_idx or bar_time. Possible values: xloc.bar_index and xloc.bar_time. Default is xloc.bar_index.
LabelArgs
Fields:
text_color (series color): Text color.
bg_color (series color): Color of the label border and arrow.
text_font_family (series string): The font family of the text. Optional. The default value is font.family_default. Possible values: font.family_default, font.family_monospace.
yloc (series string): Possible values are yloc.price, yloc.abovebar, yloc.belowbar. If yloc=yloc.price, y argument specifies the price of the label position. If yloc=yloc.abovebar, label is located above bar. If yloc=yloc.belowbar, label is located below bar. Default is yloc.price.
style (series string): Label style. Possible values: label.style_none, label.style_xcross, label.style_cross, label.style_triangleup, label.style_triangledown, label.style_flag, label.style_circle, label.style_arrowup, label.style_arrowdown, label.style_label_up, label.style_label_down, label.style_label_left, label.style_label_right, label.style_label_lower_left, label.style_label_lower_right, label.style_label_upper_left, label.style_label_upper_right, label.style_label_center, label.style_square, label.style_diamond, label.style_text_outline. Default is label.style_label_down.
size (series string): Label size. Possible values: size.auto, size.tiny, size.small, size.normal, size.large, size.huge. Default value is size.normal.
text_align (series string): Label text alignment. Possible values: text.align_left, text.align_center, text.align_right. Default value is text.align_center.
Label
Fields:
point (Point): The Label coordinates
txt (series string): Label text. Default is empty string.
args (LabelArgs): Wrapper for reusable arguments for label.new()
tooltip (series string): Hover to see tooltip label.
plot (series label): The label object to be added and plotted via draw()
LineArgs
Fields:
line_color (series color): Line color.
style (series string): Line style. Possible values: line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_left, line.style_arrow_right, line.style_arrow_both.
width (series int): Line width in pixels.
extend (series string): f extend=extend.none, draws segment starting at point (x1, y1) and ending at point (x2, y2). If extend is equal to extend.right or extend.left, draws a ray starting at point (x1, y1) or (x2, y2), respectively. If extend=extend.both, draws a straight line that goes through these points. Default value is extend.none.
Line
Fields:
start (Point): starting point of the line
end (Point)
args (LineArgs): Wrapper for reusable arguments for line.new()
plot (series line): The line object to be added and plotted via draw()
LineFill
Fields:
a (Line): The first Line object
b (Line): The second Line object
fill_color (series color): The color used to fill the space between the lines.
plot (series linefill): The linefill object to be added and plotted via draw()
BoxArgs
Fields:
border_color (series color): Color of the four borders. Optional. The default is color.blue.
border_width (series int): Width of the four borders, in pixels. Optional. The default is 1 pixel.
border_style (series string): Style of the four borders. Possible values: line.style_solid, line.style_dotted, line.style_dashed. Optional. The default value is line.style_solid.
bg_color (series color): Background color of the box. Optional. The default is color.blue.
extend (series string): When extend.none is used, the horizontal borders start at the left border and end at the right border. With extend.left or extend.right, the horizontal borders are extended indefinitely to the left or right of the box, respectively. With extend.both, the horizontal borders are extended on both sides. Optional. The default value is extend.none.
BoxTextArgs
Fields:
text_color (series color): The color of the text. Optional. The default is color.black.
text_size (series string): The size of the text. An optional parameter, the default value is size.auto. Possible values: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
text_halign (series string): The horizontal alignment of the box's text. Optional. The default value is text.align_center. Possible values: text.align_left, text.align_center, text.align_right.
text_valign (series string): The vertical alignment of the box's text. Optional. The default value is text.align_center. Possible values: text.align_top, text.align_center, text.align_bottom.
text_wrap (series string): Defines whether the text is presented in a single line, extending past the width of the box if necessary, or wrapped so every line is no wider than the box itself (and clipped by the bottom border of the box if the height of the resulting wrapped text is higher than the height of the box). Optional. The default value is text.wrap_none. Possible values: text.wrap_none, text.wrap_auto.
text_font_family (series string): The font family of the text. Optional. The default value is font.family_default. Possible values: font.family_default, font.family_monospace.
Box
Fields:
left_top (Point): top-left corner of the box
right_bottom (Point): bottom-right corner of the box
txt (series string): The text to be displayed inside the box. Optional. The default is empty string.
args (BoxArgs): Wrapper for reusable arguments for box.new()
text_args (BoxTextArgs)
plot (series box): The box object to be added and plotted via draw()
Triangle
Fields:
a (Point): first Corner
b (Point): second Corner
c (Point): third Corner
args (LineArgs): Wrapper for reusable arguments for line.new()
plot_ab (series line): The line object to be added and plotted via draw()
plot_ac (series line): The line object to be added and plotted via draw()
plot_bc (series line): The line object to be added and plotted via draw()
TriangleFill
Fields:
triangle (Triangle): The Triangle object
fill_color (series color): The color used to fill the space between the lines.
plot (series linefill): The linefill object to be added and plotted via draw()
Polygon
Fields:
points (Point[]): array of points that make up the Polygon
center (Point): Center point of the Polygon, can be used for a label and will be center for PolygonFill
args (LineArgs): Wrapper for reusable arguments for line.new()
plot (line[]): An array of Lines that form Polygon Border
PolygonFill
Fields:
poly (Polygon): the Polygon
fill_color (series color): The color used to fill the space between the lines.
plot_segments (line[]): An array of helper lines to create linefills
plot_fills (linefill[]): An array of linefills that cover the Polygon surface
Added:
method set_line_color(this, value)
Namespace types: LineArgs
Parameters:
this (LineArgs)
value (color)
method set_style(this, value)
Namespace types: LabelArgs
Parameters:
this (LabelArgs)
value (string)
method set_width(this, width)
Namespace types: LineArgs
Parameters:
this (LineArgs)
width (int)
method set_extend(this, extend)
Namespace types: LineArgs
Parameters:
this (LineArgs)
extend (string)
method set_text_color(this, value)
Namespace types: LabelArgs
Parameters:
this (LabelArgs)
value (color)
method set_bg_color(this, value)
Namespace types: LabelArgs
Parameters:
this (LabelArgs)
value (color)
method set_yloc(this, yloc)
Namespace types: LabelArgs
Parameters:
this (LabelArgs)
yloc (string)
method set_size(this, value)
Namespace types: LabelArgs
Parameters:
this (LabelArgs)
value (string)
Updated:
method draw(this)
Added:
method apply_style(this, args, text_args)
Added:
method is_green(this)
Namespace types: Candle
Parameters:
this (Candle)
method is_red(this)
Namespace types: Candle
Parameters:
this (Candle)
method is_bullish(this)
Namespace types: Candle
Parameters:
this (Candle)
method is_bearish(this)
Namespace types: Candle
Parameters:
this (Candle)
method total_size(this)
Namespace types: Candle
Parameters:
this (Candle)
method body_size(this)
Namespace types: Candle
Parameters:
this (Candle)
method wick_size_top(this)
Namespace types: Candle
Parameters:
this (Candle)
method wick_size_bottom(this)
Namespace types: Candle
Parameters:
this (Candle)
method body_total_ratio(this)
Namespace types: Candle
Parameters:
this (Candle)
create_candle(t, idx, o, h, l, c)
Parameters:
t (int)
idx (int)
o (float)
h (float)
l (float)
c (float)
Candle
Fields:
bar_time (series int): time based x coordinate
bar_idx (series int): bar index based x coordinate
o (series float): candle open price
h (series float): candle highest price
l (series float): candle lowest price
c (series float): candle close price
added enqueue functions for objects with max amount of items and auto-removal of excess items
Added:
method create_center_label(this, txt, args, tooltip)
Namespace types: Line
Parameters:
this (Line)
txt (string)
args (LabelArgs)
tooltip (string)
CenterLabel
Fields:
points (Point[]): The coordinates around the center
center_label (Label): The generated, centered Label
Updated:
LineFill
Fields:
a (Line): The first Line object
b (Line): The second Line object
fill_color (series color): The color used to fill the space between the lines.
plot (series linefill): The linefill object to be added and plotted via draw()
support (Line)
Added:
method extend_to(this, end_time, end_idx, end_price)
Namespace types: Line
Parameters:
this (Line)
end_time (int)
end_idx (int)
end_price (float)
Added:
method nz(this, default)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
default (PolygonFill)
Updated:
create_line(start_time, start_idx, start_price, end_time, end_idx, end_price, xloc, args)
Parameters:
start_time (int)
start_idx (int)
start_price (float)
end_time (int)
end_idx (int)
end_price (float)
xloc (string)
args (LineArgs)
create_box(left_time, left_idx, top, right_time, right_idx, bottom, xloc, txt, args, text_args)
Parameters:
left_time (int)
left_idx (int)
top (float)
right_time (int)
right_idx (int)
bottom (float)
xloc (string)
txt (string)
args (BoxArgs)
text_args (BoxTextArgs)
revert to this version for Triangles and Polygons, will be extracted to lib_plot_composite_objects
method hide(this)
Namespace types: Box
Parameters:
this (Box)
Updated:
method create_fill(this, other, fill_color, flip)
LineFill
Fields:
a (Line): The first Line object
b (Line): The second Line object
fill_color (series color): The color used to fill the space between the lines.
flip_support (Line): An additional Line that holds a flipped b support line (linefills are always drawn between line starts and line ends)
plot (series linefill): The linefill object to be added and plotted via draw()
See problem here:

- set default colors to fixed values instead of chart.fg_color (created issues when used via securities)
- added wrapper for polyline -> Polyline (however, polyline is lacking setters, so there's not much performance gain, points cannot be replaced, requires redraw when updating it)
- added speed optimization 'needs_redraw' flag to address polyline's lacking selective update, and to reduce all plots to absolute minimum (needs to be triggered explicitly). But composite objects like CenterLabel can infer redraw requirement from source object (as long as it isn't reset via draw() before the CenterLabel.update() call)
- replaced CenterLabel.points with source_line and source_polyline (either or can be set and will be used to update the point of the center_label)
- added methods around PolyLine (create_center_label, create_center, create_polyline, enqueue, delete
- added force_redraw parameter to all draw() functions to override needs_redraw
- removed setters for most objects, just use the direct assignment, save some lib size and context switching on function call
- removed object inspection part, i.e. tostring() functions, just bloatware for this lib
- removed workaround for chart.point.now() and chart.point.new() that returned the same chart.point instance on different calls when initialized with the same coordinates. TV fixed it, thank you guys!
- refactored LineFill draw(), will only draw if one line component has needs_redraw
Added:
method create_polyline(this, curved, closed, args)
Namespace types: array<chart.point>
Parameters:
this (array<chart.point>)
curved (bool)
closed (bool)
args (PolyLineArgs)
PolyLineArgs
Fields:
line_color (series color): The color of the line segments. Optional. The default is color.gray.
fill_color (series color): The fill color of the polyline. Optional. The default is na.
style (series string): The style of the polyline. Possible values: line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_left, line.style_arrow_right, line.style_arrow_both. Optional. The default is line.style_solid.
width (series int): The width of the line segments, expressed in pixels. Optional. The default is 1.
xloc (series string): Determines the field of the chart.point objects in the points array that the polyline will use for its x-coordinates. If xloc.bar_index, the polyline will use the index field from each point. If xloc.bar_time, it will use the time field. Optional. The default is xloc.bar_index.
PolyLine
Fields:
points (array<chart.point>): point array data of the polyline
curved (series bool): Line color. If true, the drawing will connect all points from the points array using curved line segments. Optional. The default is false.
closed (series bool): Line color. If true, the drawing will also connect the first point to the last point from the points array, resulting in a closed polyline. Optional. The default is false.
args (PolyLineArgs): Wrapper for reusable arguments for line.new()
needs_redraw (series bool)
plot (series polyline): The polyline object to be added and plotted via draw()
Updated:
method create_center(this)
Namespace types: PolyLine
Parameters:
this (PolyLine)
method create_center_label(this, txt, args, tooltip)
Creates a new Label object.
Namespace types: PolyLine
Parameters:
this (PolyLine)
txt (string)
args (LabelArgs)
tooltip (string)
method enqueue(id, item, max)
Namespace types: array<PolyLine>
Parameters:
id (array<PolyLine>)
item (PolyLine)
max (int)
CenterLabel
Fields:
center_label (Label): The generated, centered Label
source_line (Line)
source_polyline (PolyLine)
needs_redraw (series bool)
Removed:
- method set_line_color(this, value)
- method set_style(this, value)
- method set_width(this, width)
- method set_extend(this, extend)
- method set_txt_color(this, value)
- method set_bg_color(this, value)
- method set_yloc(this, yloc)
- method set_size(this, value)
- method tostring(this, date_format)
- create_point_var(id, bar_time, bar_idx, price)
Added:
method calculate_center(this)
Namespace types: PolyLine
Parameters:
this (PolyLine)
Usage:
if barstate.isnew
mylabel.update(time, bar_index, close) // update only when needed
mylabel.draw() // set/update coordinates every iteration
Updated:
create_label(txt, args, tooltip, init_plot, force_overlay)
Parameters:
txt (string)
args (LabelArgs)
tooltip (string)
init_plot (bool)
force_overlay (bool)
method create_center_label(this, txt, args, tooltip, init_plot, force_overlay)
Creates a new Label object.
Namespace types: PolyLine
Parameters:
this (PolyLine)
txt (string)
args (LabelArgs)
tooltip (string)
init_plot (bool)
force_overlay (bool)
create_line(args, init_plot, force_overlay)
Parameters:
args (LineArgs)
init_plot (bool)
force_overlay (bool)
method create_polyline(this, curved, closed, args, init_plot, force_overlay)
Namespace types: array<chart.point>
Parameters:
this (array<chart.point>)
curved (bool)
closed (bool)
args (PolyLineArgs)
init_plot (bool)
force_overlay (bool)
create_box(txt, args, text_args, init_plot, force_overlay)
Parameters:
txt (string)
args (BoxArgs)
text_args (BoxTextArgs)
init_plot (bool)
force_overlay (bool)
method create_fill(this, other, fill_color, flip, init_flip_plot, force_overlay)
Namespace types: Line
Parameters:
this (Line)
other (Line)
fill_color (color)
flip (bool)
init_flip_plot (bool)
force_overlay (bool)
Added:
method deep_copy(this)
Updated:
method deep_copy(this, copy_references)
Namespace types: LineFill
Parameters:
this (LineFill)
copy_references (bool)
LineFill
Fields:
flip_support_force_overlay (series bool) // required on initialization so deep_copy can pass it to the flip_support Line plot
- updated to pine v6
- hide(): skipped drawing (updating chart object) if it has not been drawn yet, added example (b3)
Added:
Label / Line / PolyLine / Box
Fields:
hidden (series bool)
Added:
create_point(x, price, xloc)
Creates a new chart.point based on xloc switch
Parameters:
x (int)
price (float)
xloc (string)
Pine Bibliothek
Ganz im Sinne von TradingView hat dieser Autor seinen/ihren Pine Code als Open-Source-Bibliothek veröffentlicht. Auf diese Weise können nun auch andere Pine-Programmierer aus unserer Community den Code verwenden. Vielen Dank an den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Veröffentlichungen verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert.
Haftungsausschluss
Pine Bibliothek
Ganz im Sinne von TradingView hat dieser Autor seinen/ihren Pine Code als Open-Source-Bibliothek veröffentlicht. Auf diese Weise können nun auch andere Pine-Programmierer aus unserer Community den Code verwenden. Vielen Dank an den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Veröffentlichungen verwenden. Die Nutzung dieses Codes in einer Veröffentlichung wird in unseren Hausregeln reguliert.