PINE LIBRARY

Console

Library "Console"

█  OVERVIEW

An easy way to output messages to a console like table using a a simple "print" function that can be called from anywhere in your code including functions.

█  Supports:

- Scrollable console messages
- Customisable number of displayed messages
- More than one "console" for different types of output if required
- The ability to choose which message to start viewing from (useful if the message list is long)
- The ability to place the console table at different positions on the chart to mitigate against
overwriting an existing table.

█  Limitations:
The "scrollbar" handle is actually a modified time widget handle. As the handle is grabbed and moved left or right across the chart bars, this script calculates the offset of the bar being pointed to from the last bar in the chart and uses that as the console message offset. However, It isn't possible to position this on the last chart bar with code.
So there are two solutions:
1) Manually change timestamp of the variable scrollStart to the current time (roughly)
eg. scrollStart = "25 Dec 2022 14:30 +0000"
2) Use a higher timeframe (Weeks or Months) and visually find the scroll bar. If it is to the right of the chart bars the console output will read NaN. Grab the handle and move it left and it will snap to the last chart candle position. If it is to the left then find it and move it to the right as needed.

█  Notes On Usage
- Import the library as console (the call will be console.print(...) )
- Assign a console variable name and call the console.initialise function
eg. var con1=console.initialise()
- Use the console.print() function to print a message or messages
This takes two parameters:
_consoleName :this is the console name you are printing to
_message: this is the message that you want to display. It is a string and can be built in the normal way using any pinescript string functions like str.tostring() etc
- Use the console.display function to display the messages.
To work as intended this display function should be placed at the last line with the following code
if i_showMessages
....if i_displayTable == "con1"
........display(con1, i_lineOffset, i_rowsToDisplay, i_gotoMsg, posn)

(More "consoles" can be written to and the example code provided with the library shows this in more detail. Also, the indents don't show in these notes)

Lastly, placement of a console.print() without a qualifying "if" statement will occur for every bar. This may be desired. If not then use under an if statement (example in the supplied code).

Happy debugging :)
-----------------------------------------------------------------------------------------------------------

initialise()
  initialise: creates the message array
  Parameters:
    none:
  Returns: message array: this is assigned to the "console" identifier

print(_consoleName, _message)
  used to output the desired text string to the console
  Parameters:
    _consoleName: : the message array
    _message: : the console message
  Returns: none

display(_consoleName, _lineOffset, _rowsToDisplay, _gotoMsg, _posn)
  display: placed in the last section of code. Displays the console messages
  Parameters:
    _consoleName: : the message array
    _lineOffset: : the setting of the scroll bar (time widget)
    _rowsToDisplay: : how many rows to show in the console table
    _gotoMsg: : which message to display from (default is 0)
    _posn: : where the console table will be displayed
  Returns: none
debugging

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