robbatt

lib_plot_objects

robbatt מעודכן   
Library "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 (and www.tradingview.com/...BFaR-DrawingMethods/) with added update mechanism to not have to recreate objects on every iteration for continously drawn items, automated xloc selection for coordinates, compatibility check for Points, added Triangle and Polygon types, object reflection via tostring to valid json (logging via webhook)

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
הערות שחרור:
v2 added fallback for update functions, if no Point defined in composite objects, first update will set it
הערות שחרור:
v3 added setters for LineArgs and LabelArgs

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)
הערות שחרור:
v4 added method to update label text
הערות שחרור:
v5 add draw methods for arrays of all elements

Updated:
method draw(this)
הערות שחרור:
v6 speed optimization, converted date_format string param to simple string
הערות שחרור:
v7 additional tostring methods
הערות שחרור:
v8 added methods to batch update styles of recycled objects via apply_style and LineArgs/LabelArgs/BoxArgs parameters, affects only style and colors

Added:
method apply_style(this, args, text_args)
הערות שחרור:
v9 added additional na checks for draw methods
הערות שחרור:
v10 added delete methods for builtin object arrays
הערות שחרור:
v11 added Candle data and functions

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
הערות שחרור:
v12 added Candle.direction()
הערות שחרור:
v13 added CenterLabel, with reference to a set of points and auto-updated generated center point
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
הערות שחרור:
v14 export enqueue functions
הערות שחרור:
v15 added update of generated center point into draw function of CenterLabel for convenience
הערות שחרור:
v16 fixed error in Candle.tostring()
הערות שחרור:
v17 fixed LineFill to create support line for fills between continuous line patterns (end of first is start of next line, where both lines for a linefill should be originating from the same point / headed in the same direction)

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)
הערות שחרור:
v18 removed debugging plot
הערות שחרור:
v19 added enqueue() for Point
הערות שחרור:
v20 added volume (v) to Candles
הערות שחרור:
v21 added time_close to Candle
הערות שחרור:
v22 added body_top and body_bottom
הערות שחרור:
v23

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)
הערות שחרור:
v24 added nz methods for all object types, providing null objects. added default values to Point/Candle, added methods to create Line and Box from coordinates

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)
הערות שחרור:
v25 added default param extend_only:true to draw() methods for Lines' x1 and Boxes' left edge coordinates, which prevents accessing old bar_indexes for drawing and therefore triggering max_bars_back errors.
הערות שחרור:
v26 replaced custom Point type with new builtin chart.point
revert to this version for Triangles and Polygons, will be extracted to lib_plot_composite_objects
הערות שחרור:
v27 extracted Triangle and Polygon functions to separate lib_plot_composite_objects due to size limitations in recent projects
הערות שחרור:
v28 exporting extra draw function for builtin line objects
הערות שחרור:
v29 updated demo, fixed some chart.point related issues
הערות שחרור:
v30 updated batch drawing methods
הערות שחרור:
v31 - added some na checks
הערות שחרור:
v32 enhanced create_fill() to take an optional support line for triangle creation via chart.points
הערות שחרור:
v33 added hide methods, refactored plotting support lines for LineFills
method hide(this)
  Namespace types: Box
  Parameters:
    this (Box)
הערות שחרור:
v34 Renamed set_text_color to set_txt_color to avoid overload warning
הערות שחרור:
v35 fixed fill not extended for Linefills that require a support line
הערות שחרור:
v36 refactored support for flipped line direction in linefill.

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:
ספריית Pine

ברוח TradingView אמיתית, המחבר פרסם את קוד Pine זה כספריית קוד פתוח כך שמתכנתי Pine אחרים מהקהילה שלנו יוכלו לעשות בו שימוש חוזר. כל הכבוד למחבר! אתה יכול להשתמש בספרייה זו באופן פרטי או בפרסומים אחרים בקוד פתוח, אך השימוש החוזר בקוד זה בפרסום כפוף לכללי הבית.

כתב ויתור

המידע והפרסומים אינם אמורים להיות, ואינם מהווים, עצות פיננסיות, השקעות, מסחר או סוגים אחרים של עצות או המלצות שסופקו או מאושרים על ידי TradingView. קרא עוד בתנאים וההגבלות.

רוצה להשתמש בספרייה זו?

העתק את השורה הבאה והדבק אותה בסקריפט שלך.