PINE LIBRARY

log

Telah dikemas kini
Library "log"
A Library to log and display messages in a table, with different colours.
The log consists of 3 columns:
Bar Index / Message / Log
Credits
QuantNomad - for his idea on logging messages as Error/Warnings and displaying the color based on the type of the message

setHeader(_t, _location, _header1, _header2, _header3, _halign, _valign, _size) Sets the header for the table to be used for displaying the logs.
  Parameters:
    _t: table, table to be used for printing
    _location: string, Location of the table.
    _header1: string, the name to put into the Index Queue Header. Default is 'Bar #'
    _header2: string, the name to put into the Message Queue Header. Default is 'Message'
    _header3: string, the name to put into the Log Queue Header. Default is 'Log'
    _halign: string, the horizontal alignment of header. Options - Left/Right/Center
    _valign: string, the vertical alignment of header. Options - Top/Bottom/Center
    _size: string, the size of text of header. Options - Tiny/Small/Normal/Large/Huge/Auto
  Returns: Void

initHeader(_location, _rows, _header1, _header2, _header3, _halign, _valign, _size, _frameBorder, _cellBorder) Creates the table for logging.
3 columns will be displayed.
Bar Index Q / Message Q / Log Q
  Parameters:
    _location: string, Location of the table.
    _rows: int, table size, excluding the header. Default value is 40.
    _header1: string, the name to put into the Index Queue Header. Default is 'Bar #'
    _header2: string, the name to put into the Message Queue Header. Default is 'Message'
    _header3: string, the name to put into the Log Queue Header. Default is 'Log'
    _halign: string, the horizontal alignment of header. Options - Left/Right/Center
    _valign: string, the vertical alignment of header. Options - Top/Bottom/Center
    _size: string, the size of text of header. Options - Tiny/Small/Normal/Large/Huge/Auto
    _frameBorder: int, table Frame BorderWidth. Default value is 1.
    _cellBorder: int, table Cell Borders Width, Default value is 2.
  Returns: table

init(_rows) Initiate array variables for logging.
  Parameters:
    _rows: int, table size, excluding the header. Default value is 40.
  Returns: tuple, arrays - > error code Q, bar_index Q, Message Q, Log Q

log(_ec, _idx, _1, _2, _m1, _m2, _code, _prefix, _suffix) logs a message to logging queue.
  Parameters:
    _ec: int[], Error/Codes (1-7) for colouring.
Default Colour Code is 1 - Gray, 2 - Orange, 3 - Red, 4 - Blue, 5 - Green, 6 - Cream, 7 - Offwhite
    _idx: int[], bar index Q. The index of current bar is logged automatically
you can add before and after this index value, whatever you choose to, via the _prefix and _suffix variables.
    _1: string[], Message Q.
    _2: string[], Log Q
    _m1: string, message needed to be logged to Message Q
    _m2: string, detailed log needed to be logged to Log Q
    _code: int, Error/Code to be assigned. Default code is 1.
    _prefix: string, prefix to Bar State Q message
    _suffix: string, suffix to Bar State Q message
Order of logging would be Bar Index Q / Message Q / Log Q
  Returns: void

resize(_ec, _idx, _1, _2, _rows) Resizes the all messaging queues.
a resize will delete the existing table, so a new header/table has to be initiated after the resize.
This is because pine doesnt allow changing the table dimensions once they have been recreated.
If size is decreased then removes the oldest messages
  Parameters:
    _ec: int[], Error/Codes (1-7) for colouring.
    _idx: int[], bar index Q.
    _1: string[], Message Q.
    _2: string[], Log Q
    _rows: int, the new size needed for the queue. Default value is 40.
  Returns: void

print(_t, _ec, _idx, _1, _2, halign, halign, _size) Prints Bar Index Q / Message Q / Log Q
  Parameters:
    _t: table, table to be used for printing
    _ec: int[], Error/Codes (1-7) for colouring.
Default Colour Code is 1 - Gray, 2 - Orange, 3 - Red, 4 - Blue, 5 - Green, 6 - Cream, 7 - Offwhite
    _idx: int[], for bar index Q.
    _1: string[], Message Q.
    _2: string[], Log Q
    halign: string, the horizontal alignment of all message column. Options - Left/Right/Center
    halign: string, the vertical alignment of all message column. Options - Top/Bottom/Center
    _size: string, the size of text across the table, excepr the headers. Options - Tiny/Small/Normal/Large/Huge/Auto
  Returns: void

printx(_t, _idx, _1, _2, _ec, _fg, _bg, _halign, _valign, _size) Prints Bar Index Q / Message Q / Log Q, but with custom options to format the table and colours
  Parameters:
    _t: table, table to be used for printing
    _idx: int[], for bar index Q.
    _1: string[], Message Q.
    _2: string[], Log Q
    _ec: int[], Error/Codes (1-7) for colouring.
    _fg: color[], Color array specifying colours for foreground. Maximum length is seven. Need not provide all seven, but atleast one. If not enough provided then last colour in the array is used for missing codes
    _bg: color[], Same as fg.
    _halign: string, the horizontal alignment of all message column. Options - Left/Right/Center
    _valign: string, the vertical alignment of all message column. Options - Top/Bottom/Center
    _size: string, the size of text across the table, excepr the headers. Options - Tiny/Small/Normal/Large/Huge/Auto
  Returns: void

flush(_t, _idx, _1, _2, _ec) Clears queues of existing messages, filling with blanks and 0
  Parameters:
    _t: table, table to be flushed
    _idx: int[], for bar index Q.
    _1: string[], Message Q.
    _2: string[], Log Q
    _ec: int[], Error/Codes (1-7) for colouring.
  Returns: void.

erase(_idx, _1, _2, _ec) Deletes message queue and the table used for displaying the queue
  Parameters:
    _idx: int[], for bar index Q.
    _1: string[], Message Q.
    _2: string[], Log Q
    _ec: int[], Error/Codes (1-7) for colouring.
  Returns: void
Nota Keluaran
Library "log"
A total revamp from the first version. With introduction of UDT, and methods, it has been possible to port my personal library for general use, by taking in lot of background work of the library within the library.
debugging

Perpustakaan Pine

Dalam semangat sebenar TradingView, penulis telah menerbitkan kod Pine ini sebagai satu perpustakaan sumber terbuka supaya pengaturcara Pine lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara peribadi atau dalam penerbitan sumber terbuka lain, tetapi penggunaan semula kod dalam penerbitan ini adalah dikawal oleh Peraturan dalaman.

Penafian