ZigZag Library [TradingFinder]🔵 Introduction
The "Zig Zag" indicator is an analytical tool that emerges from pricing changes. Essentially, it connects consecutive high and low points in an oscillatory manner. This method helps decipher price changes and can also be useful in identifying traditional patterns.
By sifting through partial price changes, "Zig Zag" can effectively pinpoint price fluctuations within defined time intervals.
🔵 Key Features
1. Drawing the Zig Zag based on Pivot points :
The algorithm is based on pivots that operate consecutively and alternately (switch between high and low swing). In this way, zigzag lines are connected from a swing high to a swing low and from a swing low to a swing high.
Also, with a very low probability, it is possible to have both low pivots and high pivots in one candle. In these cases, the algorithm tries to make the best decision to make the most suitable choice.
You can control what period these decisions are based on through the "PiPe" parameter.
2.Naming and labeling each pivot based on its position as "Higher High" (HH), "Lower Low" (LL), "Higher Low" (HL), and "Lower High" (LH).
Additionally, classic patterns such as HH, LH, LL, and HL can be recognized. All traders analyzing financial markets using classic patterns and Elliot Waves can benefit from the "zigzag" indicator to facilitate their analysis.
" HH ": When the price is higher than the previous peak (Higher High).
" HL ": When the price is higher than the previous low (Higher Low).
" LH ": When the price is lower than the previous peak (Lower High).
" LL ": When the price is lower than the previous low (Lower Low).
🔵 How to Use
First, you can add the library to your code as shown in the example below.
import TFlab/ZigZagLibrary_TradingFinder/1 as ZZ
Function "ZigZag" Parameters :
🟣 Logical Parameters
1. HIGH : You should place the "high" value here. High is a float variable.
2. LOW : You should place the "low" value here. Low is a float variable.
3. BAR_INDEX : You should place the "bar_index" value here. Bar_index is an integer variable.
4. PiPe : The desired pivot period for plotting Zig Zag is placed in this parameter. For example, if you intend to draw a Zig Zag with a Swing Period of 5, you should input 5.
PiPe is an integer variable.
Important :
Apart from the "PiPe" indicator, which is part of the customization capabilities of this indicator, you can create a multi-time frame mode for the indicator using 3 parameters "High", "Low" and "BAR_INDEX". In this way, instead of the data of the current time frame, use the data of other time frames.
Note that it is better to use the current time frame data, because using the multi-time frame mode is associated with challenges that may cause bugs in your code.
🟣 Setting Parameters
5. SHOW_LINE : It's a boolean variable. When true, the Zig Zag line is displayed, and when false, the Zig Zag line display is disabled.
6. STYLE_LINE : In this variable, you can determine the style of the Zig Zag line. You can input one of the 3 options: line.style_solid, line.style_dotted, line.style_dashed. STYLE_LINE is a constant string variable.
7. COLOR_LINE : This variable takes the input of the line color.
8. WIDTH_LINE : The input for this variable is a number from 1 to 3, which is used to adjust the thickness of the line that draws the Zig Zag. WIDTH_LINE is an integer variable.
9. SHOW_LABEL : It's a boolean variable. When true, labels are displayed, and when false, label display is disabled.
10. COLOR_LABEL : The color of the labels is set in this variable.
11. SIZE_LABEL : The size of the labels is set in this variable. You should input one of the following options: size.auto, size.tiny, size.small, size.normal, size.large, size.huge.
12. Show_Support : It's a boolean variable that, when true, plots the last support line, and when false, disables its plotting.
13. Show_Resistance : It's a boolean variable that, when true, plots the last resistance line, and when false, disables its plotting.
Suggestion :
You can use the following code snippet to import Zig Zag into your code for time efficiency.
//import Library
import TFlab/ZigZagLibrary_TradingFinder/1 as ZZ
// Input and Setting
// Zig Zag Line
ShZ = input.bool(true , 'Show Zig Zag Line', group = 'Zig Zag') //Show Zig Zag
PPZ = input.int(5 ,'Pivot Period Zig Zag Line' , group = 'Zig Zag') //Pivot Period Zig Zag
ZLS = input.string(line.style_dashed , 'Zig Zag Line Style' , options = , group = 'Zig Zag' )
//Zig Zag Line Style
ZLC = input.color(color.rgb(0, 0, 0) , 'Zig Zag Line Color' , group = 'Zig Zag') //Zig Zag Line Color
ZLW = input.int(1 , 'Zig Zag Line Width' , group = 'Zig Zag')//Zig Zag Line Width
// Label
ShL = input.bool(true , 'Label', group = 'Label') //Show Label
LC = input.color(color.rgb(0, 0, 0) , 'Label Color' , group = 'Label')//Label Color
LS = input.string(size.tiny , 'Label size' , options = , group = 'Label' )//Label size
Show_Support= input.bool(false, 'Show Last Support',
tooltip = 'Last Support' , group = 'Support and Resistance')
Show_Resistance = input.bool(false, 'Show Last Resistance',
tooltip = 'Last Resistance' , group = 'Support and Resistance')
//Call Function
ZZ.ZigZag(high ,low ,bar_index ,PPZ , ShZ ,ZLS , ZLC, ZLW ,ShL , LC , LS , Show_Support , Show_Resistance )
Display
Material Design ColorsThis library provides a standard set of colors defined in Material Design 2.0.
🔵 API
Step 1: Import this library.
import algotraderdev/material/1
// remember to check the latest version of this library and replace the 1 above.
Step 2: Get the color you like. Check the source code or the screenshot above to see all the supported colors.
material.red()
Each color function (except for `black()` and `white()`) accepts an optional `variant` parameter. You can choose any of 50, 100, 200, 300, 400, 500, 600, 700, 800, and 900. By default, 500 is chosen if this parameter is not provided.
TTB_TableBuilderLibrary "TTB_TableBuilder"
A helper library to make it simpler to create tables in pinescript
DefaultDarkStyle()
method Size(this, width, height)
Change the size (width, height) of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
width (int)
height (int)
Returns: Cell
method Size(this, width, height)
Change the width of all cells in that row
Namespace types: Row
Parameters:
this (Row)
width (int)
height (int)
Returns: Row
method Width(this, width)
Change the width of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
width (int)
Returns: Cell
method Width(this, width)
Change the width of all cells in that row
Namespace types: Row
Parameters:
this (Row)
width (int)
Returns: Row
method Height(this, height)
Change the height of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
height (int)
Returns: Cell
method Height(this, height)
Change the height of all cells in that row
Namespace types: Row
Parameters:
this (Row)
height (int)
Returns: Row
method Text(this, text_)
Change the text of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
text_ (string)
Returns: Cell
method Text(this, c0, c1, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29)
Set text
Namespace types: Row
Parameters:
this (Row)
c0 (string) : ... c29
c1 (string)
c3 (string)
c4 (string)
c5 (string)
c6 (string)
c7 (string)
c8 (string)
c9 (string)
c10 (string)
c11 (string)
c12 (string)
c13 (string)
c14 (string)
c15 (string)
c16 (string)
c17 (string)
c18 (string)
c19 (string)
c20 (string)
c21 (string)
c22 (string)
c23 (string)
c24 (string)
c25 (string)
c26 (string)
c27 (string)
c28 (string)
c29 (string)
Returns: Row
method TextSize(this, text_size)
Change the text size of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
text_size (string)
Returns: Cell
method TextSize(this, text_size)
Set text size
Namespace types: Row
Parameters:
this (Row)
text_size (string)
Returns: Row
method TextColor(this, c)
Change the text color of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
c (color)
Returns: Cell
method TextColor(this, text_color)
Change the text color of all cells in that row
Namespace types: Row
Parameters:
this (Row)
text_color (color)
Returns: Row
method Bg(this, c)
Change the background color of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
c (color)
Returns: Cell
method Bg(this, bg)
Change the background color of all cells in that row
Namespace types: Row
Parameters:
this (Row)
bg (color)
Returns: Row
method Font(this, text_font_family)
Change the font family of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
text_font_family (string)
Returns: Cell
method Font(this, text_font_family)
Change the width of all cells in that row
Namespace types: Row
Parameters:
this (Row)
text_font_family (string)
Returns: Row
method AlignH(this, halign)
Change the horizontal align of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
halign (string)
Returns: Cell
method AlignH(this, halign)
Change the horizontal align of all cells in that row
Namespace types: Row
Parameters:
this (Row)
halign (string)
Returns: Cell
method AlignV(this, valign)
Change the vertical align of the table cell.
Namespace types: Cell
Parameters:
this (Cell)
valign (string)
Returns: Cell
method AlignV(this, valign)
Change the vertical of all cells in that row
Namespace types: Row
Parameters:
this (Row)
valign (string)
Returns: Cell
method C(this, column)
Get the cell corresponding to the column number
Namespace types: Row
Parameters:
this (Row)
column (int)
Returns: Cell
method C(this, column, row)
Namespace types: Table
Parameters:
this (Table)
column (int)
row (int)
method R(this, row)
Namespace types: Table
Parameters:
this (Table)
row (int)
method Style(this, style)
Namespace types: Table
Parameters:
this (Table)
style (TableStyle)
method Position(this, position)
Namespace types: Table
Parameters:
this (Table)
position (string)
new(position, columns, rows, style)
Parameters:
position (string)
columns (int)
rows (int)
style (TableStyle)
CellStyle
Fields:
text_color (series__color)
text_halign (series__string)
text_valign (series__string)
text_size (series__integer)
bgcolor (series__color)
tooltip (series__string)
text_font_family (series__string)
TableStyle
Fields:
bgcolor (series__color)
frame_color (series__color)
frame_width (series__integer)
border_color (series__color)
border_width (series__integer)
default_cell_style (|CellStyle|#OBJ)
Cell
Fields:
ref (series__table)
column (series__integer)
row (series__integer)
Row
Fields:
ref (series__table)
row (series__integer)
cells (array__|Cell|#OBJ)
Table
Fields:
body (series__table)
rows (array__|Row|#OBJ)
Mad_FibonacciboxLibrary "Mad_Fibonaccibox"
This library is designed to create and manage multiple Fibonacci boxes, which are graphical representations based on the inputs.
-----------------
exports:
f_fib_calc(_Fibonacci_box, _itemnumber)
fibonacci calc.
@description This function block uses the levels and paramters set into the type_fibonacci_box(levels) and fills the corresponding array of prices.
Parameters:
_Fibonacci_box (type_Fibonacci_box )
_itemnumber (int)
Returns: returns a type_Fibonacci_box with the filled data
f_fib_draw(_Fibonacci_box, _itemnumber)
fibonacci draw.
@description This function block uses the levels, prices and paramters set into the type_fibonacci_box(levels) and draws the fib on the chart
Parameters:
_Fibonacci_box (type_Fibonacci_box )
_itemnumber (int)
Returns: returns lines labels and fills on the chart, no data returns
type_level
s for defining a lines and texts of a fibonacci box
Fields:
level (series float)
price (series float)
drawline (series bool)
linewidth (series int)
linetype (series string)
fiblinecolor (series color)
drawlabel (series string)
labeltext (series string)
textshift (series int)
fibtextcolor (series color)
fibtextsize (series string)
transp (series int)
type_fill
s for defining the fills of a fibonaccibox
Fields:
partner_A (series int)
partner_B (series int)
fill_color (series color)
transp (series int)
type_Fibonacci_box
s for defining a fibonacci box
Fields:
bottom_price (series float)
top_price (series float)
StartBar (series int)
StopBar (series int)
levels (type_level )
fills (type_fill )
ChartisLog (series bool)
fibreverse (series bool)
fibdrawreverse (series bool)
decimals_price (series int)
decimals_percent (series int)
drawlines (series bool)
drawlabels (series bool)
drawfills (series bool)
draw_biginfo (series bool)
biginfo_textshift (series int)
rangeinfo_location (series int)
rangeinfo_color (series color)
rangeinfo_textsize (series string)
line_array (line )
linefill_array (linefill )
label_array (label )
GuageLibrary "Gauge"
The gauge library utilizes a gaugeParams object, encapsulating crucial parameters for gauge creation. Essential attributes include num (the measured value) , min (the minimum value equating to 100% on the gauge's minimum scale) , and max (the maximum value equating to 100% on the gauge's maximum scale) . The size attribute (defaulting to 10) splits the scale into increments, each representing 100% divided by the specified size.
The num value dynamically shifts within the gauge based on its percentage move from the mathematical average between min and max . When num is below the average, the minimum portion of the scale activates, displaying the appropriate percentage based on the distance from the average to the minimum. The same principle applies when num exceeds the average. The 100% scale is reached at either end when num equals min or max .
The library offers full customization, allowing users to configure color schemes, labels, and titles. The gauge can be displayed either vertically (default) or horizontally. The colors employ a gradient, adapting based on the number's movement. Overall, the gauge library provides a flexible and comprehensive tool for visualizing and interpreting numerical values within a specified range.
TableUtilsLibrary "TableUtils"
Collection of table utility functions
getTablePositionByLabel(tablePosition)
Return the position for the table by given label. Useful if you want to control the position of the table with a pine script input selector that use a more human friendly labels
Parameters:
tablePosition (string) : (string) Label of the table position. Possible values are: "Top left", "Top right", "Bottom left", "Bottom right", "Middle left", "Middle right"
Returns: the position for the table by given label. Useful if you want to control the position of the table with a pine script input selector that use a more human friendly labels
chrono_utilsLibrary "chrono_utils"
📝 Description
Collection of objects and common functions that are related to datetime windows session days and time ranges. The main purpose of this library is to handle time-related functionality and make it easy to reason about a future bar checking if it will be part of a predefined session and/or inside a datetime window. All existing session functionality I found in the documentation e.g. "not na(time(timeframe, session, timezone))" are not suitable for strategy scripts, since the execution of the orders is delayed by one bar, due to the script execution happening at the bar close. Moreover, a history operator with a negative value that looks forward is not allowed in any pinescript expression. So, a prediction for the next bar using the bars_back argument of "time()"" and "time_close()" was necessary. Thus, I created this library to overcome this small but very important limitation. In the meantime, I added useful functionality to handle session-based behavior. An interesting utility that emerged from this development is data anomaly detection where a comparison between the prediction and the actual value is happening. If those two values are different then a data inconsistency happens between the prediction bar and the actual bar (probably due to a holiday, half session day, a timezone change etc..)
🤔 How to Guide
To use the functionality this library provides in your script you have to import it first!
Copy the import statement of the latest release by pressing the copy button below and then paste it into your script. Give a short name to this library so you can refer to it later on. The import statement should look like this:
import jason5480/chrono_utils/2 as chr
To check if a future bar will be inside a window first of all you have to initialize a DateTimeWindow object.
A code example is the following:
var dateTimeWindow = chr.DateTimeWindow.new().init(fromDateTime = timestamp('01 Jan 2023 00:00'), toDateTime = timestamp('01 Jan 2024 00:00'))
Then you have to "ask" the dateTimeWindow if the future bar defined by an offset (default is 1 that corresponds th the next bar), will be inside that window:
// Filter bars outside of the datetime window
bool dateFilterApproval = dateTimeWindow.is_bar_included()
You can visualize the result by drawing the background of the bars that are outside the given window:
bgcolor(color = dateFilterApproval ? na : color.new(color.fuchsia, 90), offset = 1, title = 'Datetime Window Filter')
In the same way, you can "ask" the Session if the future bar defined by an offset it will be inside that session.
First of all, you should initialize a Session object.
A code example is the following:
var sess = chr.Session.new().from_sess_string(sess = '0800-1700:23456', refTimezone = 'UTC')
Then check if the given bar defined by the offset (default is 1 that corresponds th the next bar), will be inside the session like that:
// Filter bars outside the sessions
bool sessionFilterApproval = view.sess.is_bar_included()
You can visualize the result by drawing the background of the bars that are outside the given session:
bgcolor(color = sessionFilterApproval ? na : color.new(color.red, 90), offset = 1, title = 'Session Filter')
In case you want to visualize multiple session ranges you can create a SessionView object like that:
var view = SessionView.new().init(SessionDays.new().from_sess_string('2345'), array.from(SessionTimeRange.new().from_sess_string('0800-1600'), SessionTimeRange.new().from_sess_string('1300-2200')), array.from('London', 'New York'), array.from(color.blue, color.orange))
and then call the draw method of the SessionView object like that:
view.draw()
🏋️♂️ Please refer to the "EXAMPLE DATETIME WINDOW FILTER" and "EXAMPLE SESSION FILTER" regions of the script for more advanced code examples of how to utilize the full potential of this library, including user input settings and advanced visualization!
⚠️ Caveats
As I mentioned in the description there are some cases that the prediction of the next bar is not accurate. A wrong prediction will affect the outcome of the filtering. The main reasons this could happen are the following:
Public holidays when the market is closed
Half trading days usually before public holidays
Change in the daylight saving time (DST)
A data anomaly of the chart, where there are missing and/or inconsistent data.
A bug in this library (Please report by PM sending the symbol, timeframe, and settings)
Special thanks to @robbatt and @skinra for the constructive feedback 🏆. Without them, the exposed API of this library would be very lengthy and complicated to use. Thanks to them, now the user of this library will be able to get the most, with only a few lines of code!
TouchedLibrary "Touched"
Breakout(zone, lookback)
Tells if the zone has been broken on the current bar.
Parameters:
zone (Zone) : The definitiin of the zone.
lookback (int) : How many bars to look back.
Returns: a Touch object that tells if the zone has been broken up or down.
FalseBreakout(zone, lookback)
Tells if the zone has a false breakout on the current bar.
Parameters:
zone (Zone) : The definitiin of the zone.
lookback (int) : How many bars to look back.
Returns: a Touch object that tells if the zone has had a false breakout up or down.
Retest(zone, lookback)
Tells if the zone has been retested on the current bar.
Parameters:
zone (Zone) : The definitiin of the zone.
lookback (int) : How many bars to look back.
Returns: a Touch object that tells if the zone has been retested up or down.
Zone
Fields:
High (series__float)
Low (series__float)
BaseTime (series__integer)
Touch
Fields:
Up (series__bool)
Down (series__bool)
StrategyDashboardLibrary ”StrategyDashboard”
Hey, everybody!
I haven’t done anything here for a long time, I need to get better ^^.
In my strategies, so far private, but not about that, I constantly use dashboards, which clearly show how my strategy is working out.
Of course, you can also find a number of these parameters in the standard strategy window, but I prefer to display everything on the screen, rather than digging through a bunch of boxes and dropdowns.
At the moment I am using 2 dashboards, which I would like to share with you.
1. monthly(isShow)
this is a dashboard with the breakdown of profit by month in per cent. That is, it displays how much percentage you made or lost in a particular month, as well as for the year as a whole.
Parameters:
isShow (bool) - determine allowance to display or not.
2. total(isShow)
The second dashboard displays more of the standard strategy information, but in a table format. Information from the series “number of consecutive losers, number of consecutive wins, amount of earnings per day, etc.”.
Parameters:
isShow (bool) - determine allowance to display or not.
Since I prefer the dark theme of the interface, now they are adapted to it, but in the near future for general convenience I will add the ability to adapt to light.
The same goes for the colour scheme, now it is adapted to the one I use in my strategies (because the library with more is made by cutting these dashboards from my strategies), but will also make customisable part.
If you have any wishes, feel free to write in the comments, maybe I can implement and add them in the next versions.
Statistics TableStrategy Statistics
This library will add a table with statistics from your strategy. With this library, you won't have to switch to your strategy tester tab to view your results and positions.
Usage:
You can choose whether to set the table by input fields by adding the below code to your strategy or replace the parameters with the ones you would like to use manually.
// Statistics table options.
statistics_table_enabled = input.string(title='Show a table with statistics', defval='YES', options= , group='STATISTICS')
statistics_table_position = input.string(title='Position', defval='RIGHT', options= , group='STATISTICS')
statistics_table_margin = input.int(title='Table Margin', defval=10, minval=0, maxval=100, step=1, group='STATISTICS')
statistics_table_transparency = input.int(title='Cell Transparency', defval=20, minval=1, maxval=100, step=1, group='STATISTICS')
statistics_table_text_color = input.color(title='Text Color', defval=color.new(color.white, 0), group='STATISTICS')
statistics_table_title_cell_color = input.color(title='Title Cell Color', defval=color.new(color.gray, 80), group='STATISTICS')
statistics_table_cell_color = input.color(title='Cell Color', defval=color.new(color.purple, 0), group='STATISTICS')
// Statistics table init.
statistics.table(strategy.initial_capital, close, statistics_table_enabled, statistics_table_position, statistics_table_margin, statistics_table_transparency, statistics_table_text_color, statistics_table_title_cell_color, statistics_table_cell_color)
Sample:
If you are interested in the strategy used for this statistics table, you can browse the strategies on my profile.
TableLibrary "Table"
This library provides an easy way to convert arrays and matrixes of data into tables. There are a few different implementations of each function so you can get more or less control over the appearance of the tables. The basic rule of thumb is that all matrix rows must have the same number of columns, and if you are providing multiple arrays/matrixes to specify additional colors (background/text), they must have the same number of rows/columns as the data array. Finally, you do have the option of spanning cells across rows or columns with some special syntax in the data cell. Look at the examples to see how the arrays and matrixes need to be built before they can be used by the functions.
floatArrayToCellArray(floatArray)
Helper function that converts a float array to a Cell array so it can be rendered with the fromArray function
Parameters:
floatArray (float ) : (array) the float array to convert to a Cell array.
Returns: array The Cell array to return.
stringArrayToCellArray(stringArray)
Helper function that converts a string array to a Cell array so it can be rendered with the fromArray function
Parameters:
stringArray (string ) : (array) the array to convert to a Cell array.
Returns: array The Cell array to return.
floatMatrixToCellMatrix(floatMatrix)
Helper function that converts a float matrix to a Cell matrix so it can be rendered with the fromMatrix function
Parameters:
floatMatrix (matrix) : (matrix) the float matrix to convert to a string matrix.
Returns: matrix The Cell matrix to render.
stringMatrixToCellMatrix(stringMatrix)
Helper function that converts a string matrix to a Cell matrix so it can be rendered with the fromMatrix function
Parameters:
stringMatrix (matrix) : (matrix) the string matrix to convert to a Cell matrix.
Returns: matrix The Cell matrix to return.
fromMatrix(CellMatrix, position, verticalOffset, transposeTable, textSize, borderWidth, tableNumRows, blankCellText)
Takes a CellMatrix and renders it as a table.
Parameters:
CellMatrix (matrix) : (matrix) The Cells to be rendered in a table
position (string) : (string) Optional. The position of the table. Defaults to position.top_right
verticalOffset (int) : (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
transposeTable (bool) : (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
textSize (string) : (string) Optional. The size of text to render in the table. Defaults to size.small.
borderWidth (int) : (int) Optional. The width of the border between table cells. Defaults to 2.
tableNumRows (int) : (int) Optional. The number of rows in the table. Not required, defaults to the number of rows in the provided matrix. If your matrix will have a variable number of rows, you must provide the max number of rows or the function will error when it attempts to set a cell value on a row that the table hadn't accounted for when it was defined.
blankCellText (string) : (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
fromMatrix(dataMatrix, position, verticalOffset, transposeTable, textSize, borderWidth, tableNumRows, blankCellText)
Renders a float matrix as a table.
Parameters:
dataMatrix (matrix) : (matrix_float) The data to be rendered in a table
position (string) : (string) Optional. The position of the table. Defaults to position.top_right
verticalOffset (int) : (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
transposeTable (bool) : (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
textSize (string) : (string) Optional. The size of text to render in the table. Defaults to size.small.
borderWidth (int) : (int) Optional. The width of the border between table cells. Defaults to 2.
tableNumRows (int) : (int) Optional. The number of rows in the table. Not required, defaults to the number of rows in the provided matrix. If your matrix will have a variable number of rows, you must provide the max number of rows or the function will error when it attempts to set a cell value on a row that the table hadn't accounted for when it was defined.
blankCellText (string) : (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
fromMatrix(dataMatrix, position, verticalOffset, transposeTable, textSize, borderWidth, tableNumRows, blankCellText)
Renders a string matrix as a table.
Parameters:
dataMatrix (matrix) : (matrix_string) The data to be rendered in a table
position (string) : (string) Optional. The position of the table. Defaults to position.top_right
verticalOffset (int) : (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
transposeTable (bool) : (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
textSize (string) : (string) Optional. The size of text to render in the table. Defaults to size.small.
borderWidth (int) : (int) Optional. The width of the border between table cells. Defaults to 2.
tableNumRows (int) : (int) Optional. The number of rows in the table. Not required, defaults to the number of rows in the provided matrix. If your matrix will have a variable number of rows, you must provide the max number of rows or the function will error when it attempts to set a cell value on a row that the table hadn't accounted for when it was defined.
blankCellText (string) : (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
fromArray(dataArray, position, verticalOffset, transposeTable, textSize, borderWidth, blankCellText)
Renders a Cell array as a table.
Parameters:
dataArray (Cell ) : (array) The data to be rendered in a table
position (string) : (string) Optional. The position of the table. Defaults to position.top_right
verticalOffset (int) : (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
transposeTable (bool) : (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
textSize (string) : (string) Optional. The size of text to render in the table. Defaults to size.small.
borderWidth (int) : (int) Optional. The width of the border between table cells. Defaults to 2.
blankCellText (string) : (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
fromArray(dataArray, position, verticalOffset, transposeTable, textSize, borderWidth, blankCellText)
Renders a string array as a table.
Parameters:
dataArray (string ) : (array_string) The data to be rendered in a table
position (string) : (string) Optional. The position of the table. Defaults to position.top_right
verticalOffset (int) : (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
transposeTable (bool) : (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
textSize (string) : (string) Optional. The size of text to render in the table. Defaults to size.small.
borderWidth (int) : (int) Optional. The width of the border between table cells. Defaults to 2.
blankCellText (string) : (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
fromArray(dataArray, position, verticalOffset, transposeTable, textSize, borderWidth, blankCellText)
Renders a float array as a table.
Parameters:
dataArray (float ) : (array_float) The data to be rendered in a table
position (string) : (string) Optional. The position of the table. Defaults to position.top_right
verticalOffset (int) : (int) Optional. The vertical offset of the table from the top or bottom of the chart. Defaults to 0.
transposeTable (bool) : (bool) Optional. Will transpose all of the data in the matrices before rendering. Defaults to false.
textSize (string) : (string) Optional. The size of text to render in the table. Defaults to size.small.
borderWidth (int) : (int) Optional. The width of the border between table cells. Defaults to 2.
blankCellText (string) : (string) Optional. Text to use cells when adding blank rows for vertical offsetting.
debug(message, position)
Renders a debug message in a table at the desired location on screen.
Parameters:
message (string) : (string) The message to render.
position (string) : (string) Optional. The position of the debug message. Defaults to position.middle_right.
Cell
Type for each cell's content and appearance
Fields:
content (series string)
bgColor (series color)
textColor (series color)
align (series string)
colspan (series int)
rowspan (series int)
Polyline PlusThis library introduces the `PolylinePlus` type, which is an enhanced version of the built-in PineScript `polyline`. It enables two features that are absent from the built-in type:
1. Developers can now efficiently add or remove points from the polyline. In contrast, the built-in `polyline` type is immutable, requiring developers to create a new instance of the polyline to make changes, which is cumbersome and incurs a significant performance penalty.
2. Each `PolylinePlus` instance can theoretically hold up to ~1M points, surpassing the built-in `polyline` type's limit of 10K points, as long as it does not exceed the memory limit of the PineScript runtime.
Internally, each `PolylinePlus` instance utilizes an array of `line`s and an array of `polyline`s. The `line`s array serves as a buffer to store lines formed by recently added points. When the buffer reaches its capacity, it flushes the contents and converts the lines into polylines. These polylines are expected to undergo fewer updates. This approach is similiar to the concept of "Buffered I/O" in file and network systems. By connecting the underlying lines and polylines, this library achieves an enhanced polyline that is dynamic, efficient, and capable of surpassing the maximum number of points imposed by the built-in polyline.
🔵 API
Step 1: Import this library
import algotraderdev/polylineplus/1 as pp
// remember to check the latest version of this library and replace the 1 above.
Step 2: Initialize the `PolylinePlus` type.
var p = pp.PolylinePlus.new()
There are a few optional params that developers can specify in the constructor to modify the behavior and appearance of the polyline instance.
var p = pp.PolylinePlus.new(
// If true, the drawing will also connect the first point to the last point, resulting in a closed polyline.
closed = false,
// Determines the field of the chart.point objects that the polyline will use for its x coordinates. Either xloc.bar_index (default), or xloc.bar_time.
xloc = xloc.bar_index,
// Color of the polyline. Default is blue.
line_color = color.blue,
// Style of the polyline. Default is line.style_solid.
line_style = line.style_solid,
// Width of the polyline. Default is 1.
line_width = 1,
// The maximum number of points that each built-in `polyline` instance can contain.
// NOTE: this is not to be confused with the maximum of points that each `PolylinePlus` instance can contain.
max_points_per_builtin_polyline = 10000,
// The number of lines to keep in the buffer. If more points are to be added while the buffer is full, then all the lines in the buffer will be flushed into the poylines.
// The higher the number, the less frequent we'll need to // flush the buffer, and thus lead to better performance.
// NOTE: the maximum total number of lines per chart allowed by PineScript is 500. But given there might be other places where the indicator or strategy are drawing lines outside this polyline context, the default value is 50 to be safe.
lines_bffer_size = 50)
Step 3: Push / Pop Points
// Push a single point
p.push_point(chart.point.now())
// Push multiple points
chart.point points = array.from(p1, p2, p3) // Where p1, p2, p3 are all chart.point type.
p.push_points(points)
// Pop point
p.pop_point()
// Resets all the points in the polyline.
p.set_points(points)
// Deletes the polyline.
p.delete()
🔵 Benchmark
Below is a simple benchmark comparing the performance between `PolylinePlus` and the native `polyline` type for incrementally adding 10K points to a polyline.
import algotraderdev/polylineplus/2 as pp
var t1 = 0
var t2 = 0
if bar_index < 10000
int start = timenow
var p = pp.PolylinePlus.new(xloc = xloc.bar_time, closed = true)
p.push_point(chart.point.now())
t1 += timenow - start
start := timenow
var polyline pl = na
var points = array.new()
points.push(chart.point.now())
if not na(pl)
pl.delete()
pl := polyline.new(points)
t2 += timenow - start
if barstate.islast
log.info('{0} {1}', t1, t2)
For this benchmark, `PolylinePlus` took ~300ms, whereas the native `polyline` type took ~6000ms.
We can also fine-tune the parameters for `PolylinePlus` to have a larger buffer size for `line`s and a smaller buffer for `polyline`s.
var p = pp.PolylinePlus.new(xloc = xloc.bar_time, closed = true, lines_buffer_size = 500, max_points_per_builtin_polyline = 1000)
With the above optimization, it only took `PolylinePlus` ~80ms to process the same 10K points, which is ~75x the performance compared to the native `polyline`.
lib_plot_composite_objectsLibrary "lib_plot_composite_objects"
library building on top of lib_plot_objects for composite objects such as Triangles and Polygons. heavily using chart.points
method tostring(this, date_format)
Namespace types: Triangle
Parameters:
this (Triangle)
date_format (simple string)
method tostring(this, date_format)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
date_format (simple string)
method tostring(this, date_format)
Namespace types: Polygon
Parameters:
this (Polygon)
date_format (simple string)
method tostring(this, date_format)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
date_format (simple string)
method tostring(this, date_format)
Namespace types: Triangle
Parameters:
this (Triangle )
date_format (simple string)
method tostring(this, date_format)
Namespace types: Polygon
Parameters:
this (Polygon )
date_format (simple string)
method tostring(this, date_format)
Namespace types: TriangleFill
Parameters:
this (TriangleFill )
date_format (simple string)
method tostring(this, date_format)
Namespace types: PolygonFill
Parameters:
this (PolygonFill )
date_format (simple string)
method create_triangle(this, b, c, args)
Namespace types: chart.point
Parameters:
this (chart.point)
b (chart.point)
c (chart.point)
args (LineArgs type from robbatt/lib_plot_objects/32)
method create_triangle(this, c)
Namespace types: D.Line
Parameters:
this (Line type from robbatt/lib_plot_objects/32)
c (chart.point)
method create_polygon(points, args)
Namespace types: chart.point
Parameters:
points (chart.point )
args (LineArgs type from robbatt/lib_plot_objects/32)
method create_polygon(start, others, args)
Namespace types: chart.point
Parameters:
start (chart.point)
others (chart.point )
args (LineArgs type from robbatt/lib_plot_objects/32)
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_center_label(this, txt, args, tooltip)
Namespace types: Triangle
Parameters:
this (Triangle)
txt (string)
args (LabelArgs type from robbatt/lib_plot_objects/32)
tooltip (string)
method create_label(this, txt, args, tooltip)
Namespace types: Polygon
Parameters:
this (Polygon)
txt (string)
args (LabelArgs type from robbatt/lib_plot_objects/32)
tooltip (string)
method nz(this, default)
Namespace types: Triangle
Parameters:
this (Triangle)
default (Triangle)
method nz(this, default)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
default (TriangleFill)
method nz(this, default)
Namespace types: Polygon
Parameters:
this (Polygon)
default (Polygon)
method nz(this, default)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
default (PolygonFill)
method enqueue(id, item, max)
Namespace types: Triangle
Parameters:
id (Triangle )
item (Triangle)
max (int)
method enqueue(id, item, max)
Namespace types: Polygon
Parameters:
id (Polygon )
item (Polygon)
max (int)
method enqueue(id, item, max)
Namespace types: TriangleFill
Parameters:
id (TriangleFill )
item (TriangleFill)
max (int)
method enqueue(id, item, max)
Namespace types: PolygonFill
Parameters:
id (PolygonFill )
item (PolygonFill)
max (int)
method update(this, a, b, c)
Namespace types: Triangle
Parameters:
this (Triangle)
a (chart.point)
b (chart.point)
c (chart.point)
method update(this, points)
Namespace types: Polygon
Parameters:
this (Polygon)
points (chart.point )
method delete(this)
Namespace types: Triangle
Parameters:
this (Triangle)
method delete(this)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
method delete(this)
Namespace types: Polygon
Parameters:
this (Polygon)
method delete(this)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
method delete(this)
Namespace types: Triangle
Parameters:
this (Triangle )
method delete(this)
Namespace types: TriangleFill
Parameters:
this (TriangleFill )
method delete(this)
Namespace types: Polygon
Parameters:
this (Polygon )
method delete(this)
Namespace types: PolygonFill
Parameters:
this (PolygonFill )
method draw(this, ab_args_override, ac_args_override, bc_args_override)
Namespace types: Triangle
Parameters:
this (Triangle)
ab_args_override (LineArgs type from robbatt/lib_plot_objects/32)
ac_args_override (LineArgs type from robbatt/lib_plot_objects/32)
bc_args_override (LineArgs type from robbatt/lib_plot_objects/32)
method draw(this)
Namespace types: Polygon
Parameters:
this (Polygon)
method draw(this)
Namespace types: TriangleFill
Parameters:
this (TriangleFill)
method draw(this)
Namespace types: PolygonFill
Parameters:
this (PolygonFill)
method draw(this)
Namespace types: Triangle
Parameters:
this (Triangle )
method draw(this)
Namespace types: TriangleFill
Parameters:
this (TriangleFill )
method draw(this)
Namespace types: Polygon
Parameters:
this (Polygon )
method draw(this)
Namespace types: PolygonFill
Parameters:
this (PolygonFill )
method apply_style(this, args)
Namespace types: Triangle
Parameters:
this (Triangle)
args (LineArgs type from robbatt/lib_plot_objects/32)
method apply_style(this, args)
Namespace types: Polygon
Parameters:
this (Polygon)
args (LineArgs type from robbatt/lib_plot_objects/32)
method apply_style(this, args)
Namespace types: Triangle
Parameters:
this (Triangle )
args (LineArgs type from robbatt/lib_plot_objects/32)
method apply_style(this, args)
Namespace types: Polygon
Parameters:
this (Polygon )
args (LineArgs type from robbatt/lib_plot_objects/32)
Triangle
Fields:
a (chart.point) : first Corner
b (chart.point) : second Corner
c (chart.point) : third Corner
args (LineArgs type from robbatt/lib_plot_objects/32) : Wrapper for reusable arguments for line.new()
ab (Line type from robbatt/lib_plot_objects/32)
ac (Line type from robbatt/lib_plot_objects/32)
bc (Line type from robbatt/lib_plot_objects/32)
TriangleFill
Fields:
triangle (Triangle) : The Triangle object
plot (LineFill type from robbatt/lib_plot_objects/32) : The linefill object to be added and plotted via draw()
Polygon
Fields:
points (chart.point ) : array of points that make up the Polygon
center (chart.point) : Center point of the Polygon, can be used for a label and will be center for PolygonFill
args (LineArgs type from robbatt/lib_plot_objects/32) : Wrapper for reusable arguments for line.new()
plot (Line type from robbatt/lib_plot_objects/32) : 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 (TriangleFill )
printerLibrary "printer"
Printer Library, designed to streamline the process of printing data directly onto charts while offering advanced features for enhanced functionality.
For full documentation, please visit faiyaz7283.github.io
Contrast Color LibraryThis lightweight library provides a utility method that analyzes any provided background color and automatically chooses the optimal black or white foreground color to ensure maximum visual contrast and readability.
🟠 Algorithm
The library utilizes the HSP Color Model to calculate the brightness of the background color. The formula for this calculation is as follows:
brightness = sqrt(0.299 * R^2 + 0.587 * G^2 + 0.114 * B^2 )
The library chooses black as the foreground color if the brightness exceeds the threshold (default 0.5), and white otherwise.
TradeLibrary "Trade"
A Trade Tracking Library
Monitor conditions with less code by using Arrays. When your conditions are met in chronologically, a signal is returned and the scanning starts again.
Create trades automatically with Stop Loss, Take Profit and Entry. The trades will automatically track based on the market movement and update when the targets are hit.
Sample Usage
Enter a buy trade when RSI crosses below 70 then crosses above 80 before it crosses 40.
Note: If RSI crosses 40 before 80, No trade will be entered.
rsi = ta.rsi(close, 21)
buyConditions = array.new_bool()
buyConditions.push(ta.crossunder(rsi, 70))
buyConditions.push(ta.crossover(rsi, 80))
buy = Trade.signal(buyConditions, ta.crossunder(rsi, 40))
trade = Trade.new(close-(100*syminfo.mintick), close +(200*syminfo.mintick), condition=buy)
plot(trade.takeprofit, "TP", style=plot.style_circles, linewidth=4, color=color.lime)
alertcondition(trade.tp_hit, "TP Hit")
method signal(conditions, reset)
Signal Conditions
Namespace types: bool
Parameters:
conditions (bool )
reset (bool)
Returns: Boolean: True when all the conditions have occured
method update(this, stoploss, takeprofit, entry)
Update Trade Parameters
Namespace types: Trade
Parameters:
this (Trade)
stoploss (float)
takeprofit (float)
entry (float)
Returns: nothing
method clear(this)
Clear Trade Parameters
Namespace types: Trade
Parameters:
this (Trade)
Returns: nothing
method track(this, _high, _low)
Track Trade Parameters
Namespace types: Trade
Parameters:
this (Trade)
_high (float)
_low (float)
Returns: nothing
new(stoploss, takeprofit, entry, _high, _low, condition, update)
New Trade with tracking
Parameters:
stoploss (float)
takeprofit (float)
entry (float)
_high (float)
_low (float)
condition (bool)
update (bool)
Returns: a Trade with targets and updates if stoploss or takeprofit is hit
new()
New Empty Trade
Returns: an empty trade
Trade
Fields:
stoploss (series__float)
takeprofit (series__float)
entry (series__float)
sl_hit (series__bool)
tp_hit (series__bool)
open (series__integer)
imlibLibrary "imlib"
Description
The library allows you to display images in your scripts utilising the objects. You can change the image size and screen aspect ratio (the ratio of width to height which you can change if the image is too wide / tall). The library has "example()" function which you can use to see how it works. It also has a handy "logo()" function which you can use to quickly display an image by passing the "Image data string", table position, image size and aspect ratio. And of course you can use it in your own custom way by taking the "logo()" function as an example and modifying the code to your needs.
Since tables in Pinescript are limited to 100 by 100 cells, the limit for image's size is also 100x100 px. All the necessary data to display an image is passed as a string variable, and since Pinescript has a limit of 4096 characters for variables of type, that string can have a maximum length of 4096 characters, which is enough to display a 64x64px image (but can be enough to display a 100x100 image, depending on the image itself).
Below you can find the definitions of functions for this library.
_decompress(data)
: Decompresses string with data image
Parameters:
data (string)
Returns: : Array of with decompressed data
load(data)
: Splits the string with image data into components and builds an object
Parameters:
data (string)
Returns: : An object
show(imgdata, table_id, image_size, screen_ratio)
: Displays an image in a table
Parameters:
imgdata (ImgData)
table_id (table)
image_size (float)
screen_ratio (string)
Returns: : nothing
example()
: Use it as an example of how this library works and how to use it in your own scripts
Returns: : nothing
logo(imgdata, position, image_size, screen_ratio)
: Displays logo using image data string
Parameters:
imgdata (string)
position (string)
image_size (float)
screen_ratio (string)
Returns: : nothing
ImgData
Fields:
w (series__integer)
h (series__integer)
s (series__string)
pal (series__string)
data (array__string)
gFancyMALibrary "gFancyMA"
printLbl(y, x, c, m, b, s)
Parameters:
y (float)
x (int)
c (color)
m (string)
b (bool)
s (string)
debugLibrary "debug"
Show Array or Matrix Elements In Table
Use anytime you want to see the elements in an array or a matrix displayed.
Effective debugger, particularly for strategies and complex logic structures.
Look in code to find instructions. Reach out if you need assistance.
Functionality includes:
Viewing the contents of an array or matrix on screen.
Track variables and variable updates using debug()
Track if and when local scopes fire using debugs()
Types Allowed:
string
float
int
string
debug(_col, _row, _name, _value, _msg, _ip)
Debug Variables in Matrix
Parameters:
_col (int) : (int) Assign Column
_row (int) : (int) Assign Row
_name (matrix) : (simple matrix) Matrix Name
_value (string) : (string) Assign variable as a string (str.tostring())
_msg (string)
_ip (int) : (int) (default 1) 1 for continuous updates. 2 for barstate.isnew updates. 3 for barstate.isconfirmed updates. -1 to only add once
Returns: Returns Variable _value output and _msg formatted as '_msg: variableOutput' in designated column and row
debug(_col, _row, _name, _value, _msg, _ip)
Parameters:
_col (int)
_row (int)
_name (matrix)
_value (float)
_msg (string)
_ip (int)
debug(_col, _row, _name, _value, _msg, _ip)
Parameters:
_col (int)
_row (int)
_name (matrix)
_value (int)
_msg (string)
_ip (int)
debug(_col, _row, _name, _value, _msg, _ip)
Parameters:
_col (int)
_row (int)
_name (matrix)
_value (bool)
_msg (string)
_ip (int)
debugs(_col, _row, _name, _msg)
Debug Scope in Matrix - Identify When Scope Is Accessed
Parameters:
_col (int) : (int) Column Number
_row (int) : (int) Row Number
_name (matrix) : (simple matrix) Matrix Name
_msg (string) : (string) Message
Returns: Message appears in debug panel using _col/_row as the identifier
viewArray(_arrayName, _pos, _txtSize, _tRows, s_index, s_border, _rowCol, bCol, _fillCond, _offset)
Array Element Display (Supports float , int , string , and bool )
Parameters:
_arrayName (float ) : ID of Array to be Displayed
_pos (string) : Position for Table
_txtSize (string) : Size of Table Cell Text
_tRows (int) : Number of Rows to Display Data In (columns will be calculated accordingly)
s_index (bool) : (Optional. Default True.) Show/Hide Index Numbers
s_border (bool) : (Optional. Default False.) Show/Hide Border
_rowCol (string)
bCol (color) : = (Optional. Default Black.) Frame/Border Color.
_fillCond (bool) : (Optional) Conditional statement. Function displays array only when true. For instances where size is not immediately known or indices are na. Default = true, indicating array size is set at bar_index 0.
_offset (int) : (Optional) Use to view historical array states. Default = 0, displaying realtime bar.
Returns: A Display of Array Values in a Table
viewArray(_arrayName, _pos, _txtSize, _tRows, s_index, s_border, _rowCol, bCol, _fillCond, _offset)
Parameters:
_arrayName (int )
_pos (string)
_txtSize (string)
_tRows (int)
s_index (bool)
s_border (bool)
_rowCol (string)
bCol (color)
_fillCond (bool)
_offset (int)
viewArray(_arrayName, _pos, _txtSize, _tRows, s_index, s_border, _rowCol, bCol, _fillCond, _offset)
Parameters:
_arrayName (string )
_pos (string)
_txtSize (string)
_tRows (int)
s_index (bool)
s_border (bool)
_rowCol (string)
bCol (color)
_fillCond (bool)
_offset (int)
viewArray(_arrayName, _pos, _txtSize, _tRows, s_index, s_border, _rowCol, bCol, _fillCond, _offset)
Parameters:
_arrayName (bool )
_pos (string)
_txtSize (string)
_tRows (int)
s_index (bool)
s_border (bool)
_rowCol (string)
bCol (color)
_fillCond (bool)
_offset (int)
viewMatrix(_matrixName, _pos, _txtSize, s_index, _resetIdx, s_border, bCol, _fillCond, _offset)
Matrix Element Display (Supports , , , and )
Parameters:
_matrixName (matrix) : ID of Matrix to be Displayed
_pos (string) : Position for Table
_txtSize (string) : Size of Table Cell Text
s_index (bool) : (Optional. Default True.) Show/Hide Index Numbers
_resetIdx (bool)
s_border (bool) : (Optional. Default False.) Show/Hide Border
bCol (color) : = (Optional. Default Black.) Frame/Border Color.
_fillCond (bool) : (Optional) Conditional statement. Function displays matrix only when true. For instances where size is not immediately known or indices are na. Default = true, indicating matrix size is set at bar_index 0.
_offset (int) : (Optional) Use to view historical matrix states. Default = 0, displaying realtime bar.
Returns: A Display of Matrix Values in a Table
viewMatrix(_matrixName, _pos, _txtSize, s_index, _resetIdx, s_border, bCol, _fillCond, _offset)
Parameters:
_matrixName (matrix)
_pos (string)
_txtSize (string)
s_index (bool)
_resetIdx (bool)
s_border (bool)
bCol (color)
_fillCond (bool)
_offset (int)
viewMatrix(_matrixName, _pos, _txtSize, s_index, _resetIdx, s_border, bCol, _fillCond, _offset)
Parameters:
_matrixName (matrix)
_pos (string)
_txtSize (string)
s_index (bool)
_resetIdx (bool)
s_border (bool)
bCol (color)
_fillCond (bool)
_offset (int)
viewMatrix(_matrixName, _pos, _txtSize, s_index, _resetIdx, s_border, bCol, _fillCond, _offset)
Parameters:
_matrixName (matrix)
_pos (string)
_txtSize (string)
s_index (bool)
_resetIdx (bool)
s_border (bool)
bCol (color)
_fillCond (bool)
_offset (int)
gFancyMALibrary "GalacticS2021"
printLbl(y, x, c, m, b)
Parameters:
y (float)
x (int)
c (color)
m (string)
b (bool)
Global_Public_Holidays_23_24Library "Global_Public_Holidays_23_24"
NYSE_closed()
LSE_closed()
JPX_closed()
ASX_closed()
FX_closed()
lib_plot_objectsLibrary "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 ) 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
lib_drawing_compositesLibrary "lib_drawing_composites"
methods to draw and manage composite obejects. Based on Trendoscope's added Triangle and Polygon composite objects, fixed tostring method output to be actual json
method tostring(this, format_date, format, tz, pretty)
Converts lib_drawing_types/LineProperties object to a json string representation
Namespace types: D.Point
Parameters:
this (Point type from HeWhoMustNotBeNamed/DrawingTypes/2) : lib_drawing_types/LineProperties object
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool) : if true adds a line feed after every property and a space before properties (default: true)
Returns: string representation of lib_drawing_types/LineProperties
method tostring(this, pretty)
Converts lib_drawing_types/LabelProperties object to a json string representation
Namespace types: D.LineProperties
Parameters:
this (LineProperties type from HeWhoMustNotBeNamed/DrawingTypes/2) : lib_drawing_types/LabelProperties object
pretty (simple bool) : if true adds a line feed after every property and a space before properties (default: true)
Returns: string representation of lib_drawing_types/LabelProperties
method tostring(this, format_date, format, tz, pretty)
Converts lib_drawing_types/BoxProperties object to a json string representation
Namespace types: D.Line
Parameters:
this (Line type from HeWhoMustNotBeNamed/DrawingTypes/2) : lib_drawing_types/BoxProperties object
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool) : if true adds a line feed after every property and a space before properties (default: true)
Returns: string representation of lib_drawing_types/BoxProperties
method tostring(this, pretty)
Converts lib_drawing_types/BoxText object to a json string representation
Namespace types: D.LabelProperties
Parameters:
this (LabelProperties type from HeWhoMustNotBeNamed/DrawingTypes/2) : lib_drawing_types/BoxText object
pretty (simple bool) : if true adds a line feed after every property and a space before properties (default: true)
Returns: string representation of lib_drawing_types/BoxText
method tostring(this, format_date, format, tz, pretty)
Converts lib_drawing_types/TriangleProperties object to a json string representation
Namespace types: D.Label
Parameters:
this (Label type from HeWhoMustNotBeNamed/DrawingTypes/2) : lib_drawing_types/TriangleProperties object
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool) : if true adds a line feed after every property and a space before properties (default: true)
Returns: string representation of lib_drawing_types/TriangleProperties
method tostring(this, format_date, format, tz, pretty)
Namespace types: D.Linefill
Parameters:
this (Linefill type from HeWhoMustNotBeNamed/DrawingTypes/2)
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool)
method tostring(this, pretty)
Namespace types: D.BoxProperties
Parameters:
this (BoxProperties type from HeWhoMustNotBeNamed/DrawingTypes/2)
pretty (simple bool)
method tostring(this, pretty)
Namespace types: D.BoxText
Parameters:
this (BoxText type from HeWhoMustNotBeNamed/DrawingTypes/2)
pretty (simple bool)
method tostring(this, format_date, format, tz, pretty)
Namespace types: D.Box
Parameters:
this (Box type from HeWhoMustNotBeNamed/DrawingTypes/2)
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool)
method tostring(this, pretty)
Namespace types: DC.TriangleProperties
Parameters:
this (TriangleProperties type from robbatt/lib_drawing_composite_types/1)
pretty (simple bool)
method tostring(this, format_date, format, tz, pretty)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool)
method tostring(this, format_date, format, tz, pretty)
Namespace types: DC.Trianglefill
Parameters:
this (Trianglefill type from robbatt/lib_drawing_composite_types/1)
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool)
method tostring(this, format_date, format, tz, pretty)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool)
method tostring(this, format_date, format, tz, pretty)
Namespace types: DC.Polygonfill
Parameters:
this (Polygonfill type from robbatt/lib_drawing_composite_types/1)
format_date (simple bool)
format (simple string)
tz (simple string)
pretty (simple bool)
method delete(this)
Namespace types: DC.Trianglefill
Parameters:
this (Trianglefill type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Trianglefill
Parameters:
this (Trianglefill type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Polygonfill
Parameters:
this (Polygonfill type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
method delete(this)
Namespace types: DC.Polygonfill
Parameters:
this (Polygonfill type from robbatt/lib_drawing_composite_types/1)
method clear(this)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
method clear(this)
Namespace types: DC.Trianglefill
Parameters:
this (Trianglefill type from robbatt/lib_drawing_composite_types/1)
method clear(this)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
method clear(this)
Namespace types: DC.Polygonfill
Parameters:
this (Polygonfill type from robbatt/lib_drawing_composite_types/1)
method draw(this, is_polygon_section)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
is_polygon_section (bool)
method draw(this)
Namespace types: DC.Trianglefill
Parameters:
this (Trianglefill type from robbatt/lib_drawing_composite_types/1)
method draw(this, is_polygon)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
is_polygon (bool)
method draw(this)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
method draw(this)
Namespace types: DC.Trianglefill
Parameters:
this (Trianglefill type from robbatt/lib_drawing_composite_types/1)
method draw(this)
Namespace types: DC.Polygonfill
Parameters:
this (Polygonfill type from robbatt/lib_drawing_composite_types/1)
method draw(this)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
method draw(this)
Namespace types: DC.Polygonfill
Parameters:
this (Polygonfill type from robbatt/lib_drawing_composite_types/1)
method createCenter(this, other)
Namespace types: D.Point
Parameters:
this (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
other (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
method createCenter(this)
Namespace types: D.Point
Parameters:
this (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
method createCenter(this, other1, other2)
Namespace types: D.Point
Parameters:
this (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
other1 (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
other2 (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
method createLabel(this, labeltext, tooltip, properties)
Namespace types: D.Line
Parameters:
this (Line type from HeWhoMustNotBeNamed/DrawingTypes/2)
labeltext (string)
tooltip (string)
properties (LabelProperties type from HeWhoMustNotBeNamed/DrawingTypes/2)
method createLabel(this, labeltext, tooltip, properties)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
labeltext (string)
tooltip (string)
properties (LabelProperties type from HeWhoMustNotBeNamed/DrawingTypes/2)
method createTriangle(this, p2, p3, properties)
Namespace types: D.Point
Parameters:
this (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
p2 (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
p3 (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
properties (TriangleProperties type from robbatt/lib_drawing_composite_types/1)
method createTrianglefill(this, fill_color, transparency)
Namespace types: DC.Triangle
Parameters:
this (Triangle type from robbatt/lib_drawing_composite_types/1)
fill_color (color)
transparency (int)
method createPolygonfill(this, fill_color, transparency)
Namespace types: DC.Polygon
Parameters:
this (Polygon type from robbatt/lib_drawing_composite_types/1)
fill_color (color)
transparency (int)
method createPolygon(points, properties)
Namespace types: D.Point
Parameters:
points (Point type from HeWhoMustNotBeNamed/DrawingTypes/2)
properties (TriangleProperties type from robbatt/lib_drawing_composite_types/1)