NumberOfVisibleBarsLibrary "NumberOfVisibleBars"
TODO: add library description here
NumberOfVisibleBars()
Calculates the number of visible bars on the user screen
Returns: The numbers of visible bars on the user screen (int)
지표 및 전략
lib_setLibrary "lib_set"
This is a convenience lib that bundles different setter functions allowing to update all coordinates and of line/box in one call, and coordinates and text for label.
method set_xy_text(this, x, y, txt, tooltip)
Updates a label object with new data (equals redrawing it)
Namespace types: series label
Parameters:
this (label)
x (int) : reassigns the x coordinate, optional param, no effect if x = na (same as draw(extend_only = true) for Line objects). Avoiding to reassign x can prevent errors for invalid params passed to set_x***
y (float) : reassigns the y coordinate
txt (string) : reassigns the label text
tooltip (string) : reassigns the label tooltip
method set_xy1_xy2(this, x1, y1, x2, y2)
Updates a line object with new data (equals redrawing it)
Namespace types: series line
Parameters:
this (line)
x1 (int) : reassigns the x1 coordinate, optional param, no effect if x1 = na (same as draw(extend_only = true) for Line objects). Avoiding to reassign x1 can prevent errors for invalid params passed to set_x***
y1 (float) : reassigns the y1 coordinate
x2 (int) : reassigns the x2 coordinate
y2 (float) : reassigns the y2 coordinate
method set_left_top_right_bottom(this, left, top, right, bottom)
Updates a box object with new data (equals redrawing it)
Namespace types: series box
Parameters:
this (box)
left (int) : reassigns the left coordinate, optional param, no effect if left = na (same as draw(extend_only = true) for Box objects). Avoiding to reassign 'left' can prevent errors for invalid params passed to set_x***
top (float) : reassigns the top coordinate
right (int) : reassigns the right coordinate
bottom (float) : reassigns the bottom coordinate
PRINT_DROVINGLibrary "PRINT_DROVING"
method print_droving(foot_bar, sup)
printing all footprint objects
Namespace types: footprint_type.Footprint_bar
Parameters:
foot_bar (Footprint_bar type from Alesetup/PRINT_TYPE/1) : instance of Footprint_bar type
sup (Support_objects type from Alesetup/PRINT_TYPE/1) : instance of Support_objects type
Returns: Void.
PRINT_LOGICLibrary "PRINT_LOGIC"
method fill_imba_line(imba_line, foot_bar, sup)
fill imbalance line
Namespace types: footprint_type.Imbalance_line
Parameters:
imba_line (Imbalance_line type from Alesetup/PRINT_TYPE/1) : instance of Imbalance_line type
foot_bar (Footprint_bar type from Alesetup/PRINT_TYPE/1) : instance of Footprint_bar type
sup (Support_objects type from Alesetup/PRINT_TYPE/1) : instance of Support_objects type
Returns: Void
method fill_footprint_type(foot_bar, sup)
Namespace types: footprint_type.Footprint_bar
Parameters:
foot_bar (Footprint_bar type from Alesetup/PRINT_TYPE/1) : instance of Footprint_bar type
sup (Support_objects type from Alesetup/PRINT_TYPE/1) : instance of Support_objects type
Returns: Void
method fill_footprint_object(foot_bar, sup)
fill all footprint objects
Namespace types: footprint_type.Footprint_bar
Parameters:
foot_bar (Footprint_bar type from Alesetup/PRINT_TYPE/1) : instance of Footprint_bar type
sup (Support_objects type from Alesetup/PRINT_TYPE/1) : instance of Support_objects type
Returns: Void
PRINT_TYPELibrary "PRINT_TYPE"
Inputs
Inputs objects
Fields:
inbalance_percent (series int) : percentage coefficient to determine the Imbalance of price levels
stacked_input (series int) : minimum number of consecutive Imbalance levels required to draw extended lines
show_summary_footprint (series bool)
procent_volume_area (series int) : definition size Value area
new_imbalance_cond (series bool) : bool input for setup alert on new imbalance buy and sell
new_imbalance_line_cond (series bool) : bool input for setup alert on new imbalance line buy and sell
stop_past_imbalance_line_cond (series bool) : bool input for setup alert on stop past imbalance line buy and sell
Constants
Constants all Constants objects
Fields:
imbalance_high_char (series string) : char for printing buy imbalance
imbalance_low_char (series string) : char for printing sell imbalance
color_title_sell (series color) : color for footprint sell
color_title_buy (series color) : color for footprint buy
color_line_sell (series color) : color for sell line
color_line_buy (series color) : color for buy line
color_title_none (series color) : color None
Calculation_data
Calculation_data data for calculating
Fields:
detail_open (array) : array open from calculation timeframe
detail_high (array) : array high from calculation timeframe
detail_low (array) : array low from calculation timeframe
detail_close (array) : array close from calculation timeframe
detail_vol (array) : array volume from calculation timeframe
previos_detail_close (array) : array close from calculation timeframe
isBuyVolume (series bool) : attribute previosly bar buy or sell
Footprint_row
Footprint_row objects one footprint row
Fields:
price (series float) : row price
buy_vol (series float) : buy volume
sell_vol (series float) : sell volume
imbalance_buy (series bool) : attribute buy inbalance
imbalance_sell (series bool) : attribute sell imbalance
buy_vol_box (series box) : for ptinting buy volume
sell_vol_box (series box) : for printing sell volume
buy_vp_box (series box) : for ptinting volume profile buy
sell_vp_box (series box) : for ptinting volume profile sell
row_line (series label) : for ptinting row price
empty (series bool) : = true attribute row with zero volume buy and zero volume sell
Imbalance_line_var_object
Imbalance_line_var_object var objects printing and calculation imbalance line
Fields:
cum_buy_line (array) : line array for saving all history buy imbalance line
cum_sell_line (array) : line array for saving all history sell imbalance line
Imbalance_line
Imbalance_line objects printing and calculation imbalance line
Fields:
buy_price_line (array) : float array for saving buy imbalance price level
sell_price_line (array) : float array for saving sell imbalance price level
var_imba_line (Imbalance_line_var_object) : var objects this type
Footprint_bar
Footprint_bar all objects one bar with footprint
Fields:
foot_rows (array) : objects one row footprint
imba_line (Imbalance_line) : objects imbalance line
row_size (series float) : size rows
total_vol (series float) : total volume one footprint bar
foot_buy_vol (series float) : buy volume one footprint bar
foot_sell_vol (series float) : sell volume one footprint bar
foot_max_price_vol (map) : map with one value - price row with max volume buy + sell
calc_data (Calculation_data) : objects with detail data from calculation resolution
Support_objects
Support_objects support object for footprint calculation
Fields:
consts (Constants) : all consts objects
inp (Inputs) : all input objects
bar_index_show_condition (series bool) : calculation bool value for show all objects footprint
row_line_color (series color) : calculation value - color for row price
dop_info (series string)
show_table_cond (series bool)
TimeLibraryLibrary "TimeLibrary"
TODO: add library description here
Line_Type_Control(Type)
Line_Type_Control: This function changes between common line types options available are "Solid","Dashed","Dotted"
Parameters:
Type (string) : : The string to choose the line type from
Returns: Line_Type : returns the pine script equivalent of the string input
Text_Size_Switch(Text_Size)
Text_Size_Switch : This function changes between common text sizes options are "Normal", "Tiny", "Small", "Large", "Huge", "Auto"
Parameters:
Text_Size (string) : : The string to choose the text type from
Returns: Text_Type : returns the pine script equivalent of the string input
TF(TF_Period, TF_Multip)
TF generates a string representation of a time frame based on the provided time frame unit (`TF_Period`) and multiplier (`TF_Multip`).
Parameters:
TF_Period (simple string)
TF_Multip (simple int)
Returns: A string that represents the time frame in Pine Script format, depending on the `TF_Period`:
- For "Minute", it returns the multiplier as a string (e.g., "5" for 5 minutes).
- For "Hour", it returns the equivalent number of minutes (e.g., "120" for 2 hours).
- For "Day", it appends "D" to the multiplier (e.g., "2D" for 2 days).
- For "Week", it appends "W" to the multiplier (e.g., "1W" for 1 week).
- For "Month", it appends "M" to the multiplier (e.g., "3M" for 3 months).
If none of these cases match, it returns the current chart's time frame.
TF_Display(Chart_as_Timeframe, TF_Period, TF_Multip)
TF_Display generates a string representation of a time frame based on user-defined inputs or the current chart's time frame settings.
Parameters:
Chart_as_Timeframe (bool) : (bool): Determines whether to use the current chart's time frame or a custom time frame.
TF_Period` (string): The time frame unit (e.g., "Minute", "Hour", "Day", "Week", "Month").
TF_Multip` (int): The multiplier for the time frame (e.g., 15 for 15 minutes, 2 for 2 days).
TF_Period (string)
TF_Multip (int)
Returns: If `Chart_as_Timeframe` is `false`, the function returns a time frame string based on the provided `TF_Period` and `TF_Multip` values (e.g., "5Min", "2D").
If `Chart_as_Timeframe` is `true`, the function determines the current chart's time frame and returns it as a string:
For minute-based time frames, it returns the number of minutes with "Min" (e.g., "15Min") unless it's an exact hour, in which case it returns the hour (e.g., "1H").
For daily, weekly, and monthly time frames, it returns the multiplier with the appropriate unit (e.g., "1D" for daily, "1W" for weekly, "1M" for monthly).
MTF_MS_Display(Chart_as_Timeframe, TF_Period, TF_Multip, Swing_Length)
MTF_MS_Display This function calculates and returns a modified swing length value based on the selected time frame and current chart's time frame.
Parameters:
Chart_as_Timeframe (bool)
TF_Period (string)
TF_Multip (int)
Swing_Length (int)
HTF_Structure_Control(Chart_as_Timeframe, Show_Only_On_Lower_Timeframes, TF_Period, TF_Multip)
Parameters:
Chart_as_Timeframe (bool)
Show_Only_On_Lower_Timeframes (bool)
TF_Period (string)
TF_Multip (int)
HTFBands█ OVERVIEW
Contains type and methods for drawing higher-timeframe bands of several types:
Bollinger bands
Parabolic SAR
Supertrend
VWAP
By copy pasting ready made code sections to your script you can add as many multi-timeframe bands as necessary.
█ HOW TO USE
Please see instructions in the code. (Important: first fold all sections of the script: press Cmd + K then Cmd + - (for Windows Ctrl + K then Ctrl + -)
█ FULL LIST OF FUNCTIONS AND PARAMETERS
atr2(length)
An alternate ATR function to the `ta.atr()` built-in, which allows a "series float"
`length` argument.
Parameters:
length (float) : (series int/float) Length for the smoothing parameter calculation.
Returns: (float) The ATR value.
pine_supertrend2(factor, atrLength, wicks)
An alternate SuperTrend function to `supertrend()`, which allows a "series float"
`atrLength` argument.
Parameters:
factor (float) : (series int/float) Multiplier for the ATR value.
atrLength (float) : (series int/float) Length for the ATR smoothing parameter calculation.
wicks (simple bool) : (simple bool) Condition to determine whether to take candle wicks into account when
reversing trend, or to use the close price. Optional. Default is false.
Returns: ( ) A tuple of the superTrend value and trend direction.
method getDefaultBandQ1(bandType)
For a given BandType returns its default Q1
Namespace types: series BandTypes
Parameters:
bandType (series BandTypes)
method getDefaultBandQ2(bandType)
For a given BandType returns its default Q2
Namespace types: series BandTypes
Parameters:
bandType (series BandTypes)
method getDefaultBandQ3(bandType)
For a given BandType returns its default Q3
Namespace types: series BandTypes
Parameters:
bandType (series BandTypes)
method init(this, bandsType, q1, q2, q3, vwapAnchor)
Initiates RsParamsBands for each band (used in htfUpdate() withi req.sec())
Namespace types: RsParamsBands
Parameters:
this (RsParamsBands)
bandsType (series BandTypes)
q1 (float) : (float) Depending on type: BB - length, SAR - AF start, ST - ATR's prd
q2 (float) : (float) Depending on type: BB - StdDev mult, SAR - AF step, ST - mult
q3 (float) : (float) Depending on type: BB - not used, SAR - AF max, ST - not used
vwapAnchor (series VwapAnchors) : (VwapAnchors) VWAP ahcnor
method init(this, bandsType, tf, showRecentBars, lblsShow, lblsMaxLabels, lblSize, lnMidClr, lnUpClr, lnLoClr, fill, fillClr, lnWidth, lnSmoothen)
Initialises object with params (incl. input). Creates arrays if any.
Namespace types: HtfBands
Parameters:
this (HtfBands)
bandsType (series BandTypes) : (BandTypes) Just used to enable/disable - if BandTypes.none then disable )
tf (string) : (string) Timeframe
showRecentBars (int) : (int) Only show over this number of recent bars
lblsShow (bool) : (bool) Show labels
lblsMaxLabels (int) : (int) Max labels to show
lblSize (string) : (string) Size of the labels
lnMidClr (color) : (color) Middle band color
lnUpClr (color) : (color) Upper band color
lnLoClr (color) : (color) Lower band color
fill (bool)
fillClr (color) : (color) Fill color
lnWidth (int) : (int) Line width
lnSmoothen (bool) : (bool) Smoothen the bands
method htfUpdateTuple(rsPrms, repaint)
(HTF) Calculates Bands within request.security(). Returns tuple . If any or all of the bands are not available returns na as their value.
Namespace types: RsParamsBands
Parameters:
rsPrms (RsParamsBands) : (RsParamsBands) Parameters of the band.
repaint (bool) : (bool) If true does not update on realtime bars.
Returns: A tuple (corresponds to fields in RsReturnBands)
method importRsRetTuple(this, htfBi, mid, up, lo, dir)
Imports a tuple returned from req.sec() into an HtfBands object
Namespace types: HtfBands
Parameters:
this (HtfBands) : (HtfBands) Object to import to
htfBi (int) : (float) Higher timeframe's bar index (Default = na)
mid (float)
up (float) : (float) Value of upper band (Default = na)
lo (float) : (float) Value of lower band (Default = na)
dir (int) : (int) Direction (for bands like Parabolic SAR) (Default = na)
method addUpdDrawings(this, rsPrms)
Draws band's labels
Namespace types: HtfBands
Parameters:
this (HtfBands)
rsPrms (RsParamsBands)
method update(this)
Sets band's values to na on intrabars if `smoothen` is set.
Namespace types: HtfBands
Parameters:
this (HtfBands)
method newRsParamsBands(this)
A wraper for RsParamsBands.new()
Namespace types: LO_A
Parameters:
this (LO_A)
method newHtfBands(this)
A wraper for HtfBands.new()
Namespace types: LO_B
Parameters:
this (LO_B)
RsParamsBands
Used to pass bands' params to req.sec()
Fields:
bandsType (series BandTypes) : (enum BandTypes) Type of the band (BB, SAR etc.)
q1 (series float) : (float) Depending on type: BB - length, SAR - AF start, ST - ATR's prd
q2 (series float) : (float) Depending on type: BB - StdDev mult, SAR - AF step, ST - mult
q3 (series float) : (float) Depending on type: BB - not used, SAR - AF max, ST - not used
vwapAnchor (series VwapAnchors)
RsReturnBands
Used to return bands' data from req.sec(). Params of the bands are in RsParamsBands
Fields:
htfBi (series float) : (float) Higher timeframe's bar index (Default = na)
upBand (series float) : (float) Value of upper band (Default = na)
loBand (series float) : (float) Value of lower band (Default = na)
midBand (series float) : (float) Value of middle band (Default = na)
dir (series int) : (float) Direction (for bands like Parabolic SAR) (Default = na)
BandsDrawing
Contains plot visualization parameters and stores and keeps track of lines, labels and other visual objects (not plots)
Fields:
lnMidClr (series color) : (color) Middle band color
lnLoClr (series color) : (color) Lower band color
lnUpClr (series color) : (color) Upper band color
fillUpClr (series color)
fillLoClr (series color)
lnWidth (series int) : (int) Line width
lnSmoothen (series bool) : (bool) Smoothen the bands
showHistory (series bool) : (bool) If true show bands lines, otherwise only current level
showRecentBars (series int) : (int) Only show over this number of recent bars
arLbl (array) : (label Labels
lblsMaxLabels (series int) : (int) Max labels to show
lblsShow (series bool) : (bool) Show labels
lblSize (series string) : (string) Size of the labels
HtfBands
Calcs and draws HTF bands
Fields:
rsRet (RsReturnBands) : (RsReturnBands) Bands' values
rsRetNaObj (RsReturnBands) : (RsReturnBands) Dummy na obj for returning from request.security()
rsPrms (RsParamsBands) : (RsParamsBands) Band parameters (for htfUpdate() called in req.sec() )
drw (BandsDrawing) : (BandsDrawing) Contains plot visualization parameters and stores and keeps track of lines, labels and other visual objects (not plots)
enabled (series bool) : (bool) Toggles bands on/off
tf (series string) : (string) Timeframe
LO_A
LO Library object, whose only purpose is to serve as a shorthand for library name in script code.
Fields:
dummy (series string)
LO_B
LO Library object, whose only purpose is to serve as a shorthand for library name in script code.
Fields:
dummy (series string)
HTFMAs█ OVERVIEW
Contains a type HTFMA used to return data on six moving averages from a higher timeframe.
Several types of MA's are supported.
█ HOW TO USE
Please see instructions in the code (in library description). (Important: first fold all sections of the script: press Cmd + K then Cmd + - (for Windows Ctrl + K then Ctrl + -)
█ FULL LIST OF FUNCTIONS AND PARAMETERS
method getMaType(this)
Enumerator function, given a key returns `enum MaTypes` value
Namespace types: series string, simple string, input string, const string
Parameters:
this (string)
method init(this, enableAll, ma1Enabled, ma1MaType, ma1Src, ma1Prd, ma2Enabled, ma2MaType, ma2Src, ma2Prd, ma3Enabled, ma3MaType, ma3Src, ma3Prd, ma4Enabled, ma4MaType, ma4Src, ma4Prd, ma5Enabled, ma5MaType, ma5Src, ma5Prd, ma6Enabled, ma6MaType, ma6Src, ma6Prd)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs)
enableAll (simple MaEnable)
ma1Enabled (bool)
ma1MaType (series MaTypes)
ma1Src (string)
ma1Prd (int)
ma2Enabled (bool)
ma2MaType (series MaTypes)
ma2Src (string)
ma2Prd (int)
ma3Enabled (bool)
ma3MaType (series MaTypes)
ma3Src (string)
ma3Prd (int)
ma4Enabled (bool)
ma4MaType (series MaTypes)
ma4Src (string)
ma4Prd (int)
ma5Enabled (bool)
ma5MaType (series MaTypes)
ma5Src (string)
ma5Prd (int)
ma6Enabled (bool)
ma6MaType (series MaTypes)
ma6Src (string)
ma6Prd (int)
method init(this, enableAll, tf, rngAtrQ, showRecentBars, lblsOffset, lblsShow, lnOffset, lblSize, lblStyle, smoothen, ma1lnClr, ma1lnWidth, ma1lnStyle, ma2lnClr, ma2lnWidth, ma2lnStyle, ma3lnClr, ma3lnWidth, ma3lnStyle, ma4lnClr, ma4lnWidth, ma4lnStyle, ma5lnClr, ma5lnWidth, ma5lnStyle, ma6lnClr, ma6lnWidth, ma6lnStyle, ma1ShowHistory, ma2ShowHistory, ma3ShowHistory, ma4ShowHistory, ma5ShowHistory, ma6ShowHistory, ma1ShowLabel, ma2ShowLabel, ma3ShowLabel, ma4ShowLabel, ma5ShowLabel, ma6ShowLabel)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
enableAll (series MaEnable)
tf (string)
rngAtrQ (int)
showRecentBars (int)
lblsOffset (int)
lblsShow (bool)
lnOffset (int)
lblSize (string)
lblStyle (string)
smoothen (bool)
ma1lnClr (color)
ma1lnWidth (int)
ma1lnStyle (string)
ma2lnClr (color)
ma2lnWidth (int)
ma2lnStyle (string)
ma3lnClr (color)
ma3lnWidth (int)
ma3lnStyle (string)
ma4lnClr (color)
ma4lnWidth (int)
ma4lnStyle (string)
ma5lnClr (color)
ma5lnWidth (int)
ma5lnStyle (string)
ma6lnClr (color)
ma6lnWidth (int)
ma6lnStyle (string)
ma1ShowHistory (bool)
ma2ShowHistory (bool)
ma3ShowHistory (bool)
ma4ShowHistory (bool)
ma5ShowHistory (bool)
ma6ShowHistory (bool)
ma1ShowLabel (bool)
ma2ShowLabel (bool)
ma3ShowLabel (bool)
ma4ShowLabel (bool)
ma5ShowLabel (bool)
ma6ShowLabel (bool)
method get(this, id)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs)
id (int)
method set(this, id, prop, val)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs)
id (int)
prop (string)
val (string)
method set(this, id, prop, val)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
id (int)
prop (string)
val (string)
method htfUpdateTuple(rsParams, repaint)
Namespace types: RsParamsMAs
Parameters:
rsParams (RsParamsMAs)
repaint (bool)
method clear(this)
Namespace types: MaDrawing
Parameters:
this (MaDrawing)
method importRsRetTuple(this, htfBi, ma1, ma2, ma3, ma4, ma5, ma6)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
htfBi (int)
ma1 (float)
ma2 (float)
ma3 (float)
ma4 (float)
ma5 (float)
ma6 (float)
method getDrw(this, id)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
id (int)
method setDrwProp(this, id, prop, val)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
id (int)
prop (string)
val (string)
method initDrawings(this, rsPrms, dispBandWidth)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
rsPrms (RsParamsMAs)
dispBandWidth (float)
method updateDrawings(this, rsPrms, dispBandWidth)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
rsPrms (RsParamsMAs)
dispBandWidth (float)
method update(this)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps0 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps1 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps2 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps3 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps4 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps5 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `RsParamsMAs` child `RsMaCalcParams` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (RsParamsMAs) Target object to import prop values to.
oCfg (objProps6 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs)
oCfg (objProps7 type from moebius1977/CSVParser/1)
maCount (int)
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: RsParamsMAs
Parameters:
this (RsParamsMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps8 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps0 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps1 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps2 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps3 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps4 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps5 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Imports HTF MAs settings from objProps (of any level) into `HTFMAs` child `MaDrawing` objects (into the first first `maCount` of them)
Namespace types: HTFMAs
Parameters:
this (HTFMAs) : (HTFMAs) Target object to import prop values to.
oCfg (objProps6 type from moebius1977/CSVParser/1) : (CSVP.objProps) (one of objProps types) an objProps, ... opjProps8 containing properties' values in a child objProps objects
maCount (int) : (int) Number of tgtObj's RsMaCalcParams childs of tgtObj to set (1 to 6, starting from 1)
Returns: this
method importConfig(this, oCfg, maCount)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
oCfg (objProps7 type from moebius1977/CSVParser/1)
maCount (int)
method importConfig(this, oCfg, maCount)
Namespace types: HTFMAs
Parameters:
this (HTFMAs)
oCfg (objProps8 type from moebius1977/CSVParser/1)
maCount (int)
method newRsParamsMAs(this)
Namespace types: LO
Parameters:
this (LO)
method newHTFMAs(this)
Namespace types: LO
Parameters:
this (LO)
RsMaCalcParams
Parameters of one MA (only calculation params needed within req.sec(), visual parameters are within htfMAs type)
Fields:
enabled (series bool)
maType (series MaTypes) : MA type options: SMA / EMA / WMA / ...
src (series string)
prd (series int) : MA period
RsParamsMAs
Collection of parameters of 6 MAs. Used to pass params to req.sec()
Fields:
ma1CalcParams (RsMaCalcParams)
ma2CalcParams (RsMaCalcParams)
ma3CalcParams (RsMaCalcParams)
ma4CalcParams (RsMaCalcParams)
ma5CalcParams (RsMaCalcParams)
ma6CalcParams (RsMaCalcParams)
RsReturnMAs
Used to return data from req.sec().
Fields:
htfBi (series int)
ma1 (series float)
ma2 (series float)
ma3 (series float)
ma4 (series float)
ma5 (series float)
ma6 (series float)
MaDrawing
MA's plot parameters plus drawing objects for MA's current level (line and label).
Fields:
lnClr (series color) : (color) MA plot line color (like in plot())
lnWidth (series int) : (int) MA plot line width (like in plot())
lnStyle (series string) : (string) MA plot line style (like in plot())
showHistory (series bool) : (bool) Whether to plot the MA on historical bars or only show current level to the right of the latest bar.
showLabel (series bool) : (bool) Whether to show the name of the MA to the right of the MA's level
ln (series line) : (line) line to show MA"s current level
lbl (series label) : (label) label showing MA's name
HTFMAs
Contains data and drawing parameters for MA's of one timeframe (MA calculation parameters for MA's of one timeframe are in a separate object RsParamsMAs)
Fields:
rsRet (RsReturnMAs) : (RsReturnMAs) Contains data returned from req.sec(). Is set to na in between HTF bar changes if smoothing is enabled.
rsRetLast (RsReturnMAs) : (RsReturnMAs) Contains a copy of data returned from req.sec() in case rsRet is set to na for smoothing.
rsRetNaObj (RsReturnMAs) : (RsReturnMAs) An empty object as `na` placeholder
ma1Drawing (MaDrawing) : (MaDrawing) MA drawing properties
ma2Drawing (MaDrawing) : (MaDrawing) MA drawing properties
ma3Drawing (MaDrawing) : (MaDrawing) MA drawing properties
ma4Drawing (MaDrawing) : (MaDrawing) MA drawing properties
ma5Drawing (MaDrawing) : (MaDrawing) MA drawing properties
ma6Drawing (MaDrawing) : (MaDrawing) MA drawing properties
enabled (series bool) : (bool ) Enables/disables all of the MAs of one timeframe.
tf (series string) : (string) Timeframe
showHistory (series bool) : (bool ) Plot MA line on historical bars
rngAtrQ (series int) : (int ) A multiplier for atr(14). Determines a range within which the MA's will be plotted. MA's too far away will not be plotted.
showRecentBars (series int) : (int ) Only plot MA on these recent bars
smoothen (series bool) : (bool ) Smoothen MA plot. If false the same HTF value is returned on all chart bars within a HTF bar (intrabars), so the plot looks like steps.
lblsOffset (series int) : (int ) Show MA name this number of bars to the right off last bar.
lblsShow (series bool) : (bool ) Show MA name
lnOffset (series int) : (int ) Start line showing current level of the MA this number of bars to the right off the last bar.
lblSize (series string) : (string) Label size
lblStyle (series string) : (string) Label style
lblTxtAlign (series string) : (string) Label text align
bPopupLabel (series bool) : (bool ) Show current MA value as a tooltip to MA's name.
LO
LO Library object, whose only purpose is to serve as a shorthand for library name in script code.
Fields:
dummy (series string)
CSVParser█ OVERVIEW
The library contains functions for parsing and importing complex CSV configurations (with a special simple syntax) into a special hierarchical object (of type objProps ) as follows:
Functions:
parseConfig() - reads CSV text into an objProps object.
toT() - displays the contents of an objProps object in a table form, which allows to check the CSV text for syntax errors.
getPropAr() - returns objProps.arS array for child object with `prop` key in mpObj map (or na if not found)
This library is handy in allowing users to store presets for the scripts and switch between them (see, e.g., my HTF moving averages script where users can switch between several preset configuations of 24 MA's across 5 timeframes).
█ HOW THE SCRIPT WORKS.
The script works as follows:
all values read from config text are stored as strings
Nested brackets in config text create a named nested objects of objProps0, ... , objProps9 types.
objProps objects of each level have the following fields:
- array arS for storing values without names (e.g. "12, 23" will be imported into a string array arS as )
- map mpS for storing items with names (e.g. "tf = 60, length = 21" will be imported as <"tf", "60"> and <"length", "21"> pairs into mpS )
- map mpObj for storing nested objects (e.g. "TF1(tf=60, length(21,50,100))" creates a <"TF1, objProps0 object> pair in mpObj map property of the top level object (objProps) , "tf=60" is stored as <"tf", "60"> key-value pair in mpS map property of a next level object (objProps0) and "length (...)" creates a <"length", objProps1> pair in objProps0.mpObj map while length values are stored in objProps1.arS array as strings. Every opening bracket creates a next level objProps object.
If objects or properties with duplicate names are encountered only the latest is imported
(e.g. for "TF1(length(12,22)), TF1(tf=240)" only "TF1(tf=240)" will be imported
Line breaks are not regarded as part of syntax (i.e. values are imported with line breaks, you can supply
symbols "(" , ")" , "," and "=" are special characters and cannot be used within property values (with the exception of a quoted text as a value of a property as explained below)
named properties can have quoted text as their value. In that case special characters within quotation marks are regarded as normal characters. Text between "=" and opening quotation mark as well as text following the closing quotation mark and until next property value is ignored. E.g. "quote = ignored "The quote" also ignored" will be imported as <"quote", "The quote">. Quotation marks within quotes must be excaped with "\" .
if a key names happens to be a multi-line then only first line containing non-space characters (trimmed from spaces) is taken as a key.
")," or ") ," and similar do not create an empty ("") array item while ",," does. (",)" creates an "" array item)
█ CSV CONFIGURATION SYNTAX
Unnamed values: just list them comma separated and they will be imported into arS of the object of the current level.
Named values: use "=" sign as follows: "property1=value1, property2 = value2"
Value of several objects: Use brackets after the name of the object ant list all object properties within the brackets (including its child objects if necessary). E.g. "TF1(tf =60, length(21,200), TF2(tf=240, length(50,200)"
Named and unnamed values as well as objects can go in any order. E.g. "12, tf=60, 21" will be imported as follows: "12", "21" will go to arS array and <"tf", "60"> will go to mpS maP of objProps (the top level object).
You can play around and test your config text using demo in this library, just edit your text in script settings and see how it is parsed into objProps objects.
█ USAGE RECOMMENDATIONS AND SAMPLE USE
I suggest the following approach:
- create functions for your UDT which can set properties by name.
- create enumerator functions which iterates through all the property names (supplied as a const string array) and imports their values into the object
█ SAMPLE USE
A sample use of this library can be seen in my Multi-timeframe 24 moving averages + BB+SAR+Supertrend+VWAP script where settings for the MAs across many timeframes are imported from CSV configurations (presets).
█ FULL LIST OF FUNCTIONS AND PROPERTIES
nzs(_s, nz)
Like nz() but for strings. Returns `nz` arg (default = "") if _s is na.
Parameters:
_s (string)
nz (string)
method init(this)
Initializes objProps obj (creates child maps and arrays)
Namespace types: objProps
Parameters:
this (objProps)
method toT(this, nz)
Outputs objProps to string matrices for further display using autotable().
Namespace types: objProps, objProps1, ..., objProps9
Parameters:
this (objProps/objProps1/..../objProps9)
nz (string)
Returns: A tuple - value, merge and color matrix (autotable() parameters)
method parseConfig(this, s)
Reads config text into objProps (unnamed values into arS, named into mpS, sub-levels into mpObj)
Namespace types: objProps
Parameters:
this (objProps)
s (string)
method getPropArS(this, prop)
Returns a string array of values for a given property name `prop`. Looks for a key `prop` in objProps.mpObj
if finds pair returns obj.arS, otherwise returns na. Returns a reference to the original, not a copy.
Namespace types: objProps, objProps1, ..., objProps8
Parameters:
this (objProps/objProps1/..../objProps8)
prop (string)
method getPropVal(this, prop, id)
Checks if there is an array of values for property `prop` and returns its `id`'s element or na if not found
Namespace types: objProps, objProps1, ..., objProps8
Parameters:
this (objProps/objProps1/..../objProps8) : objProps object containing array of property values in a child objProp object corresponding to propertty name.
prop (string) : (string) Name of the property
id (int) : (int) Id of the element to be returned from the array pf property values
objProps9 type
Object for storing values read from CSV relating to a particular object or property name.
Fields:
mpS (map) : (map() Stores property values as pairs
arS (array) : (string ) Array of values
objProps, objProps0, ... objProps8 types
Object for storing values read from CSV relating to a particular object or property name.
Fields:
mpS (map) : (map() Stores property values as pairs
arS (array) : (string ) Array of values
mpObj (map) : (map() Stores objProps objects containing properties's data as pairs
Autotable█ OVERVIEW
The library allows to automatically draw a table based on a string or float matrix (or both) controlling all of the parameters of the table (including merging cells) with parameter matrices (like, e.g. matrix of cell colors).
All things you would normally do with table.new() and table.cell() are now possible using respective parameters of library's main function, autotable() (as explained further below).
Headers can be supplied as arrays.
Merging of the cells is controlled with a special matrix of "L" and "U" values which instruct a cell to merged with the cell to the left or upwards (please see examples in the script and in this description).
█ USAGE EXAMPLES
The simplest and most straightforward:
mxF = matrix.new(3,3, 3.14)
mxF.autotable(bgcolor = color.rgb(249, 209, 29)) // displays float matrix as a table in the top right corner with defalult settings
mxS = matrix.new(3,3,"PI")
// displays string matrix as a table in the top right corner with defalult settings
mxS.autotable(Ypos = "bottom", Xpos = "right", bgcolor = #b4d400)
// displays matrix displaying a string value over a float value in each cell
mxS.autotable(mxF, Ypos = "middle", Xpos = "center", bgcolor = color.gray, text_color = #86f62a)
Draws this:
Tables with headers:
if barstate.islast
mxF = matrix.new(3,3, 3.14)
mxS = matrix.new(3,3,"PI")
arColHeaders = array.from("Col1", "Col2", "Col3")
arRowHeaders = array.from("Row1", "Row2", "Row3")
// float matrix with col headers
mxF.autotable(
bgcolor = #fdfd6b
, arColHeaders = arColHeaders
)
// string matrix with row headers
mxS.autotable(arRowHeaders = arRowHeaders, Ypos = "bottom", Xpos = "right", bgcolor = #b4d400)
// string/float matrix with both row and column headers
mxS.autotable(mxF
, Ypos = "middle", Xpos = "center"
, arRowHeaders = arRowHeaders
, arColHeaders = arColHeaders
, cornerBgClr = #707070, cornerTitle = "Corner cell", cornerTxtClr = #ffdc13
, bgcolor = color.gray, text_color = #86f62a
)
Draws this:
█ FUNCTIONS
One main function is autotable() which has only one required argument mxValS, a string matrix.
Please see below the description of all of the function parameters:
The table:
tbl (table) (Optional) If supplied, this table will be deleted.
The data:
mxValS (matrix ) (Required) Cell text values
mxValF (matrix) (Optional) Numerical part of cell text values. Is concatenated to the mxValS values via `string_float_separator` string (default " ")
Table properties, have same effect as in table.new() :
defaultBgColor (color) (Optional) bgcolor to be used if mxBgColor is not supplied
Ypos (string) (Optional) "top", "bottom" or "center"
Xpos (string) (Optional) "left", "right", or "center"
frame_color (color) (Optional) frame_color like in table.new()
frame_width (int) (Optional) frame_width like in table.new()
border_color (color) (Optional) border_color like in table.new()
border_width (int) (Optional) border_width like in table.new()
force_overlay (simple bool) (Optional) If true draws table on main pane.
Cell parameters, have same effect as in table.cell() ):
mxBgColor (matrix) (Optional) like bgcolor argument in table.cell()
mxTextColor (matrix) (Optional) like text_color argument in table.cell()
mxTt (matrix) (Optional) like tooltip argument in table.cell()
mxWidth (matrix) (Optional) like width argument in table.cell()
mxHeight (matrix) (Optional) like height argument in table.cell()
mxHalign (matrix) (Optional) like text_halign argument in table.cell()
mxValign (matrix) (Optional) like text_valign argument in table.cell()
mxTextSize (matrix) (Optional) like text_size argument in table.cell()
mxFontFamily (matrix) (Optional) like text_font_family argument in table.cell()
Other table properties:
tableWidth (float) (Optional) Overrides table width if cell widths are non zero. E.g. if there are four columns and cell widths are 20 (either as set via cellW or via mxWidth) then if tableWidth is set to e.g. 50 then cell widths will be 50 * (20 / 80), where 80 is 20*4 = total width of all cells. Works simialar for widths set via mxWidth - determines max sum of widths across all cloumns of mxWidth and adjusts cell widths proportionally to it. If cell widths are 0 (i.e. auto-adjust) tableWidth has no effect.
tableHeight (float) (Optional) Overrides table height if cell heights are non zero. E.g. if there are four rows and cell heights are 20 (either as set via cellH or via mxHeight) then if tableHeigh is set to e.g. 50 then cell heights will be 50 * (20 / 80), where 80 is 20*4 = total height of all cells. Works simialar for heights set via mxHeight - determines max sum of heights across all cloumns of mxHeight and adjusts cell heights proportionally to it. If cell heights are 0 (i.e. auto-adjust) tableHeight has no effect.
defaultTxtColor (color) (Optional) text_color to be used if mxTextColor is not supplied
text_size (string) (Optional) text_size to be used if mxTextSize is not supplied
font_family (string) (Optional) cell text_font_family value to be used if a value in mxFontFamily is no supplied
cellW (float) (Optional) cell width to be used if a value in mxWidth is no supplied
cellH (float) (Optional) cell height to be used if a value in mxHeight is no supplied
halign (string) (Optional) cell text_halign value to be used if a value in mxHalign is no supplied
valign (string) (Optional) cell text_valign value to be used if a value in mxValign is no supplied
Headers parameters:
arColTitles (array) (Optional) Array of column titles. If not na a header row is added.
arRowTitles (array) (Optional) Array of row titles. If not na a header column is added.
cornerTitle (string) (Optional) If both row and column titles are supplied allows to set the value of the corner cell.
colTitlesBgColor (color) (Optional) bgcolor for header row
colTitlesTxtColor (color) (Optional) text_color for header row
rowTitlesBgColor (color) (Optional) bgcolor for header column
rowTitlesTxtColor (color) (Optional) text_color for header column
cornerBgClr (color) (Optional) bgcolor for the corner cell
cornerTxtClr (color) (Optional) text_color for the corner cell
Cell merge parameters:
mxMerge (matrix) (Optional) A matrix determining how cells will be merged. "L" - cell merges to the left, "U" - upwards.
mergeAllColTitles (bool) (Optional) Allows to print a table title instead of column headers, merging all header row cells and leaving just the value of the first cell. For more flexible options use matrix arguments leaving header/row arguments na.
mergeAllRowTitles (bool) (Optional) Allows to print one text value merging all header row cells and leaving just the value of the first cell. For more flexible options use matrix arguments leaving header/row arguments na.
Format:
string_float_separator (string) (Optional) A string used to separate string and float parts of cell values (mxValS and mxValF). Default is " "
format (string) (Optional) format string like in str.format() used to format numerical values
nz (string) (Optional) Determines how na numerical values are displayed.
The only other available function is autotable(string,... ) with a string parameter instead of string and float matrices which draws a one cell table.
█ SAMPLE USE
E.g., CSVParser library demo uses Autotable's for generating complex tables with merged cells.
█ CREDITS
The library was inspired by @kaigouthro's matrixautotable . A true master. Many thanks to him for his creative, beautiful and very helpful libraries.
StrTrimPadCase█ OVERVIEW
Contains various functions for manipulation with strings:
- padright() / padleft() - Pad a string to the right or left with a given char.
- trim2() - Trims not only spaces but also line breaks.
- nz(string) - like nz(), replaces na with a supplied string
█ FUNCTIONS
nz(s, replacement)
Similar to nz() but for strings. However, since `string(na)` is the same as `""`
there is no such thing as `na` for strings. So, the function just replaces `""` with `replacement`.
Parameters:
s (string)
replacement (string) : (string) (Optional) A string returned when `s` is `""` / `na`. Default: `""`
method toUppercase(s)
Converts a string to uppercase
Namespace types: series string, simple string, input string, const string
Parameters:
s (string)
method toLowercase(s)
Converts a string to uppercase
Namespace types: series string, simple string, input string, const string
Parameters:
s (string)
method padright(this, length, char)
pads a string up to `length` by adding `char`'s (spaces by default) to the end. (the first char of `char`
string is used). Respects max string length of 4096.
Namespace types: series string, simple string, input string, const string
Parameters:
this (string)
length (int)
char (simple string) : (string) A char to pad with. (if string longer than one char is supplied uses the first char)
method padleft(this, length, char)
pads a string up to `length` by adding `char`'s (spaces by default) to the beginning(the first char of
`char` string is used). Respects max string length of 4096.
Namespace types: series string, simple string, input string, const string
Parameters:
this (string)
length (int)
char (simple string) : (string) A char to pad with. (if string longer than one char is supplied uses the first char)
StrConcatWrap█ OVERVIEW
Contains functions for concatenation and wrapping of the strings:
- concatTrunc() / concatTrunc2() - Concatenate via a separator up to a given length truncating from left or right. concatTrunc2 returns also the number of overflowing chars (in a tuple)
- print() - A powerful concatenate function truncating chars from left or right and/or lines from top or bottom. By default just adds new lines respecting max length.
- wrap() - Wraps each line of the text adding prefix/postfix. If resulting string exceeds max length truncates from the end adding " "
- scroll() Returns a range of lines from the source string.
█ FUNCTIONS
method concatTrunc2(this, txt, separator, max_length, truncate_left, ignore_empty_strings)
Concatenates two strings leaving _max_length chars truncating from left/right. (Truncates from the end of the string by default).
this String to which txt is added
txt String to be added
max_length (int) (Optional) max length of string, default: 4096
separator (string) (Optional) If both this and txt are non empty separator is added in between. Usually " " is used.
truncate_left (bool) (Optional) if true truncates left string (this), if false - txt. Default - false (truncates txt)
ignore_empty_strings (bool) (Optional) if true and one of `this` or `txt` is empty just returns the other, if false - adds separator.
Returns: (tuple ) A tuple . E.g. if `this` is 4095 chars and separator is 2 chars then 4095+2=4097 exceeds default max_length = 4096 by 1, so will be returned, even if , e.g. `txt` is empty and `ignore_empty_strings` is true.
method concatTrunc(this, txt, separator, max_length, truncate_left, ignore_empty_strings)
Concatenates two strings leaving _max_length chars truncating from left/right. (Truncates from the end of the string by default).
this : string to which txt is added
txt : string to be added to this
max_length : max length of string, default: 4096
separator : If both this and txt are non empty separator is added in between. Usually " " is used.
truncate_left : if true truncates left string (this), if false - txt. Default - false (truncates txt)
ignore_empty_strings : (bool) (Optional) if true and one of `this` or `txt` is empty just returns the other, if false - adds separator.
Returns: (string) Resulting string
method printLines( this, txt, max_length, max_lines, line_break_regex, line_break, truncate_left, ignore_empty_strings, add_line_numbers, line_number_format, start_line_number, print_to_last_line)
Adds up to `max_lines` lines from `txt` to `this` observing `max_length`, truncating from left or right (truncating source strings `this` and/or `txt` themselves if necessary).
this : (string) Print outputs `txt` to the end of `this`
txt : (string) Print outputs `txt` to the end of `this`
max_length : (int) (Optional) Chars in excess of `max_length` will be truncated (ending chars by default, see `truncate_left` arg). Default: 4096
max_lines : (int) (Optional) Lines in excess of `max_lines` will be truncated (from end by default, see `truncate_left` arg). Default: 4096
line_break_regex : (string) (Optional) A regex expression used to search for linebrakes. Default is "( |\\r|\\r )"
line_break : (string) (Optional) A string added as a line break. Default is " ".
truncate_left : (bool) (Optional) If true chars in excess of `max_length` will be truncated from the beginning , if false - from the end. Default: false.
ignore_empty_strings : (bool) (Optional) If false a line break will be added (as an empty string), if false `this` will not change.
add_line_numbers : (bool) (Optional) If true adds number before each line. Default format: "LN0001". Custom fomat can be set with `line_number_format'.
line_numbers_format : (string) (Optional) Line number format (like in `str.format()`). Default: `"LN{0000: }"`
print_to_last_line : (string) (Optional) If true will add text to the last line (notwithout adding line break before the first added line). Default: false.
Returns: ` ` where `outS` = `this` + added lines, `intLenthOverflow` = number of truncated chars (including separator), e.g. if `this` is 4095 chars and separator is 2 chars then 4095+2=4097 exceeds default max_length = 4096 by 1, so will be returned, even if , e.g. `txt` is empty and `ignore_empty_strings` is true, and n - number of added lines
method print( this, txt, max_length, max_lines, truncate_left, truncate_top, truncate_lines_src, add_line_numbers, line_number_format, print_to_last_line)
Powerful concatenate function. In simplest form (`this.print(txt)`) just adds `txt` to the end of `this` starting from new line. If `print_to_last_line` is true then concatenates. Can truncate for _max_length (from right by default) and max_lines (truncating from top or bottom). (First removes excessive lines (over `max_lines`) then concatenates truncating for `max_length`.) `print()` looks for all kinds of line breaks (`\r`, ` ` or `\r `) and replaces them with ` `.
this : (string) Print outputs `txt` to the end of `this`
txt : (string) Print outputs `txt` to the end of `this`
max_length : (int) (Optional) Chars in excess of `max_length` will be truncated (ending chars by default, see `truncate_left` arg). Default: 4096
max_lines : (int) (Optional) Lines in excess of `max_lines` will be truncated (from end by default, see `truncate_left` arg). Default: 4096
truncate_left : (bool) (Optional) If true chars in excess of `max_length` will be truncated from the beginning , if false - from the end. Default: false.
truncate_top : (bool) (Optional) If true lines in excess of `max_lines` will be truncated from the top, if false - from the bottom. Default: false.
truncate_lines_src : (bool) (Optional) If true and either `this` or `txt` exceed `max_lines` they will be truncated (excessive lines removed). (Characters in excess of max_length will be truncated regardless). If truncate_top and txt has more than max_lines lines excessive lines will be truncated from the top. (if truncate_top escessive lines from `this` will be truncated regardless of truncate_src). If not truncate_top and this has more than max_lines lines excessive lines will be truncated from the bottom. (if not truncate_top escessive lines from `txt` will be truncated regardless of truncate_src)
add_line_numbers : (bool) (Optional) If true adds number before each line. Default format: "LN0001". Custom fomat can be set with `line_number_format'.
line_numbers_format : (string) (Optional) Line number format (like in `str.format()`). Default: `"LN{0000: }"`
print_to_last_line : (string) (Optional) If true will add text to the last line (notwithout adding line break before the first added line). Default: false.
Returns: ` ` where `outS` = `this` + added lines.
method wrap(this, wrap_width, breaker_prefix, breaker_postfix, line_postfix, max_length)
Wraps each line of `this` to wrap_width adding breaker_prefix to the end of each line (before " ") and breaker_postfix to the beginning of each line (after " ")" (i.e. breaker_prefix'es are effectively added to the end of each line (but the last) and breaker_postfix'es to the beginning of new line starting from second). If with breakers the line exceeds 4096 it is truncated from the right and " " is added at the end.
wrap_width : (series int) Width of each line (chars).
breaker_prefix : (series string) (Optional) Text to add at the end of each line. (Default = "")
breaker_postfix : (series string) (Optional) Text to add after the each added line break at the beginning of next line. (Default = "")
Returns: the wrapped text
export method scroll(this, start_line, lines_in_window, show_line_numbers, show_header)
Scrolls the text (this) by returning a given number of lines (`lines_in_window`) starting from `start_line`. Can add line numbers and/or a header line in the form "Starting from line ... out of total ... lines, ... chars"
start_line : (int) (Optional) Start line
lines_in_window : (int) (Optional) Number of lines to read and return
show_line_numbers : (bool) (Optional) If true preceeds each line with a line number in the form "LN0001}: "
show_header : (bool) (Optional) If true shows the header string in the form "Starting from line {0} out of total {1} lines, {2} chars" followed by a separator line "----------".
Returns: (string) Range of strings.
RegexLib█ OVERVIEW
This library contains regular expression (regex) search functions which are helpful, in particular, in reading configuration inputs.
feedRgx(): Searches for the first occurrence of `regex` pattern in the `src` and returns `src` split into parts as a tuple: ` `. If no match returns ` `
countRgx(): Counts `regex` occurrences in the `src`.
matchRgx(): Finds given `occurence` of `regex` pattern in `src` string.
NB! countRgx() and matchRgx() do not support `^` (beginning of the string placeholder), lookbehind some other complex patterns, because they works by cutting off the part of the string up to the first found occurence (inclusive) and then continuing the search on the remainder of the string. E.g. in a four line source `(?<= ).+ ` should match the second and the third lines but matchRgx only matches the second line since after matching it continues to search in the remainder AFTER the match only.
█ FULL LIST OF FUNCTIONS AND PARAMETERS
method feedRgx(src, regex)
Searches for the first occurrence of ` regex ` pattern in the ` src ` and returns ` src ` split into parts as a tuple: ` `. If no match returns ` `
Namespace types: series string, simple string, input string, const string
Parameters:
src (string) : (string) String to search for the regex pattern
regex (string) : (string) RegEx pattern
Returns: A tuple ` ` where `begS` is the part of the `src` string from the beginning up to the
first occurence of the `regex` pattern (or up to the end if not found), `matchS` - the first occurrence of the
regex pattern and `endS` the part of the strinf following the first occurrence of the `regex` pattern.
method countRgx(src, regex)
Counts `regex` occurrences in the `src`. ___NB!___ _Does not support `^` (beginning of the string
placeholder), lookbehind some other complex patterns, because it works by cutting off the part of the string up to
the first found occurence (inclusive) and then continuing the search on the remainder of the string. E.g. in a four line source `(?<= ).+ ` should match the second and the third lines but matchRgx only
matches the second line since after matching it continues to search in the remainder AFTER the match only. _
Namespace types: series string, simple string, input string, const string
Parameters:
src (string) : (string) String in which the regex pattern occurences are to be counted
regex (string) : (string) RegEx pattern
Returns: The number of occurrences of the `regex` pattern in the `src` string.
method matchRgx(src, regex, occurrence)
Finds given `occurence` of `regex` pattern in `src` string. ___NB!___ _Does not support `^` (beginning of the string placeholder), lookbehind and some other complex patterns, because it works by cutting off the part of the string up to the first found occurence (inclusive) and then continuing the search on the remainder of the string. E.g. in a four line source `(?<= ).+ ` should match the second and the third lines but matchRgx only matches the second line since after matching it continues to search in the remainder AFTER the match only. _
Namespace types: series string, simple string, input string, const string
Parameters:
src (string) : (string) String to search for the regex pattern
regex (string) : (string) RegEx pattern
occurrence (int) : (int) (Default is 1) The number of the occurrence to search for. If this params exceeds the actual
number of occurrences of the pattern in the `src` string the following tuple is returned
Returns: A tuple, matchS - matched substring, matchPos - position of the match, matchL - match length
█ HOW TO USE
See DEMO section in the script.
You can test regex patterns by playing around with script input settings.
Another usage example can be found in my CSVParser and HTFMAs libraries.
ToStringMx█ OVERVIEW
Contains methods for conversion of matrices to string.
Supports matrices of int/float/bool/string/color/line/label/box/.
- toStringMx(matrix) - converts matrix to a string matrix converting each of its elements to string
- toS(matrix) - converts matrix to a string matrix (using toStringMx()) and outputs as string using str.tostring(matrix)
Conversion of each item to string is made using toS() function from moebius1977/ToS/1 library.
█ GENERAL DESCRIPTION OF FUNCTIONS
All toStringMx(matrix) and toS(matrix) methods have same parameters. The only difference will be in format parameter as explained below.
Parameters:
this (matrix) Matrix to be converted to a string matrix.
format (string) Format string.
nz (string) Placeholder for na items.
format parameter depends on the type:
For matrix format parameter works in the same way as `str.format()` (i.e. you can use same format strings as with `str.format()` with `{0}` as a placeholder for the value) with some shorthand "format" options available:
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
- "... ... " in any place is substituted with "{0, date, dd.MM.YY}"
--- time ---
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "... ... " in any place is substituted with "{0, time, HH.mm.ss}"
For matrix :
format (string) : (string) (Optional) Use `x1` as placeholder for `x1` and so on. E.g. default format is `"(x1, y1) - (x2, y2)"`.
For matrix :
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` and `txt` for label's text. E.g. default format is `(x1, y1): "txt"` if ptint_text is true and `(x1, y1)` if false.
For matrix :
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` etc. E.g. default format is "(x1, y1) - (x2, y2)".
For matrix :
format (string) : (string) (Optional) Options are "HEX" (e.g. "#FFFFFF33") or "RGB" (e.g. "rgb(122,122,122,23)"). Default is "HEX".
█ FULL LIST OF FUNCTIONS AND PARAMETERS
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) Like in str.format()
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) Like in str.format() with some shorthand options:
```
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
- "... ... " in any place is substituted with "{0, date, dd.MM.YY}"
--- time ---
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "... ... " in any place is substituted with "{0, time, HH.mm.ss}"
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) Like in str.format() with some shorthand options:
```
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
- "... ... " in any place is substituted with "{0, date, dd.MM.YY}"
--- time ---
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "... ... " in any place is substituted with "{0, time, HH.mm.ss}"
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) Like in str.format()
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) "HEX" (default) or "RGB"
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) (Optional) Format string. By default "{0}: {1}" if showIDs = true or "{1}" otherwise. (use "{0}" as a placeholder for id and "{1}" for item value)
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) (Optional) Format string. By default "{0}: {1}" if showIDs = true or "{1}" otherwise. (use "{0}" as a placeholder for id and "{1}" for item value)
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toStringMx(mx, format, nz)
Returns a string matrix made of original matrix items converted to string with toS().
Namespace types: matrix
Parameters:
mx (matrix)
format (string) : (string) (Optional) Format string. By default "{0}: {1}" if showIDs = true or "{1}" otherwise. (use "{0}" as a placeholder for id and "{1}" for item value)
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) Format string as in str.format()
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) Like in str.format() with some shorthand options:
```
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
- "... ... " in any place is substituted with "{0, date, dd.MM.YY}"
--- time ---
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "... ... " in any place is substituted with "{0, time, HH.mm.ss}"
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) Format string as in str.format()
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) "HEX" (default) or "RGB"
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) (Optional) Format string. By default "{0}: {1}" if showIDs = true or "{1}" otherwise. (use "{0}" as a placeholder for id and "{1}" for item value)
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) (Optional) Format string. By default "{0}: {1}" if showIDs = true or "{1}" otherwise. (use "{0}" as a placeholder for id and "{1}" for item value)
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
method toS(this, format, nz)
Converts each element of the matrix to string outputs using str.tostring(matrix)
Namespace types: matrix
Parameters:
this (matrix) : (matrix) Matrix to be converted to string
format (string) : (string) (Optional) Format string. By default "{0}: {1}" if showIDs = true or "{1}" otherwise. (use "{0}" as a placeholder for id and "{1}" for item value)
nz (string) : (string) If val is na and nz is not na the value of nz param is returned instead.export method toS(matrix this, string format = "", string nz = na) => str.tostring(this.toStringMx(format, nz))
ToStringAr█ OVERVIEW
Contains to string conversion methods arrays of int/float/bool/string/line/label/box types
- toS() - method works like array.join() with more flexibility and
- toStringAr() - converts array to string on a per item basis and returns the resulting string array
Conversion of each item to string is made using toS() function from moebius1977/ToS/1 library.
█ GENERAL DESCRIPTION OF LIBRARY FUNCTIONS
All toS(array) methods have same parameters. The only difference will be in format parameter as explained below.
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Like array.join() but with string length limit. Joins elements into readable string (length capped at 4000, truncating the end or beg)
Parameters:
this (array) : array to be converted to string
index_from (int) : index_from (int) (Optional) Start from this id (starting from 0, in insertion order). If omitted - start from the first item.
index_to (int) : index_to (int) (Optional) End with this pair (inclusive, in insertion order). If omitted - to last item.
separator (string) : separator (string) (Optional) String to be inserted between pairs. Default: `", "`
showIDs (bool) : showIDs (bool) (Optional) If true item's id is added in the form `id: value`.
format (string) : format (string) (Optional) Format string fo toS(). If omitted default format is used depending in the type.
truncate_left (bool) : truncate_left (bool) (Optional) Truncate from left or right. Default: false.
size_limit (int) : size_limit (int) (Optional) Max output string length. Default: 4000.
nz (string) : nz (string) (Optional) A string used to represent na (na values are substituted with this string).
format parameter depends on the type:
For toS(bool/int/float ...) format parameter works in the same way as `str.format()` (i.e. you can use same format strings as with `str.format()` with `{0}` as a placeholder for the value) with some shorthand "format" options available:
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "... ... " in any place is substituted with "{0, date, dd.MM.YY}" (e.g. " " results in "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}")
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
--- time ---
- "... ... " in any place is substituted with "{0, time, HH.mm.ss}" (e.g. " " results in "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}")
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
For toS(line ...):
format (string) : (string) (Optional) Use `x1` as placeholder for `x1` and so on. E.g. default format is `"(x1, y1) - (x2, y2)"`.
For toS(label ...) :
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` and `txt` for label's text. E.g. default format is `(x1, y1): "txt"` if ptint_text is true and `(x1, y1)` if false.
For toS(box ... ) :
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` etc. E.g. default format is "(x1, y1) - (x2, y2)".
For toS(color] ... ) :
format (string) : (string) (Optional) Options are "HEX" (e.g. "#FFFFFF33") or "RGB" (e.g. "rgb(122,122,122,23)"). Default is "HEX".
All toStringAr() methods just convert each item to string using toS with same format options as described above.
Parameters:
arr (array) : Array to be converted to a string array.
format (string) : Format string.
nz (string) : Placeholder for na items.
█ FULL OF FUNCTIONS AND PARAMETERS
Library "ToStringAr"
Contains toString/toS conversion methods for int/float/bool/string/line/label/box and arrays and matrices thereof. Also contains a string wraping function.
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toS(this, index_from, index_to, separator, showIDs, format, truncate_left, size_limit, nz)
Namespace types: array
Parameters:
this (array)
index_from (int)
index_to (int)
separator (string)
showIDs (bool)
format (string)
truncate_left (bool)
size_limit (int)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
method toStringAr(arr, format, nz)
Namespace types: array
Parameters:
arr (array)
format (string)
nz (string)
display_valueOVERVIEW
This script is a tinny library for creating and displaying formatted values in TradingView scripts. It provides a structured way to present key information like titles, percentages, currency values, decimals, and integers with clear formatting. This allows you to coordinate your strings in advance and hold one item to use for calling your string to a label, box, table.. Made for day to day use of most typical use cases, more advanced techniques should be used for complicated scenarios.
Building Blocks
User Defined Types (UDTs)
The script defines a UDT called `DisplayValue` to encapsulate the components of a display value:
* title : The title or label of the value.
* format_string : The string used to format the value (e.g., "{0} - 1,number,percent}").
* value : The actual value to be displayed.
* format : An enum value specifying the desired format (percent, currency, etc.).
Enums
The `DisplayFormat` enum provides predefined constants for various formatting options, making the code more readable and less prone to errors.
Functions
* create() : This function creates a new `DisplayValue` instance. It takes the title, value, and desired format as arguments and generates the appropriate format string.
* to_string() : This function converts a `DisplayValue` instance into a formatted string ready for display on the chart.
How to Use
1. Import the library:
import kaigouthro/display_value/1as dv
2. Create a DisplayValue instance:
myValue = dv.create("My Percentage", 0.5, dv.DisplayFormat.percent)
3. Convert it to a string:
formattedString = dv.to_string(myValue)
4. Display the formatted string:
label.new(bar_index, high, formattedString)
Example
//@version=5
import kaigouthro/display_value/1 as dv
myValue = dv.create("Profit", 0.15, dv.DisplayFormat.percent)
formattedString = dv.to_string(myValue)
label.new(bar_index, high, formattedString)
This will display a label on the chart with the text "Profit - 15%".
### Notes
* The library handles the formatting details, making it easier to display values consistently in your scripts.
* The use of enums and UDTs improves code organization and readability.
--------
Library "display_value"
create(display_name, display_value, display_format)
Gets the appropriate format string based on the display format.
Parameters:
display_name (string) : (string) The name of the display value. Default is na.
display_value (float)
display_format (series DisplayFormat)
Returns: (DisplayValue) A new DisplayValue instance with the formatted value.
to_string(item)
Converts the display value to a string with the specified format.
Parameters:
item (DisplayValue) : (DisplayValue) The display value to convert to a string.
Returns: (string) The string representation of the display value.
DisplayValue
Structure representing a display value.
Fields:
title (series string) : (string) The title of the display value.
format_string (series string) : (string) The format string to use for display.
value (series float) : (float) The value to display.
format (series DisplayFormat) : (DisplayFormat) The format to use.
analytics_tablesLibrary "analytics_tables"
📝 Description
This library provides the implementation of several performance-related statistics and metrics, presented in the form of tables.
The metrics shown in the afforementioned tables where developed during the past years of my in-depth analalysis of various strategies in an atempt to reason about the performance of each strategy.
The visualization and some statistics where inspired by the existing implementations of the "Seasonality" script, and the performance matrix implementations of @QuantNomad and @ZenAndTheArtOfTrading scripts.
While this library is meant to be used by my strategy framework "Template Trailing Strategy (Backtester)" script, I wrapped it in a library hoping this can be usefull for other community strategy scripts that will be released in the future.
🤔 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/analytics_tables/1 as ant
There are three types of tables provided by this library in the initial release. The stats table the metrics table and the seasonality table.
Each one shows different kinds of performance statistics.
The table UDT shall be initialized once using the `init()` method.
They can be updated using the `update()` method where the updated data UDT object shall be passed.
The data UDT can also initialized and get updated on demend depending on the use case
A code example for the StatsTable is the following:
var ant.StatsData statsData = ant.StatsData.new()
statsData.update(SideStats.new(), SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var statsTable = ant.StatsTable.new().init(ant.getTablePos('TOP', 'RIGHT'))
statsTable.update(statsData)
A code example for the MetricsTable is the following:
var ant.StatsData statsData = ant.StatsData.new()
statsData.update(ant.SideStats.new(), ant.SideStats.new(), 0)
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var metricsTable = ant.MetricsTable.new().init(ant.getTablePos('BOTTOM', 'RIGHT'))
metricsTable.update(statsData, 10)
A code example for the SeasonalityTable is the following:
var ant.SeasonalData seasonalData = ant.SeasonalData.new().init(Seasonality.monthOfYear)
seasonalData.update()
if (barstate.islastconfirmedhistory or (barstate.isrealtime and barstate.isconfirmed))
var seasonalTable = ant.SeasonalTable.new().init(seasonalData, ant.getTablePos('BOTTOM', 'LEFT'))
seasonalTable.update(seasonalData)
🏋️♂️ Please refer to the "EXAMPLE" regions of the script for more advanced and up to date code examples!
Special thanks to @Mrcrbw for the proposal to develop this library and @DCNeu for the constructive feedback 🏆.
getTablePos(ypos, xpos)
Get table position compatible string
Parameters:
ypos (simple string) : The position on y axise
xpos (simple string) : The position on x axise
Returns: The position to be passed to the table
method init(this, pos, height, width, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor)
Initialize the stats table object with the given colors in the given position
Namespace types: StatsTable
Parameters:
this (StatsTable) : The stats table object
pos (simple string) : The table position string
height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
width (simple float) : The width of the table as a percentage of the charts height. By default, 0 auto-adjusts the width based on the text inside the cells
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
neutralTxtColor (simple color) : The text color when neutral
positiveBgColor (simple color) : The background color with transparency when positive
negativeBgColor (simple color) : The background color with transparency when negative
neutralBgColor (simple color) : The background color with transparency when neutral
method init(this, pos, height, width, neutralBgColor)
Initialize the metrics table object with the given colors in the given position
Namespace types: MetricsTable
Parameters:
this (MetricsTable) : The metrics table object
pos (simple string) : The table position string
height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
width (simple float) : The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
neutralBgColor (simple color) : The background color with transparency when neutral
method init(this, seas)
Initialize the seasonal data
Namespace types: SeasonalData
Parameters:
this (SeasonalData) : The seasonal data object
seas (simple Seasonality) : The seasonality of the matrix data
method init(this, data, pos, maxNumOfYears, height, width, extended, neutralTxtColor, neutralBgColor)
Initialize the seasonal table object with the given colors in the given position
Namespace types: SeasonalTable
Parameters:
this (SeasonalTable) : The seasonal table object
data (SeasonalData) : The seasonality data of the table
pos (simple string) : The table position string
maxNumOfYears (simple int) : The maximum number of years that fit into the table
height (simple float) : The height of the table as a percentage of the charts height. By default, 0 auto-adjusts the height based on the text inside the cells
width (simple float) : The width of the table as a percentage of the charts width. By default, 0 auto-adjusts the width based on the text inside the cells
extended (simple bool) : The seasonal table with extended columns for performance
neutralTxtColor (simple color) : The text color when neutral
neutralBgColor (simple color) : The background color with transparency when neutral
method update(this, wins, losses, numOfInconclusiveExits)
Update the strategy info data of the strategy
Namespace types: StatsData
Parameters:
this (StatsData) : The strategy statistics object
wins (SideStats)
losses (SideStats)
numOfInconclusiveExits (int) : The number of inconclusive trades
method update(this, stats, positiveTxtColor, negativeTxtColor, negativeBgColor, neutralBgColor)
Update the stats table object with the given data
Namespace types: StatsTable
Parameters:
this (StatsTable) : The stats table object
stats (StatsData) : The stats data to update the table
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
negativeBgColor (simple color) : The background color with transparency when negative
neutralBgColor (simple color) : The background color with transparency when neutral
method update(this, stats, buyAndHoldPerc, positiveTxtColor, negativeTxtColor, positiveBgColor, negativeBgColor)
Update the metrics table object with the given data
Namespace types: MetricsTable
Parameters:
this (MetricsTable) : The metrics table object
stats (StatsData) : The stats data to update the table
buyAndHoldPerc (float) : The buy and hold percetage
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
positiveBgColor (simple color) : The background color with transparency when positive
negativeBgColor (simple color) : The background color with transparency when negative
method update(this)
Update the seasonal data based on the season and eon timeframe
Namespace types: SeasonalData
Parameters:
this (SeasonalData) : The seasonal data object
method update(this, data, positiveTxtColor, negativeTxtColor, neutralTxtColor, positiveBgColor, negativeBgColor, neutralBgColor, timeBgColor)
Update the seasonal table object with the given data
Namespace types: SeasonalTable
Parameters:
this (SeasonalTable) : The seasonal table object
data (SeasonalData) : The seasonal cell data to update the table
positiveTxtColor (simple color) : The text color when positive
negativeTxtColor (simple color) : The text color when negative
neutralTxtColor (simple color) : The text color when neutral
positiveBgColor (simple color) : The background color with transparency when positive
negativeBgColor (simple color) : The background color with transparency when negative
neutralBgColor (simple color) : The background color with transparency when neutral
timeBgColor (simple color) : The background color of the time gradient
SideStats
Object that represents the strategy statistics data of one side win or lose
Fields:
numOf (series int)
sumFreeProfit (series float)
freeProfitStDev (series float)
sumProfit (series float)
profitStDev (series float)
sumGain (series float)
gainStDev (series float)
avgQuantityPerc (series float)
avgCapitalRiskPerc (series float)
avgTPExecutedCount (series float)
avgRiskRewardRatio (series float)
maxStreak (series int)
StatsTable
Object that represents the stats table
Fields:
table (series table) : The actual table
rows (series int) : The number of rows of the table
columns (series int) : The number of columns of the table
StatsData
Object that represents the statistics data of the strategy
Fields:
wins (SideStats)
losses (SideStats)
numOfInconclusiveExits (series int)
avgFreeProfitStr (series string)
freeProfitStDevStr (series string)
lossFreeProfitStDevStr (series string)
avgProfitStr (series string)
profitStDevStr (series string)
lossProfitStDevStr (series string)
avgQuantityStr (series string)
MetricsTable
Object that represents the metrics table
Fields:
table (series table) : The actual table
rows (series int) : The number of rows of the table
columns (series int) : The number of columns of the table
SeasonalData
Object that represents the seasonal table dynamic data
Fields:
seasonality (series Seasonality)
eonToMatrixRow (map)
numOfEons (series int)
mostRecentMatrixRow (series int)
balances (matrix)
returnPercs (matrix)
maxDDs (matrix)
eonReturnPercs (array)
eonCAGRs (array)
eonMaxDDs (array)
SeasonalTable
Object that represents the seasonal table
Fields:
table (series table) : The actual table
headRows (series int) : The number of head rows of the table
headColumns (series int) : The number of head columns of the table
eonRows (series int) : The number of eon rows of the table
seasonColumns (series int) : The number of season columns of the table
statsRows (series int)
statsColumns (series int) : The number of stats columns of the table
rows (series int) : The number of rows of the table
columns (series int) : The number of columns of the table
extended (series bool) : Whether the table has additional performance statistics
ToS█ OVERVIEW
Contains methods for conversion to string of simple types int/float/bool/string/line/label/box .
- toS() - For bool/int/float works much the same as str.tostring() with some shorthand formatting options for int/float. For line/label/box displays their text and coordinates automatically formatting x coordinate as time or bar index.
- toShortString() - Converts a number to a short form using "k", "m", "bn" and "T" nominators. (e.g. `12,350` --> `12.4k`).
Supports some shorthand formatting options for int/float and time.
█ HOW TO USE
All toS() methods have the same parameters:
Parameters:
val (int) : A float to be converted to string
format (string) : Format string, which depends on the value type
nz (string) : (string) A string used to represent na (na values are substituted with this string).
For toS(bool/int/float) format parameter works in the same way as `str.format()` (i.e. you can use same format strings as with `str.format()` with `{0}` as a placeholder for the value)
Some shorthand "format" options available:
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "... ... " in any place is substituted with "{0, date, dd.MM.YY}"
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
--- time ---
- "... ... " in any place is substituted with "{0, time, HH.mm.ss}"
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
For toS(line) :
format (string) : (string) (Optional) Use `x1` as placeholder for `x1` and so on. E.g. default format is `"(x1, y1) - (x2, y2)"`.
For toS(label) :
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` and `txt` for label's text. E.g. default format is `(x1, y1): "txt"` if ptint_text is true and `(x1, y1)` if false.
For toS(box) :
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` etc. E.g. default format is "(x1, y1) - (x2, y2)".
For toS(color) :
format (string) : (string) (Optional) Options are "HEX" (e.g. "#FFFFFF33") or "RGB" (e.g. "rgb(122,122,122,23)"). Default is "HEX".
█ LIST OF FUNCTIONS AND PARAMETERS
method toS(val, format, nz)
Formats the `int/float` in the same way as `str.format()` (i.e. you can use same format strings as with
`str.format()` with `{0}` arg) with some shorthand "format" options:
```
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "......" in angular brackets in any place is substituted with "{0, date, dd.MM.YY}"
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
--- time ---
- "......" in angular brackets in any place is substituted with "{0, time, HH.mm.ss}"
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
```
Namespace types: series int, simple int, input int, const int
Parameters:
val (int) : A float to be converted to string
format (string) : Format string (e.g. "0.000" or "date : time" or "HH:mm")
nz (string) : (string) A string used to represent na (na values are substituted with this string).
method toS(val, format, nz)
Formats the `int/float` in the same way as `str.format()` (i.e. you can use same format strings as with
`str.format()` with `{0}` arg) with some shorthand "format" options:
```
--- number ---
- "" => "{0}"
- "number" => "{0}"
- "0" => "{0, number, 0 }"
- "0.0" => "{0, number, 0.0 }"
- "0.00" => "{0, number, 0.00 }"
- "0.000" => "{0, number, 0.000 }"
- "0.0000" => "{0, number, 0.0000 }"
- "0.00000" => "{0, number, 0.00000 }"
- "0.000000" => "{0, number, 0.000000 }"
- "0.0000000" => "{0, number, 0.0000000}"
--- date ---
- "......" in angular brackets in any place is substituted with "{0, date, dd.MM.YY}"
- "date" => "{0, date, dd.MM.YY}"
- "date : time" => "{0, date, dd.MM.YY} : {0, time, HH.mm.ss}"
- "dd.MM" => "{0, date, dd:MM}"
- "dd" => "{0, date, dd}"
--- time ---
- "......" in angular brackets in any place is substituted with "{0, time, HH.mm.ss}"
- "time" => "{0, time, HH:mm:ss}"
- "HH:mm" => "{0, time, HH:mm}"
- "mm:ss" => "{0, time, mm:ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
- "date, time" => "{0, date, dd.MM.YY\}, {0, time, HH.mm.ss}"
- "date,time" => "{0, date, dd.MM.YY\},{0, time, HH.mm.ss}"
- "date time" => "{0, date, dd.MM.YY\} {0, time, HH.mm.ss}"
```
Namespace types: series float, simple float, input float, const float
Parameters:
val (float) : A float to be converted to string
format (string) : Format string (e.g. "0.000" or "date : time" or "HH:mm")
nz (string) : (string) A string used to represent na (na values are substituted with this string).
method toS(val, format, nz)
Formats `bool val` in the same way as `str.format()` (i.e. you can use same format strings as with
`str.format()` with `{0}` placeholder for the `val` argument).
Namespace types: series bool, simple bool, input bool, const bool
Parameters:
val (bool) : (bool) Value to be formatted
format (string)
nz (string) : (string) A string used to represent na (na values are substituted with this string).
method toS(val, format, nz)
Formats `string val` in the same way as `str.format()` (i.e. you can use same format strings as with
`str.format()` with `{0}` placeholder for the `val` argument).
Namespace types: series color, simple color, input color, const color
Parameters:
val (color)
format (string) : (string) "HEX" or "RGB"
nz (string) : (string) A string used to represent na (na values are substituted with this string).
method toS(val, format, nz)
Formats `string val` in the same way as `str.format()` (i.e. you can use same format strings as with
`str.format()` with `{0}` placeholder for the `val` argument).
Namespace types: series string, simple string, input string, const string
Parameters:
val (string)
format (string)
nz (string) : (string) A string used to represent na (na values are substituted with this string).
method toS(ln, format, nz)
Returns line's coordinates as a string (by default in "(x1, y1) - (x2, y2)" format, use `x1`, `y1`, `x2`,`y2` as placeholders in `format` string)). Automatically detects
whether the coordinates are in `xloc.bar_index` or `xloc.bar_time` and displays
accordingly (in _dd.MM.yy HH:mm:ss_ format)
Namespace types: series line
Parameters:
ln (line)
format (string) : (string) (Optional) Use `x1` as placeholder for `x1` and so on. E.g. default format is `"(x1, y1) - (x2, y2)"`.
nz (string) : (string) (Optional) If `val` is `na` and `nz` is not `na` the value of `nz` param is returned instead.
method toS(lbl, format, nz, print_text)
Returns label's coordinates and text as a string (by default in "(x, y): text = ...)" format; use `x1`, `y1`, `txt` as placeholders in `format` string))).
Automatically detects whether the coordinates are in `xloc.bar_index` or `xloc.bar_time` and displays.
accordingly (in _dd.MM.yy HH:mm:ss_ format)
Namespace types: series label
Parameters:
lbl (label)
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` and `txt` for label's text. E.g. default format is `(x1, y1): "txt"`.
nz (string) : (string) A string used to represent na (na values are substituted with this string).
print_text (bool)
method toS(bx, format, nz)
Returns box's coordinates as a string (by default in "(x1, y1) - (x2, y2)" format)
Namespace types: series box
Parameters:
bx (box)
format (string) : (string) (Optional) Use `x1` as placeholder for `x`, `y1 - for `y` etc. E.g. default format is "(x1, y1) - (x2, y2)".
nz (string) : (string) A string used to represent na (na values are substituted with this string).
method toShortString(this, decimals)
Converts number to a short form using "k", "m", "bn" and "T" nominators. (e.g. `12,350` --> `12.4k`).
@this (series float) Number to be converted to short format.
@decimals (series int) Optional argument. Decimal places to which number will be rounded. When no argument
is supplied, rounding is to the nearest integer.
Namespace types: series float, simple float, input float, const float
Parameters:
this (float)
decimals (int)
Killzones And Macros LibraryKillzones & Macros Library for Trading Sessions
This Pine Script library is designed to help traders identify and act during high-volatility trading windows, commonly referred to as "Killzones." These are specific times during the day when institutional traders are most active, resulting in increased liquidity and price movement. The library provides boolean fields that return true when the current time falls within one of the killzones or macroeconomic event windows, allowing for enhanced trade timing and precision.
Killzones Include:
London Open, New York Open, Midnight Open, London Lunch, New York PM, and more.
Capture high-volume periods like Power Hour, Equities Open, and Asian Range.
Macros:
Identify key moments like London 02:33, New York 08:50, and other significant times aligned with market movements or events.
This library is perfect for integrating into your custom strategies, backtesting, or setting alerts for optimal trade execution during major trading sessions and events.
mlivsLibrary "mlivs"
TODO: add library description here
adx(high, low, adxlen, dilen)
TODO: add function description here
Parameters:
high (float)
low (float)
adxlen (simple int)
dilen (simple int)
Returns: TODO: add what function returns
adxMA()
impulseMACD(lengthMA, lengthSignal)
Parameters:
lengthMA (simple int)
lengthSignal (int)
movingAveragesUtilitiesLibrary "movingAveragesUtilities"
get_movingAverages_data(source, length_fast, length_medium, length_slow)
Parameters:
source (float)
length_fast (simple int)
length_medium (simple int)
length_slow (simple int)
gridUtilitiesLibrary "gridUtilities"
TODO: add library description here
get_fibonacciGrid_data(length, trend_direction, plot_grid, plot_labels, bars_to_right, include_levels)
: Gets and plots a fibonacci grid.
Parameters:
length (int) : (int): The direction flag that indicates where the trend is going.
trend_direction (string) : (string): Direction of the trend (Long, Short or Neutral)
plot_grid (bool) : (bool): Plots the fibonacci grid.
plot_labels (bool) : (bool): Plots the datatable.
bars_to_right (int) : (bool): Plots the datatable.
include_levels (bool) : (bool): Plots the datatable.
Returns: : Returns a map with the grid levels, as string with the direction of the grid and a map with the values for the dataTable.
BinaryInsertionSortLibrary "BinaryInsertionSort"
Library containing functions which can help create sorted array based on binary insertion sort.
This sorting will be quicker than array.sort function if the sorting needs to be done on every bar and the size of the array is comparatively big.
method binary_search_basic(sortedArray, item, order)
binary_search_basic - finds the closest index of the value
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (float) : float item which needs to be searched in the sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item can be inserted into sorted array
method binary_search_basic(sortedArray, item, order)
binary_search_basic - finds the closest index of the value
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (int) : int item which needs to be searched in the sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item can be inserted into sorted array
method binary_insertion_sort(sortedArray, item, order)
binary insertion sort - inserts item into sorted array while maintaining sort order
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (float) : float item which needs to be inserted into sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item is inserted into sorted array
method binary_insertion_sort(sortedArray, item, order)
binary insertion sort - inserts item into sorted array while maintaining sort order
Namespace types: array
Parameters:
sortedArray (array) : array which is assumed to be sorted in the requested order
item (int) : int item which needs to be inserted into sorted array
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: int index at which the item is inserted into sorted array
update_sort_indices(sortIndices, newItemIndex)
adds the sort index of new item added to sorted array and also updates existing sort indices.
Parameters:
sortIndices (array) : array containing sort indices of an array.
newItemIndex (int) : sort index of new item added to sorted array
Returns: void
get_array_of_series(item, order)
Converts series into array and sorted array.
Parameters:
item (float) : float series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_array_of_series(item, order)
Converts series into array and sorted array.
Parameters:
item (int) : int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_sorted_arrays(item, order)
Converts series into array and sorted array. Also calculates the sort order of the value array
Parameters:
item (float) : float|int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns:
get_sorted_arrays(item, order)
Converts series into array and sorted array. Also calculates the sort order of the value array
Parameters:
item (int) : int series
order (int) : Sort order - positive number means ascending order whereas negative number represents descending order
Returns: