FunctionSurvivalEstimationLibrary "FunctionSurvivalEstimation"
The Survival Estimation function, also known as Kaplan-Meier estimation or product-limit method, is a statistical technique used to estimate the survival probability of an individual over time. It's commonly used in medical research and epidemiology to analyze the survival rates of patients with different treatments, diseases, or risk factors.
What does it do?
The Survival Estimation function takes into account censored observations (i.e., individuals who are still alive at a certain point) and calculates the probability that an individual will survive beyond a specific time period. It's particularly useful when dealing with right-censoring, where some subjects are lost to follow-up or have not experienced the event of interest by the end of the study.
Interpretation
The Survival Estimation function provides a plot of the estimated survival probability over time, which can be used to:
1. Compare survival rates between different groups (e.g., treatment arms)
2. Identify patterns in the data that may indicate differences in mortality or disease progression
3. Make predictions about future outcomes based on historical data
4. In a trading context it may be used to ascertain the survival ratios of trading under specific conditions.
Reference:
www.global-developments.org
"Beyond GDP" ~ www.aeaweb.org
en.wikipedia.org
www.kdnuggets.com
survival_probability(alive_at_age, initial_alive)
Kaplan-Meier Survival Estimator.
Parameters:
alive_at_age (int) : The number of subjects still alive at a age.
initial_alive (int) : The Total number of initial subjects.
Returns: The probability that a subject lives longer than a certain age.
utility(c, l)
Captures the utility value from consumption and leisure.
Parameters:
c (float) : Consumption.
l (float) : Leisure.
Returns: Utility value from consumption and leisure.
welfare_utility(age, b, u, s)
Calculate the welfare utility value based age, basic needs and social interaction.
Parameters:
age (int) : Age of the subject.
b (float) : Value representing basic needs (food, shelter..).
u (float) : Value representing overall well-being and happiness.
s (float) : Value representing social interaction and connection with others.
Returns: Welfare utility value.
expected_lifetime_welfare(beta, consumption, leisure, alive_data, expectation)
Calculates the expected lifetime welfare of an individual based on their consumption, leisure, and survival probability over time.
Parameters:
beta (float) : Discount factor.
consumption (array) : List of consumption values at each step of the subjects life.
leisure (array) : List of leisure values at each step of the subjects life.
alive_data (array) : List of subjects alive at each age, the first element is the total or initial number of subjects.
expectation (float) : Optional, `defaut=1.0`. Expectation or weight given to this calculation.
Returns: Expected lifetime welfare value.
Chỉ báo và chiến lược
CSCMultiTimeframeToolsLibrary "CSCMultiTimeframeTools"
Calculates instant higher timeframe values for higher timeframe analysis with zero lag.
getAdjustedLookback(current_tf_minutes, higher_tf_minutes, length)
Calculate adjusted lookback period for higher timeframe conversion.
Parameters:
current_tf_minutes (int) : Current chart timeframe in minutes (e.g., 5 for 5m).
higher_tf_minutes (int) : Target higher timeframe in minutes (e.g., 15 for 15m).
length (int) : Base length value (e.g., 14 for RSI/MFI).
Returns: Adjusted lookback period (length × multiplier).
Purpose and Benefits of the TimeframeTools Library
This library is designed to solve a critical pain point for traders who rely on higher timeframe (HTF) indicator values while analyzing lower timeframe (LTF) charts. Traditional methods require waiting for multiple candles to close—for example, to see a 1-hour RSI on a 5-minute chart, you’d need 12 closed candles (5m × 12 = 60m) before the value updates. This lag means missed opportunities, delayed signals, and inefficient decision-making.
Why Traders Need This
Whether you’re scalping (5M/15M) or swing trading (1H/4H), this library bridges the gap between timeframes, giving you HTF context in real time—so you can act faster, with confidence.
How This Library Eliminates the Waiting Game
By dynamically calculating the adjusted lookback period, the library allows:
Real-time HTF values on LTF charts – No waiting for candle closes.
Accurate conversions – A 14-period RSI on a 1-hour chart translates to 168 periods (14 × 12) on a 5-minute chart, ensuring mathematical precision.
Flexible application – Works with common indicators like RSI, MFI, CCI, and moving averages (though confirmations should be done before publishing under your own secondary use).
Key Advantages Over Manual Methods
Speed: Instantly reflects HTF values without waiting for candle resolutions.
Adaptability: Adjusts automatically if the user changes timeframes or lengths.
Consistency: Removes human error in manual period calculations.
Limitations to Note
Not a magic bullet – While it solves the lag issue, traders should still:
Validate signals with price action or additional confirmations.
Be mindful of extreme lookback lengths (e.g., a 200-period daily SMA on a 1-minute chart requires 28,800 periods, which may strain performance).
arrayutilsLibrary "arrayutils"
Library contains utility functions using arrays.
delete(arr, index)
remove an item from array at specific index. Also deletes the item
Parameters:
arr (array) : - array from which the item needs to be deleted
index (int) : - index of item to be deleted
Returns: void
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
delete(arr, index)
Parameters:
arr (array)
index (int)
pop(arr)
remove the last item from array. Also deletes the item
Parameters:
arr (array) : - array from which the last item needs to be removed and deleted
Returns: void
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
pop(arr)
Parameters:
arr (array)
shift(arr)
remove an item from array at index 0. Also deletes the item
Parameters:
arr (array) : - array from which the first item needs to be removed and deleted
Returns: void
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
shift(arr)
Parameters:
arr (array)
unshift(arr, val, maxItems)
add an item to the beginning of an array with max items cap
Parameters:
arr (array) : - array to which the item needs to be added at the beginning
val (int) : - value of item which needs to be added
maxItems (simple int) : - max items array can hold. After that, items are removed from the other end
Returns: resulting array
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (float)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (bool)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (string)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (color)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (line)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (label)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (box)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (table)
maxItems (simple int)
unshift(arr, val, maxItems)
Parameters:
arr (array)
val (linefill)
maxItems (simple int)
clear(arr)
remove and delete all items in an array
Parameters:
arr (array) : - array which needs to be cleared
Returns: void
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
clear(arr)
Parameters:
arr (array)
push(arr, val, maxItems)
add an item to the end of an array with max items cap
Parameters:
arr (array) : - array to which the item needs to be added at the beginning
val (int) : - value of item which needs to be added
maxItems (simple int) : - max items array can hold. After that, items are removed from the starting index
Returns: resulting array
push(arr, val, maxItems)
Parameters:
arr (array)
val (float)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (bool)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (string)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (color)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (line)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (label)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (box)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (table)
maxItems (simple int)
push(arr, val, maxItems)
Parameters:
arr (array)
val (linefill)
maxItems (simple int)
check_overflow(a, b, c, pivots, barArray)
finds difference between two timestamps
Parameters:
a (float)
b (float)
c (float)
pivots (array) : pivots array
barArray (array) : pivot bar array
Returns: bool overflow
get_trend_series(pivots, length, highLow, trend)
finds series of pivots in particular trend
Parameters:
pivots (array) : pivots array
length (int) : length for which trend series need to be checked
highLow (int) : filter pivot high or low
trend (int) : Uptrend or Downtrend
Returns: int trendIndexes
get_trend_series(pivots, firstIndex, lastIndex)
finds series of pivots in particular trend
Parameters:
pivots (array) : pivots array
firstIndex (int) : First index of the series
lastIndex (int) : Last index of the series
Returns: int trendIndexes
sma(source)
calculates sma for elements in array
Parameters:
source (array) : source array
Returns: float sma
ema(source, length)
calculates ema for elements in array
Parameters:
source (array) : source array
length (simple int) : ema length
Returns: float ema
rma(source, length)
calculates rma for elements in array
Parameters:
source (array) : source array
length (simple int) : rma length
Returns: float rma
wma(source, length)
calculates wma for elements in array
Parameters:
source (array) : source array
length (simple int) : wma length
Returns: float wma
hma(source, length)
calculates hma for elements in array
Parameters:
source (array) : source array
length (simple int) : hma length
Returns: float hma
ma(source, matype, length)
wrapper for all moving averages based on array
Parameters:
source (array) : source array
matype (simple string) : moving average type. Valud values are: sma, ema, rma, wma, hma, high, low, median, medianHigh, medianLow
length (simple int) : moving average length length
Returns: float moving average
getFibSeries(numberOfFibs, start)
gets fib series in array
Parameters:
numberOfFibs (simple int) : number of fibs
start (simple int) : starting number
Returns: float fibArray
basechartpatternsLibrary "basechartpatterns"
getPatternNameById(id)
Returns pattern name by id
Parameters:
id (int) : pattern id
Returns: Pattern name
method find(points, properties, dProperties, ohlcArray)
Find patterns based on array of points
Namespace types: array
Parameters:
points (array) : array of chart.point objects
properties (ScanProperties type from OptionsAlerts/abstractchartpatterns/1) : ScanProperties object
dProperties (DrawingProperties type from OptionsAlerts/abstractchartpatterns/1) : DrawingProperties object
ohlcArray (array type from OptionsAlerts/ohlc/1)
Returns: Flag indicating if the pattern is valid, Current Pattern object
method find(this, properties, dProperties, patterns, ohlcArray)
Find patterns based on the currect zigzag object but will not store them in the pattern array.
Namespace types: zg.Zigzag
Parameters:
this (Zigzag type from OptionsAlerts/ZigzagLite/1) : Zigzag object containing pivots
properties (ScanProperties type from OptionsAlerts/abstractchartpatterns/1) : ScanProperties object
dProperties (DrawingProperties type from OptionsAlerts/abstractchartpatterns/1) : DrawingProperties object
patterns (array type from OptionsAlerts/abstractchartpatterns/1) : Array of Pattern objects
ohlcArray (array type from OptionsAlerts/ohlc/1)
Returns: Flag indicating if the pattern is valid, Current Pattern object
abstractchartpatternsLibrary "abstractchartpatterns"
method checkSize(filters, points)
checks if the series of pivots are within the size filter
Namespace types: SizeFilters
Parameters:
filters (SizeFilters) : SizeFilters object containing size criteria to be matched
points (array) : list of pivot points
Returns: true if matches the size filter, false otherwise
checkBarRatio(p1, p2, p3, properties)
checks if three zigzag pivot points are having uniform bar ratios
Parameters:
p1 (chart.point) : First pivot point
p2 (chart.point) : Second pivot point
p3 (chart.point) : Third pivot point
properties (ScanProperties)
Returns: true if points are having uniform bar ratio
getRatioDiff(p1, p2, p3)
gets ratio difference between 3 pivot combinations
Parameters:
p1 (chart.point)
p2 (chart.point)
p3 (chart.point)
Returns: returns the ratio difference between pivot2/pivot1 ratio and pivot3/pivot2 ratio
method inspect(points, stratingBar, endingBar, direction, ohlcArray)
Creates a trend line between 2 or 3 points and validates and selects best combination
Namespace types: array
Parameters:
points (array) : Array of chart.point objects used for drawing trend line
stratingBar (int) : starting bar of the trend line
endingBar (int) : ending bar of the trend line
direction (float) : direction of the last pivot. Tells whether the line is joining upper pivots or the lower pivots
ohlcArray (array type from OptionsAlerts/ohlc/1) : Array of OHLC values
Returns: boolean flag indicating if the trend line is valid and the trend line object as tuple
method draw(this)
draws pattern on the chart
Namespace types: Pattern
Parameters:
this (Pattern) : Pattern object that needs to be drawn
Returns: Current Pattern object
method erase(this)
erase the given pattern on the chart
Namespace types: Pattern
Parameters:
this (Pattern) : Pattern object that needs to be erased
Returns: Current Pattern object
method push(this, p, maxItems)
push Pattern object to the array by keeping maxItems limit
Namespace types: array
Parameters:
this (array) : array of Pattern objects
p (Pattern) : Pattern object to be added to array
@oaram maxItems Max number of items the array can hold
maxItems (int)
Returns: Current Pattern array
method deepcopy(this)
Perform deep copy of a chart point array
Namespace types: array
Parameters:
this (array) : array of chart.point objects
Returns: deep copy array
DrawingProperties
Object containing properties for pattern drawing
Fields:
patternLineWidth (series int) : Line width of the pattern trend lines
showZigzag (series bool) : show zigzag associated with pattern
zigzagLineWidth (series int) : line width of the zigzag lines. Used only when showZigzag is set to true
zigzagLineColor (series color) : color of the zigzag lines. Used only when showZigzag is set to true
showPatternLabel (series bool) : display pattern label containing the name
patternLabelSize (series string) : size of the pattern label. Used only when showPatternLabel is set to true
showPivotLabels (series bool) : Display pivot labels of the patterns marking 1-6
pivotLabelSize (series string) : size of the pivot label. Used only when showPivotLabels is set to true
pivotLabelColor (series color) : color of the pivot label outline. chart.bg_color or chart.fg_color are the appropriate values.
deleteOnPop (series bool) : delete the pattern when popping out from the array of Patterns.
Pattern
Object containing Individual Pattern data
Fields:
dir (series int) : direction of the last pivot
points (array) : array of Zigzag Pivot points
trendLine1 (Line type from OptionsAlerts/LineWrapper/1) : First trend line joining pivots 1, 3, 5
trendLine2 (Line type from OptionsAlerts/LineWrapper/1) : Second trend line joining pivots 2, 4 (, 6)
properties (DrawingProperties) : DrawingProperties Object carrying common properties
patternColor (series color) : Individual pattern color. Lines and labels will be using this color.
ratioDiff (series float) : Difference between trendLine1 and trendLine2 ratios
zigzagLine (series polyline) : Internal zigzag line drawing Object
pivotLabels (array) : array containning Pivot labels
patternLabel (series label) : pattern label Object
patternType (series int) : integer representing the pattern type
patternName (series string) : Type of pattern in string
SizeFilters
Object containing properties for pattern size filters
Fields:
filterByBar (series bool) : If set filter the patterns by the bar range
minPatternBars (series int) : Used only when filterByBar is set to true. Minimum bars range for pattern size
maxPatternBars (series int) : Used only when filterByBar is set to true. Maximum bars range for pattern size
filterByPercent (series bool) : Filters patterns by percent of price if set
minPatternPercent (series int) : Used only when filterByPercent is set. Minimum pattern size in terms of percent of price
maxPatternPercent (series int) : Used only when filterByPercent is set. Maximum pattern size in terms of percent of price
ScanProperties
Object containing properties for pattern scanning
Fields:
offset (series int) : Zigzag pivot offset. Set it to 1 for non repainting scan.
numberOfPivots (series int) : Number of pivots to be used in pattern search. Can be either 5 or 6
errorRatio (series float) : Error Threshold to be considered for comparing the slope of lines
flatRatio (series float) : Retracement ratio threshold used to determine if the lines are flat
checkBarRatio (series bool) : Also check bar ratio are within the limits while scanning the patterns
barRatioLimit (series float) : Bar ratio limit used for checking the bars. Used only when checkBarRatio is set to true
avoidOverlap (series bool) : avoid overlapping patterns.
ignoreIfEntryCrossed (series bool) : Ignore the trade if close price does not fall within the price entry price range
allowedPatterns (array) : array of bool encoding the allowed pattern types.
allowedLastPivotDirections (array) : array of int representing allowed last pivot direction for each pattern types
themeColors (array) : color array of themes to be used.
filters (SizeFilters)
ZigzagLiteLibrary "ZigzagLite"
method getPrices(pivots)
Gets the array of prices from array of Pivots
Namespace types: array
Parameters:
pivots (array) : array array of Pivot objects
Returns: array array of pivot prices
method getBars(pivots)
Gets the array of bars from array of Pivots
Namespace types: array
Parameters:
pivots (array) : array array of Pivot objects
Returns: array array of pivot bar indices
method getPoints(pivots)
Gets the array of chart.point from array of Pivots
Namespace types: array
Parameters:
pivots (array) : array array of Pivot objects
Returns: array array of pivot points
method getPoints(this)
Gets the array of chart.point from Zigzag Object
Namespace types: Zigzag
Parameters:
this (Zigzag) : Zigzag object
Returns: array array of pivot points
method calculate(this, ohlc, ltfHighTime, ltfLowTime)
Calculate zigzag based on input values and indicator values
Namespace types: Zigzag
Parameters:
this (Zigzag) : Zigzag object
ohlc (array) : Array containing OHLC values. Can also have custom values for which zigzag to be calculated
ltfHighTime (int) : Used for multi timeframe zigzags when called within request.security. Default value is current timeframe open time.
ltfLowTime (int) : Used for multi timeframe zigzags when called within request.security. Default value is current timeframe open time.
Returns: current Zigzag object
method calculate(this)
Calculate zigzag based on properties embedded within Zigzag object
Namespace types: Zigzag
Parameters:
this (Zigzag) : Zigzag object
Returns: current Zigzag object
method nextlevel(this)
Calculate Next Level Zigzag based on the current calculated zigzag object
Namespace types: Zigzag
Parameters:
this (Zigzag) : Zigzag object
Returns: Next Level Zigzag object
method clear(this)
Clears zigzag drawings array
Namespace types: array
Parameters:
this (array) : array
Returns: void
method clear(this)
Clears zigzag drawings array
Namespace types: array
Parameters:
this (array) : array
Returns: void
method drawplain(this)
draws fresh zigzag based on properties embedded in ZigzagDrawing object without trying to calculate
Namespace types: ZigzagDrawing
Parameters:
this (ZigzagDrawing) : ZigzagDrawing object
Returns: ZigzagDrawing object
method drawplain(this)
draws fresh zigzag based on properties embedded in ZigzagDrawingPL object without trying to calculate
Namespace types: ZigzagDrawingPL
Parameters:
this (ZigzagDrawingPL) : ZigzagDrawingPL object
Returns: ZigzagDrawingPL object
method drawfresh(this, ohlc)
draws fresh zigzag based on properties embedded in ZigzagDrawing object
Namespace types: ZigzagDrawing
Parameters:
this (ZigzagDrawing) : ZigzagDrawing object
ohlc (array) : values on which the zigzag needs to be calculated and drawn. If not set will use regular OHLC
Returns: ZigzagDrawing object
method drawcontinuous(this, ohlc)
draws zigzag based on the zigzagmatrix input
Namespace types: ZigzagDrawing
Parameters:
this (ZigzagDrawing) : ZigzagDrawing object
ohlc (array) : values on which the zigzag needs to be calculated and drawn. If not set will use regular OHLC
Returns:
PivotCandle
PivotCandle represents data of the candle which forms either pivot High or pivot low or both
Fields:
_high (series float) : High price of candle forming the pivot
_low (series float) : Low price of candle forming the pivot
length (series int) : Pivot length
pHighBar (series int) : represents number of bar back the pivot High occurred.
pLowBar (series int) : represents number of bar back the pivot Low occurred.
pHigh (series float) : Pivot High Price
pLow (series float) : Pivot Low Price
Pivot
Pivot refers to zigzag pivot. Each pivot can contain various data
Fields:
point (chart.point) : pivot point coordinates
dir (series int) : direction of the pivot. Valid values are 1, -1, 2, -2
level (series int) : is used for multi level zigzags. For single level, it will always be 0
ratio (series float) : Price Ratio based on previous two pivots
sizeRatio (series float) : ratio of current zigzag wave size in comparison to last zigzag wave in the same direction
barRatio (series float) : Bar Ratio based on previous two pivots
ZigzagFlags
Flags required for drawing zigzag. Only used internally in zigzag calculation. Should not set the values explicitly
Fields:
newPivot (series bool) : true if the calculation resulted in new pivot
doublePivot (series bool) : true if the calculation resulted in two pivots on same bar
updateLastPivot (series bool) : true if new pivot calculated replaces the old one.
Zigzag
Zigzag object which contains whole zigzag calculation parameters and pivots
Fields:
length (series int) : Zigzag length. Default value is 5
numberOfPivots (series int) : max number of pivots to hold in the calculation. Default value is 20
offset (series int) : Bar offset to be considered for calculation of zigzag. Default is 0 - which means calculation is done based on the latest bar.
level (series int) : Zigzag calculation level - used in multi level recursive zigzags
zigzagPivots (array) : array which holds the last n pivots calculated.
flags (ZigzagFlags) : ZigzagFlags object which is required for continuous drawing of zigzag lines.
ZigzagObject
Zigzag Drawing Object
Fields:
zigzagLine (series line) : Line joining two pivots
zigzagLabel (series label) : Label which can be used for drawing the values, ratios, directions etc.
ZigzagProperties
Object which holds properties of zigzag drawing. To be used along with ZigzagDrawing
Fields:
lineColor (series color) : Zigzag line color. Default is color.blue
lineWidth (series int) : Zigzag line width. Default is 1
lineStyle (series string) : Zigzag line style. Default is line.style_solid.
showLabel (series bool) : If set, the drawing will show labels on each pivot. Default is false
textColor (series color) : Text color of the labels. Only applicable if showLabel is set to true.
maxObjects (series int) : Max number of zigzag lines to display. Default is 300
xloc (series string) : Time/Bar reference to be used for zigzag drawing. Default is Time - xloc.bar_time.
curved (series bool) : Boolean field to print curved zigzag - used only with polyline implementation
ZigzagDrawing
Object which holds complete zigzag drawing objects and properties.
Fields:
zigzag (Zigzag) : Zigzag object which holds the calculations.
properties (ZigzagProperties) : ZigzagProperties object which is used for setting the display styles of zigzag
drawings (array) : array which contains lines and labels of zigzag drawing.
ZigzagDrawingPL
Object which holds complete zigzag drawing objects and properties - polyline version
Fields:
zigzag (Zigzag) : Zigzag object which holds the calculations.
properties (ZigzagProperties) : ZigzagProperties object which is used for setting the display styles of zigzag
zigzagLabels (array)
zigzagLine (series polyline) : polyline object of zigzag lines
LineWrapperLibrary "LineWrapper"
Wrapper Type for Line.
method draw(this)
draws line as per the wrapper object contents
Namespace types: Line
Parameters:
this (Line) : (series Line) Line object.
Returns: current Line object
method draw(this)
draws lines as per the wrapper object array
Namespace types: array
Parameters:
this (array) : (series array) Array of Line object.
Returns: current Array of Line objects
method update(this)
updates or redraws line as per the wrapper object contents
Namespace types: Line
Parameters:
this (Line) : (series Line) Line object.
Returns: current Line object
method update(this)
updates or redraws lines as per the wrapper object array
Namespace types: array
Parameters:
this (array) : (series array) Array of Line object.
Returns: current Array of Line objects
method delete(this)
Deletes the underlying line drawing object
Namespace types: Line
Parameters:
this (Line) : (series Line) Line object.
Returns: Current Line object
method get_price(this, bar)
get line price based on bar
Namespace types: Line
Parameters:
this (Line) : (series Line) Line object.
bar (int) : (series/int) bar at which line price need to be calculated
Returns: line price at given bar.
Line
Line Wrapper object
Fields:
p1 (chart.point)
p2 (chart.point)
xloc (series string) : (series string) See description of x1 argument. Possible values: xloc.bar_index and xloc.bar_time. Default is xloc.bar_index.
extend (series string) : (series string) If extend=extend.none, draws segment starting at point (x1, y1) and ending at point (x2, y2). If extend is equal to extend.right or extend.left, draws a ray starting at point (x1, y1) or (x2, y2), respectively. If extend=extend.both, draws a straight line that goes through these points. Default value is extend.none.
color (series color) : (series color) Line color.
style (series string) : (series string) Line style. Possible values: line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_left, line.style_arrow_right, line.style_arrow_both.
width (series int) : (series int) Line width in pixels.
obj (series line) : line object
utilsLibrary "utils"
Few essentials captured together (subset of arrayutils)
timer(timeStart, timeEnd)
finds difference between two timestamps
Parameters:
timeStart (int) : start timestamp
timeEnd (int)
Returns:
check_overflow(pivots, barArray, dir)
finds difference between two timestamps
Parameters:
pivots (array) : pivots array
barArray (array) : pivot bar array
dir (int) : direction for which overflow need to be checked
Returns: bool overflow
get_trend_series(pivots, length, highLow, trend)
finds series of pivots in particular trend
Parameters:
pivots (array) : pivots array
length (int) : length for which trend series need to be checked
highLow (int) : filter pivot high or low
trend (int) : Uptrend or Downtrend
Returns: int trendIndexes
get_trend_series(pivots, firstIndex, lastIndex)
finds series of pivots in particular trend
Parameters:
pivots (array) : pivots array
firstIndex (int) : First index of the series
lastIndex (int) : Last index of the series
Returns: int trendIndexes
getConsolidatedLabel(include, labels, separator)
Consolidates labels into single string by concatenating it with given separator
Parameters:
include (array) : array of conditions to include label or not
labels (array) : string array of labels
separator (simple string) : Separator for concatenating labels
Returns: string labelText
getColors(theme)
gets array of colors based on theme
Parameters:
theme (simple string) : dark or light theme
Returns: color themeColors
ohlcLibrary "ohlc"
Library having OHLC and Indicator type and method implementations.
getOhlcArray(o, h, l, c, highBeforeLow, highAfterLow, lowBeforeHigh, lowAfterHigh, barindex, bartime, indicators)
get array of OHLC values when called on every bar
Parameters:
o (float) : Open price
h (float) : High Price
l (float) : Low Price
c (float) : Close Price
highBeforeLow (float) : to be calculated based on lower timeframe. high price attained within the candle before reaching the lowest point.
highAfterLow (float) : to be calculated based on lower timeframe. high price attained within the candle after reaching the lowest point.
lowBeforeHigh (float) : to be calculated based on lower timeframe. low price attained within the candle before reaching the highest point.
lowAfterHigh (float) : to be calculated based on lower timeframe. low price attained within the candle after reaching the highest point.
barindex (int) : bar_index of OHLC data
bartime (int) : time of OHLC cata
indicators (array) : array containing indicator
Returns: Array of OHLC objects
push(this, item, maxItems)
Push items to OHLC array with maxItems limit
Parameters:
this (array)
item (OHLC) : OHLC Item to be pushed to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
push(this, item, maxItems)
Push items to Indicator array with maxItems limit
Parameters:
this (array)
item (Indicator) : Indicator Item to be pushed to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
unshift(this, item, maxItems)
Unshift items to OHLC array with maxItems limit
Parameters:
this (array)
item (OHLC) : OHLC Item to be unshifted to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
unshift(this, item, maxItems)
Unshift items to Indicator array with maxItems limit
Parameters:
this (array)
item (Indicator) : Indicator Item to be unshifted to the array
maxItems (int) : max Items the array can hold at a time
Returns: current object
method getPoints(indicators)
get array of points based on array of indicator values
Namespace types: array
Parameters:
indicators (array) : Array containing indicator objects
Returns: array of indicator points
method plot(indicator, xloc, line_color, line_style, line_width)
plots an array of Indicator using polyline
Namespace types: array
Parameters:
indicator (array) : Array containing indicator objects
xloc (string) : can have values xloc.bar_index or xloc.bar_time. Used for drawing the line based on either bars or time.
line_color (color) : color in which the plots need to be printed on chart.
line_style (string) : line style line.style_solid, line.style_dotted, line.style_dashed, line.style_arrow_right, line.style_arrow_left, line.style_arrow_both
line_width (int) : width of the plot line
Returns: array of plot polyline
Indicator
Object containing Indicator name and value
Fields:
name (series string) : Indicator Name
value (chart.point) : Indicator Value as a chart point
OHLC
Object containing OHLC and indicator values
Fields:
o (series float) : Open price
h (series float) : High Price
l (series float) : Low Price
c (series float) : Close Price
highBeforeLow (series float) : to be calculated based on lower timeframe. high price attained within the candle before reaching the lowest point.
highAfterLow (series float) : to be calculated based on lower timeframe. high price attained within the candle after reaching the lowest point.
lowBeforeHigh (series float) : to be calculated based on lower timeframe. low price attained within the candle before reaching the highest point.
lowAfterHigh (series float) : to be calculated based on lower timeframe. low price attained within the candle after reaching the highest point.
barindex (series int) : bar_index of OHLC data
bartime (series int) : time of OHLC cata
indicators (array) : array containing indicator
arraysLibrary "arrays"
Supplementary array methods.
method delete(arr, index)
remove int object from array of integers at specific index
Namespace types: array
Parameters:
arr (array) : int array
index (int) : index at which int object need to be removed
Returns: void
method delete(arr, index)
remove float object from array of float at specific index
Namespace types: array
Parameters:
arr (array) : float array
index (int) : index at which float object need to be removed
Returns: float
method delete(arr, index)
remove bool object from array of bool at specific index
Namespace types: array
Parameters:
arr (array) : bool array
index (int) : index at which bool object need to be removed
Returns: bool
method delete(arr, index)
remove string object from array of string at specific index
Namespace types: array
Parameters:
arr (array) : string array
index (int) : index at which string object need to be removed
Returns: string
method delete(arr, index)
remove color object from array of color at specific index
Namespace types: array
Parameters:
arr (array) : color array
index (int) : index at which color object need to be removed
Returns: color
method delete(arr, index)
remove chart.point object from array of chart.point at specific index
Namespace types: array
Parameters:
arr (array) : chart.point array
index (int) : index at which chart.point object need to be removed
Returns: void
method delete(arr, index)
remove line object from array of lines at specific index and deletes the line
Namespace types: array
Parameters:
arr (array) : line array
index (int) : index at which line object need to be removed and deleted
Returns: void
method delete(arr, index)
remove label object from array of labels at specific index and deletes the label
Namespace types: array
Parameters:
arr (array) : label array
index (int) : index at which label object need to be removed and deleted
Returns: void
method delete(arr, index)
remove box object from array of boxes at specific index and deletes the box
Namespace types: array
Parameters:
arr (array) : box array
index (int) : index at which box object need to be removed and deleted
Returns: void
method delete(arr, index)
remove table object from array of tables at specific index and deletes the table
Namespace types: array
Parameters:
arr (array) : table array
index (int) : index at which table object need to be removed and deleted
Returns: void
method delete(arr, index)
remove linefill object from array of linefills at specific index and deletes the linefill
Namespace types: array
Parameters:
arr (array) : linefill array
index (int) : index at which linefill object need to be removed and deleted
Returns: void
method delete(arr, index)
remove polyline object from array of polylines at specific index and deletes the polyline
Namespace types: array
Parameters:
arr (array) : polyline array
index (int) : index at which polyline object need to be removed and deleted
Returns: void
method popr(arr)
remove last int object from array
Namespace types: array
Parameters:
arr (array) : int array
Returns: int
method popr(arr)
remove last float object from array
Namespace types: array
Parameters:
arr (array) : float array
Returns: float
method popr(arr)
remove last bool object from array
Namespace types: array
Parameters:
arr (array) : bool array
Returns: bool
method popr(arr)
remove last string object from array
Namespace types: array
Parameters:
arr (array) : string array
Returns: string
method popr(arr)
remove last color object from array
Namespace types: array
Parameters:
arr (array) : color array
Returns: color
method popr(arr)
remove last chart.point object from array
Namespace types: array
Parameters:
arr (array) : chart.point array
Returns: void
method popr(arr)
remove and delete last line object from array
Namespace types: array
Parameters:
arr (array) : line array
Returns: void
method popr(arr)
remove and delete last label object from array
Namespace types: array
Parameters:
arr (array) : label array
Returns: void
method popr(arr)
remove and delete last box object from array
Namespace types: array
Parameters:
arr (array) : box array
Returns: void
method popr(arr)
remove and delete last table object from array
Namespace types: array
Parameters:
arr (array) : table array
Returns: void
method popr(arr)
remove and delete last linefill object from array
Namespace types: array
Parameters:
arr (array) : linefill array
Returns: void
method popr(arr)
remove and delete last polyline object from array
Namespace types: array
Parameters:
arr (array) : polyline array
Returns: void
method shiftr(arr)
remove first int object from array
Namespace types: array
Parameters:
arr (array) : int array
Returns: int
method shiftr(arr)
remove first float object from array
Namespace types: array
Parameters:
arr (array) : float array
Returns: float
method shiftr(arr)
remove first bool object from array
Namespace types: array
Parameters:
arr (array) : bool array
Returns: bool
method shiftr(arr)
remove first string object from array
Namespace types: array
Parameters:
arr (array) : string array
Returns: string
method shiftr(arr)
remove first color object from array
Namespace types: array
Parameters:
arr (array) : color array
Returns: color
method shiftr(arr)
remove first chart.point object from array
Namespace types: array
Parameters:
arr (array) : chart.point array
Returns: void
method shiftr(arr)
remove and delete first line object from array
Namespace types: array
Parameters:
arr (array) : line array
Returns: void
method shiftr(arr)
remove and delete first label object from array
Namespace types: array
Parameters:
arr (array) : label array
Returns: void
method shiftr(arr)
remove and delete first box object from array
Namespace types: array
Parameters:
arr (array) : box array
Returns: void
method shiftr(arr)
remove and delete first table object from array
Namespace types: array
Parameters:
arr (array) : table array
Returns: void
method shiftr(arr)
remove and delete first linefill object from array
Namespace types: array
Parameters:
arr (array) : linefill array
Returns: void
method shiftr(arr)
remove and delete first polyline object from array
Namespace types: array
Parameters:
arr (array) : polyline array
Returns: void
method push(arr, val, maxItems)
add int to the end of an array with max items cap. Objects are removed from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : int array
val (int) : int object to be pushed
maxItems (int) : max number of items array can hold
Returns: int
method push(arr, val, maxItems)
add float to the end of an array with max items cap. Objects are removed from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : float array
val (float) : float object to be pushed
maxItems (int) : max number of items array can hold
Returns: float
method push(arr, val, maxItems)
add bool to the end of an array with max items cap. Objects are removed from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : bool array
val (bool) : bool object to be pushed
maxItems (int) : max number of items array can hold
Returns: bool
method push(arr, val, maxItems)
add string to the end of an array with max items cap. Objects are removed from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : string array
val (string) : string object to be pushed
maxItems (int) : max number of items array can hold
Returns: string
method push(arr, val, maxItems)
add color to the end of an array with max items cap. Objects are removed from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : color array
val (color) : color object to be pushed
maxItems (int) : max number of items array can hold
Returns: color
method push(arr, val, maxItems)
add chart.point to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : chart.point array
val (chart.point) : chart.point object to be pushed
maxItems (int) : max number of items array can hold
Returns: chart.point
method push(arr, val, maxItems)
add line to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : line array
val (line) : line object to be pushed
maxItems (int) : max number of items array can hold
Returns: line
method push(arr, val, maxItems)
add label to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : label array
val (label) : label object to be pushed
maxItems (int) : max number of items array can hold
Returns: label
method push(arr, val, maxItems)
add box to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : box array
val (box) : box object to be pushed
maxItems (int) : max number of items array can hold
Returns: box
method push(arr, val, maxItems)
add table to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : table array
val (table) : table object to be pushed
maxItems (int) : max number of items array can hold
Returns: table
method push(arr, val, maxItems)
add linefill to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : linefill array
val (linefill) : linefill object to be pushed
maxItems (int) : max number of items array can hold
Returns: linefill
method push(arr, val, maxItems)
add polyline to the end of an array with max items cap. Objects are removed and deleted from start to maintain max items cap
Namespace types: array
Parameters:
arr (array) : polyline array
val (polyline) : polyline object to be pushed
maxItems (int) : max number of items array can hold
Returns: polyline
method unshift(arr, val, maxItems)
add int to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : int array
val (int) : int object to be unshift
maxItems (int) : max number of items array can hold
Returns: int
method unshift(arr, val, maxItems)
add float to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : float array
val (float) : float object to be unshift
maxItems (int) : max number of items array can hold
Returns: float
method unshift(arr, val, maxItems)
add bool to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : bool array
val (bool) : bool object to be unshift
maxItems (int) : max number of items array can hold
Returns: bool
method unshift(arr, val, maxItems)
add string to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : string array
val (string) : string object to be unshift
maxItems (int) : max number of items array can hold
Returns: string
method unshift(arr, val, maxItems)
add color to the beginning of an array with max items cap. Objects are removed from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : color array
val (color) : color object to be unshift
maxItems (int) : max number of items array can hold
Returns: color
method unshift(arr, val, maxItems)
add chart.point to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : chart.point array
val (chart.point) : chart.point object to be unshift
maxItems (int) : max number of items array can hold
Returns: chart.point
method unshift(arr, val, maxItems)
add line to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : line array
val (line) : line object to be unshift
maxItems (int) : max number of items array can hold
Returns: line
method unshift(arr, val, maxItems)
add label to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : label array
val (label) : label object to be unshift
maxItems (int) : max number of items array can hold
Returns: label
method unshift(arr, val, maxItems)
add box to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : box array
val (box) : box object to be unshift
maxItems (int) : max number of items array can hold
Returns: box
method unshift(arr, val, maxItems)
add table to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : table array
val (table) : table object to be unshift
maxItems (int) : max number of items array can hold
Returns: table
method unshift(arr, val, maxItems)
add linefill to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : linefill array
val (linefill) : linefill object to be unshift
maxItems (int) : max number of items array can hold
Returns: linefill
method unshift(arr, val, maxItems)
add polyline to the beginning of an array with max items cap. Objects are removed and deleted from end to maintain max items cap
Namespace types: array
Parameters:
arr (array) : polyline array
val (polyline) : polyline object to be unshift
maxItems (int) : max number of items array can hold
Returns: polyline
method isEmpty(arr)
checks if an int array is either null or empty
Namespace types: array
Parameters:
arr (array) : int array
Returns: bool
method isEmpty(arr)
checks if a float array is either null or empty
Namespace types: array
Parameters:
arr (array) : float array
Returns: bool
method isEmpty(arr)
checks if a string array is either null or empty
Namespace types: array
Parameters:
arr (array) : string array
Returns: bool
method isEmpty(arr)
checks if a bool array is either null or empty
Namespace types: array
Parameters:
arr (array) : bool array
Returns: bool
method isEmpty(arr)
checks if a color array is either null or empty
Namespace types: array
Parameters:
arr (array) : color array
Returns: bool
method isEmpty(arr)
checks if a chart.point array is either null or empty
Namespace types: array
Parameters:
arr (array) : chart.point array
Returns: bool
method isEmpty(arr)
checks if a line array is either null or empty
Namespace types: array
Parameters:
arr (array) : line array
Returns: bool
method isEmpty(arr)
checks if a label array is either null or empty
Namespace types: array
Parameters:
arr (array) : label array
Returns: bool
method isEmpty(arr)
checks if a box array is either null or empty
Namespace types: array
Parameters:
arr (array) : box array
Returns: bool
method isEmpty(arr)
checks if a linefill array is either null or empty
Namespace types: array
Parameters:
arr (array) : linefill array
Returns: bool
method isEmpty(arr)
checks if a polyline array is either null or empty
Namespace types: array
Parameters:
arr (array) : polyline array
Returns: bool
method isEmpty(arr)
checks if a table array is either null or empty
Namespace types: array
Parameters:
arr (array) : table array
Returns: bool
method isNotEmpty(arr)
checks if an int array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : int array
Returns: bool
method isNotEmpty(arr)
checks if a float array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : float array
Returns: bool
method isNotEmpty(arr)
checks if a string array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : string array
Returns: bool
method isNotEmpty(arr)
checks if a bool array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : bool array
Returns: bool
method isNotEmpty(arr)
checks if a color array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : color array
Returns: bool
method isNotEmpty(arr)
checks if a chart.point array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : chart.point array
Returns: bool
method isNotEmpty(arr)
checks if a line array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : line array
Returns: bool
method isNotEmpty(arr)
checks if a label array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : label array
Returns: bool
method isNotEmpty(arr)
checks if a box array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : box array
Returns: bool
method isNotEmpty(arr)
checks if a linefill array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : linefill array
Returns: bool
method isNotEmpty(arr)
checks if a polyline array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : polyline array
Returns: bool
method isNotEmpty(arr)
checks if a table array is not null and has at least one item
Namespace types: array
Parameters:
arr (array) : table array
Returns: bool
method flush(arr)
remove all int objects in an array
Namespace types: array
Parameters:
arr (array) : int array
Returns: int
method flush(arr)
remove all float objects in an array
Namespace types: array
Parameters:
arr (array) : float array
Returns: float
method flush(arr)
remove all bool objects in an array
Namespace types: array
Parameters:
arr (array) : bool array
Returns: bool
method flush(arr)
remove all string objects in an array
Namespace types: array
Parameters:
arr (array) : string array
Returns: string
method flush(arr)
remove all color objects in an array
Namespace types: array
Parameters:
arr (array) : color array
Returns: color
method flush(arr)
remove all chart.point objects in an array
Namespace types: array
Parameters:
arr (array) : chart.point array
Returns: chart.point
method flush(arr)
remove and delete all line objects in an array
Namespace types: array
Parameters:
arr (array) : line array
Returns: line
method flush(arr)
remove and delete all label objects in an array
Namespace types: array
Parameters:
arr (array) : label array
Returns: label
method flush(arr)
remove and delete all box objects in an array
Namespace types: array
Parameters:
arr (array) : box array
Returns: box
method flush(arr)
remove and delete all table objects in an array
Namespace types: array
Parameters:
arr (array) : table array
Returns: table
method flush(arr)
remove and delete all linefill objects in an array
Namespace types: array
Parameters:
arr (array) : linefill array
Returns: linefill
method flush(arr)
remove and delete all polyline objects in an array
Namespace types: array
Parameters:
arr (array) : polyline array
Returns: polyline
jsonBuilderLibrary "jsonBuilder"
jsonBuilder is a lightweight Pine Script utility library for building JSON strings manually. It includes functions to convert key-value pairs into JSON format and to combine multiple pairs into a complete JSON object.
jsonString(key, value) – Converts a string key and string value into a valid JSON key-value pair.
jsonObject(pair1, ..., pair20) – Merges up to 20 key-value pairs into a complete JSON object string. Empty arguments are skipped automatically.
This is useful when sending structured JSON data via webhooks or external integrations from Pine Script.
MyReusableFunctionsLibrary "MyReusableFunctions"
Library of trend direction functions using pivot points
CurrentSymbolTrendDirection(pivotPeriod)
Parameters:
pivotPeriod (int) : The period to use for pivot point detection
Returns: String direction ("up"/"down"), integer direction (1/-1), and previous pivot high/low values
OtherSymbolSmallTrendDirection(symbol, timeframe)
Parameters:
symbol (string) : The symbol to analyze
timeframe (string) : The timeframe to use
Returns: String direction ("up"/"down"), integer direction (1/-1), and previous pivot high/low values
OtherSymbolLargeTrendDirection(symbol, timeframe)
Parameters:
symbol (string)
timeframe (string)
isInCustomTimeRange(startHour, startMinute, endHour, endMinute)
Parameters:
startHour (int) : Starting hour (0-23)
startMinute (int) : Starting minute (0-59)
endHour (int) : Ending hour (0-23)
endMinute (int) : Ending minute (0-59)
Returns: boolean True if current time is within the specified range
getTimeConditions()
TimeConditions
Fields:
isMarketHours (series bool)
isPreMarket (series bool)
isMarketOpen (series bool)
isMarketClose (series bool)
isLondonOpen (series bool)
isOvernightHours (series bool)
fork_libsmc
Library "fork_libsmc"
this is fork of robbatt's lib_smc
description:
This is an adaptation of LuxAlgo's Smart Money Concepts indicator with numerous changes.
Main changes include integration of object based plotting, plenty of performance improvements, live tracking of Order Blocks, integration of volume profiles to refine Order Blocks, and many more.This is a library for developers,
////////////////////////////////////////////////////////////
fork_libsmc
v1 - support show price level: swing point, market structure, broken OrderBlock ( using profile.show_price_levels )
financial_history_utilsLibrary "financial_history_utils"
get_fq_value_n_quarters_ago(symbol, financial_id, n)
Parameters:
symbol (string)
financial_id (string)
n (int)
Volatility_ZigZag_LibraryLibrary "Volatility_ZigZag_Library"
getValues_andStyling_VolatilityZigZag_byBrettkind(hl_src, SOURCE, length, min_dev_input, pvt_length, stdev_fctr, ZigZag, zz_color, zz_width, zz_devline, zz_points, zz_alert_sign, ZZ_Label, ZZ_Label_clr, rev_text, zz_bars_text, pcabs_text, avg_pcabs_text, pcrel_text, avg_pcrel_text, vol_text, avg_vol_text, text_size, input_currency)
Parameters:
hl_src (bool)
SOURCE (float)
length (int)
min_dev_input (float)
pvt_length (int)
stdev_fctr (float)
ZigZag (bool)
zz_color (color)
zz_width (int)
zz_devline (bool)
zz_points (bool)
zz_alert_sign (bool)
ZZ_Label (bool)
ZZ_Label_clr (color)
rev_text (bool)
zz_bars_text (bool)
pcabs_text (bool)
avg_pcabs_text (bool)
pcrel_text (bool)
avg_pcrel_text (bool)
vol_text (bool)
avg_vol_text (bool)
text_size (string)
input_currency (string)
getStatisticTable_VolatilityZigZag_byBrettkind(x1, Y1_array, number_of_bars_array, draw_tbl)
Parameters:
x1 (int)
Y1_array (array)
number_of_bars_array (array)
draw_tbl (bool)
suntimelibLibrary "suntimelib"
calculate_sunrise_time_trig(latitude, longitude, day, mon, yr, is_sunset)
Parameters:
latitude (float)
longitude (float)
day (int)
mon (int)
yr (int)
is_sunset (bool)
calculate_sunrise_time(cityId, _year, _month, _dayofmonth, lat, lon)
Parameters:
cityId (string)
_year (int)
_month (int)
_dayofmonth (int)
lat (float)
lon (float)
sunArray
Fields:
cityId (series string)
year (series int)
month (series int)
dates (array)
cityArray
Fields:
cityId (series string)
sunArrays (array)
PineVersatilitiesBundleLibrary "PineVersatilitiesBundle"
Versatilities (aka, Versatile Utilities) Pack includes:
- Eighteen Price Variants bundled in a Map,
- Nine Smoothing Variants bundled in a Map,
- Visualisations that indicate on both - pane and chart.
price_variants(lb)
Computes Several different averages using current and previous OHLC values
Parameters:
lb (int) : - lookback distance for combining OHLC values from the past with the present
Returns: Map of Eighteen Uncommon Combinations of single and two-bar OHLC averages (rounded-to-mintick)
dynamic_MA(masrc, malen, lsmaoff, almasgm, almaoff, almaflr)
Dynamically computes Eight different MAs and returns a Map containing Nine MAs
Parameters:
masrc (float) : source series to compute MA
malen (simple int) : lookback distance for MA
lsmaoff (simple int) : optional LSMA offset - default is 0
almasgm (simple float) : optional ALMA sigma - default is 5
almaoff (simple float) : optional ALMA offset - default is 0.5
almaflr (simple bool) : optional ALMA floor flag - default is false
Returns: Map of MAs - 'ALMA', 'EMA', 'HMA', 'LSMA', 'RMA', 'SMA', 'SWMA', 'WMA', 'ALL' (rounded-to-mintick)
EMACrossLibLibrary "EMACrossLib"
Common functions for EMA strategies
calcEMAs(src, fastLength, slowLength)
Parameters:
src (float)
fastLength (simple int)
slowLength (simple int)
detectCrossovers(fastEMA, slowEMA)
Parameters:
fastEMA (float)
slowEMA (float)
prepareWebhookMessage(epic, direction, size)
Parameters:
epic (string)
direction (string)
size (float)
next_libsmcLibrary "next_libsmc"
TODO: add library description here
method init(this)
Namespace types: OrderBlockConfig
Parameters:
this (OrderBlockConfig)
method delete(this)
Namespace types: OrderBlock
Parameters:
this (OrderBlock)
method delete(blocks)
Namespace types: array
Parameters:
blocks (array)
method delete(this)
delete the plot of an object, including deleting it from the chart
Namespace types: FVG
Parameters:
this (FVG)
method delete(fvgs)
delete the plot of an array of objects, including deleting it from the chart
Namespace types: array
Parameters:
fvgs (array)
create_ob(id, mode, start_t, start_i, top, end_t, end_i, bottom, break_price, break_mode)
INTERNAL: set internal order block coordinates
Parameters:
id (int)
mode (int) : 1: bullish, -1 bearish block
start_t (int)
start_i (int)
top (float)
end_t (int)
end_i (int)
bottom (float)
break_price (float)
break_mode (simple LevelBreakMode)
Returns: signals are true if an according order block was broken/mitigated
method align_to_profile(block, align_edge, align_break_price)
Namespace types: OrderBlock
Parameters:
block (OrderBlock)
align_edge (bool)
align_break_price (bool)
method create_profile(block, opens, tops, bottoms, closes, values, resolution, vah_pc, val_pc, init_calculated, use_open_close_data_for_blocks_shorter_than_bars)
Namespace types: OrderBlock
Parameters:
block (OrderBlock)
opens (array)
tops (array)
bottoms (array)
closes (array)
values (array)
resolution (int)
vah_pc (float)
val_pc (float)
init_calculated (bool)
use_open_close_data_for_blocks_shorter_than_bars (simple int)
method create_profile(block, resolution, vah_pc, val_pc, init_calculated, use_open_close_data_for_blocks_shorter_than_bars)
Namespace types: OrderBlock
Parameters:
block (OrderBlock)
resolution (int)
vah_pc (float)
val_pc (float)
init_calculated (bool)
use_open_close_data_for_blocks_shorter_than_bars (simple int)
track_obs(swing_len, swing_high_confirmed, swing_low_confirmed, bull_bos_alert, bull_choch_alert, bear_bos_alert, bear_choch_alert, min_block_size, max_block_size, enabled, include_consecutive_bars, capture_profile, align_edge_to_value_area, align_break_price_to_poc, use_soft_confirm, soft_confirm_offset, use_soft_confirm_big_candle, use_retracements_with_FVG_out, broken_by, keep_broken_max, gc_cycle)
Parameters:
swing_len (int)
swing_high_confirmed (float)
swing_low_confirmed (float)
bull_bos_alert (bool)
bull_choch_alert (bool)
bear_bos_alert (bool)
bear_choch_alert (bool)
min_block_size (float)
max_block_size (float)
enabled (bool)
include_consecutive_bars (simple bool)
capture_profile (simple bool)
align_edge_to_value_area (simple bool)
align_break_price_to_poc (simple bool)
use_soft_confirm (simple bool)
soft_confirm_offset (float)
use_soft_confirm_big_candle (simple bool)
use_retracements_with_FVG_out (simple bool)
broken_by (simple LevelBreakMode)
keep_broken_max (simple int)
gc_cycle (simple int)
method draw(this, config, extend_only, force_overlay, left_override, right_override)
plot order block
Namespace types: OrderBlock
Parameters:
this (OrderBlock) : OrderBlock to draw
config (OrderBlockConfig) : OrderBlockConfig to apply to block
extend_only (bool) : if true, only the right x coordinate will be updated after initial draw. This enables usage of xloc.bar_index older than 254 bars (given the block has been drawn once within the 254 bars after the left coordinate bar). If you want to draw with changing left x coordinate set this to false (default: true)
force_overlay (simple bool)
left_override (int)
right_override (int)
method draw(blocks, config, extend_only, force_overlay, left_override, right_override)
plot order blocks
Namespace types: array
Parameters:
blocks (array) : array of OrderBlocks to draw
config (OrderBlockConfig) : OrderBlockConfig to apply to all blocks
extend_only (bool) : if true, only the right x coordinate will be updated after initial draw. This enables usage of xloc.bar_index older than 254 bars (given the block has been drawn once within the 254 bars after the left coordinate bar). If you want to draw with changing left x coordinate set this to false (default: true)
force_overlay (simple bool)
left_override (int) : ob left coordinate (defaults to xloc.bar_index, configure config.args.xloc to use bar_time)
right_override (int) : ob right coordinate (defaults to xloc.bar_index, configure config.args.xloc to use bar_time)
method draw(blocks, config, extend_only, force_overlay, left_override, right_override)
plot order blocks
Namespace types: map
Parameters:
blocks (map) : array of OrderBlocks to draw
config (OrderBlockConfig) : OrderBlockConfig to apply to all blocks
extend_only (bool) : if true, only the right x coordinate will be updated after initial draw. This enables usage of xloc.bar_index older than 254 bars (given the block has been drawn once within the 254 bars after the left coordinate bar). If you want to draw with changing left x coordinate set this to false (default: true)
force_overlay (simple bool)
left_override (int) : ob left x coordinate (defaults to xloc.bar_index, configure config.args.xloc to use bar_time)
right_override (int) : ob right x coordinate (defaults to xloc.bar_index, configure config.args.xloc to use bar_time)
method draw(this, config, extend_only, force_overlay, left_override, right_override)
plot FVG (Fair Value Gap)
Namespace types: FVG
Parameters:
this (FVG) : FVG to draw
config (FVGConfig) : FVGConfig to apply to fvg
extend_only (bool) : if true, only the right x coordinate will be updated after initial draw. This enables usage of xloc.bar_index older than 254 bars (given the block has been drawn once within the 254 bars after the left coordinate bar). If you want to draw with changing left x coordinate set this to false (default: true)
force_overlay (simple bool)
left_override (int)
right_override (int)
method draw(fvgs, config, extend_only, force_overlay, left_override, right_override)
plot fvgs
Namespace types: array
Parameters:
fvgs (array) : array of FVGs to draw
config (FVGConfig) : FVGConfig to apply to all fvgs
extend_only (bool) : if true, only the right x coordinate will be updated after initial draw. This enables usage of xloc.bar_index older than 254 bars (given the block has been drawn once within the 254 bars after the left coordinate bar). If you want to draw with changing left x coordinate set this to false (default: true)
force_overlay (simple bool)
left_override (int)
right_override (int)
method hide(this)
hide the plot of an object, without deleting it from the chart, so it can re-appear later without triggering a max_bars_back error when redrawing an object that has a x coordinate > 244 bars in the past (the limit for the default buffer)
Namespace types: OrderBlock
Parameters:
this (OrderBlock)
method hide(this)
hide the plot of an object, without deleting it from the chart, so it can re-appear later without triggering a max_bars_back error when redrawing an object that has a x coordinate > 244 bars in the past (the limit for the default buffer)
Namespace types: FVG
Parameters:
this (FVG)
detect_swings(length)
INTERNAL: detect swing points (HH and LL) in given range
Parameters:
length (simple int)
Returns: values are the price level where and if a new HH or LL was detected, else na
detect_pivot(mode, trend, hhll_x, hhll, super_hhll, filter_insignificant_internal_breaks)
INTERNAL: detect whether a structural level has been broken and if it was in trend direction (BoS) or against trend direction (ChoCh), also track the latest high and low swing points
Parameters:
mode (simple int) : detect 1: bullish, -1 bearish pivot points
trend (int) : current trend direction
hhll_x (int) : x-coordinate of newly detected hh/ll (bar_index)
hhll (float) : y-coordinate of newly detected hh/ll (price)
super_hhll (float) : level/y-coordinate of superior hhll (if this is an internal structure pivot level)
filter_insignificant_internal_breaks (bool) : if true pivot points / internal structure will be ignored where the wick in trend direction is longer than the opposite (likely to push further in direction of main trend)
Returns: coordinates of internal structure that has been broken (x,y): start of structure, (trail_x, trail_y): tracking hh/ll after structure break, (bos_alert, choch_alert): signal whether a structural level has been broken
detect_structure(swing_len, super_hh, super_ll, filter_insignificant_internal_breaks)
detect (and plot) structural breaks and the resulting new trend
Parameters:
swing_len (simple int)
super_hh (float) : level/y-coordinate of superior hh (for internal structure detection)
super_ll (float) : level/y-coordinate of superior ll (for internal structure detection)
filter_insignificant_internal_breaks (bool) : if true pivot points / internal structure will be ignored where the wick in trend direction is longer than the opposite (likely to push further in direction of main trend)
Returns: trend: direction 1:bullish -1:bearish, (bull_bos_alert, bull_choch_alert, top_x, top_y, trail_up_x, trail_up): whether and which level broke in a bullish direction, trailing high, (bbear_bos_alert, bear_choch_alert, tm_x, btm_y, trail_dn_x, trail_dn): same in bearish direction
plot_pivot_points(mode, x, y, enabled, args, keep_history)
INTERNAL: plot swing points
Parameters:
mode (int) : 1: bullish, -1 bearish block
x (int) : x-coordingate of swing point to plot (bar_index)
y (float) : y-coordingate of swing point to plot (price)
enabled (bool) : switch to enable/disable plotting of swing point labels
args (LabelArgs type from robbatt/lib_plot_objects/56) : object for swing point label styling
keep_history (bool) : weather to remove older swing point labels or only keep the most recent
plot_swing_levels(mode, trail_x, trail_y, trend, enabled, label_args, line_args, override_right_index)
INTERNAL: plot latest swing levels
Parameters:
mode (int) : 1: bullish, -1 bearish block
trail_x (int) : x-coordinate for latest swing point (bar_index)
trail_y (float) : y-coordinate for latest swing point (price)
trend (int) : the current trend 1: bullish, -1: bearish, to determine Strong/Weak Low/Highs
enabled (bool) : switch to enable/disable plotting of swing point labels
label_args (LabelArgs type from robbatt/lib_plot_objects/56) : object for swing point label styling
line_args (LineArgs type from robbatt/lib_plot_objects/56) : object for swing point line styling
override_right_index (int)
plot_structure(x, y, is_bos, is_choch, label_args, line_args, keep_history)
INTERNAL: plot structural breaks (BoS/ChoCh)
Parameters:
x (int) : x-coordinate of newly broken structure (bar_index)
y (float) : y-coordinate of newly broken structure (price)
is_bos (bool) : whether this structural break was in trend direction
is_choch (bool) : whether this structural break was against trend direction
label_args (LabelArgs type from robbatt/lib_plot_objects/56) : object for plot structure styling
line_args (LineArgs type from robbatt/lib_plot_objects/56) : object for plot structure styling
keep_history (bool) : weater to remove older swing point labels and only keep the most recent
detect_equal_level(mode, len, eq_threshold, enabled)
INTERNAL: detect equal levels (double top/bottom)
Parameters:
mode (int) : detect 1: bullish/high, -1 bearish/low pivot points
len (int) : lookback period for equal level (swing point) detection
eq_threshold (float) : maximum price offset for a level to be considered equal
enabled (bool)
Returns: eq_alert whether an equal level was detected and coordinates of the first and the second level/swing point
detect_equal_levels(len, threshold, enabled)
detect (and plot) equal levels (double top/bottom), returns coordinates
Parameters:
len (int) : lookback period for equal level (swing point) detection
threshold (float) : maximum price offset for a level to be considered equal
enabled (bool) : whether detection is enabled
Returns: (eqh_alert, eqh_x1, eqh_y1, eqh_x2, eqh_y2) whether an equal high was detected and coordinates of the first and the second level/swing point, (eql_alert, eql_x1, eql_y1, eql_x2, eql_y2) same for equal lows
plot_equal_level(show_eq, x1, y1, x2, y2, label_txt, label_args, line_args, keep_history, force_overlay)
INTERNAL: plot equal levels (double top/bottom)
Parameters:
show_eq (bool) : whether to plot the level or not
x1 (int) : x-coordinate of the first level / swing point
y1 (float) : y-coordinate of the first level / swing point
x2 (int) : x-coordinate of the second level / swing point
y2 (float) : y-coordinate of the second level / swing point
label_txt (string) : text for the label above/below the line connecting the equal levels
label_args (LabelArgs type from robbatt/lib_plot_objects/56)
line_args (LineArgs type from robbatt/lib_plot_objects/56)
keep_history (bool) : weater to remove older swing point labels and only keep the most recent
force_overlay (bool)
_detect_fvg(mode, enabled, size_threshold)
INTERNAL: detect FVG (fair value gap)
Parameters:
mode (int) : detect 1: bullish, -1 bearish gaps
enabled (bool) : whether detection is enabled
size_threshold (float) : filter small/insignificant gaps that are smaller than this value
Returns: whether a new FVG was detected and its top/bottom levels
_detect_fvg_object(mode, enabled, size_threshold, fill_mode, fill_target_ratio)
INTERNAL: detect FVG points (fair value gap)
Parameters:
mode (int) : detect 1: bullish, -1 bearish gaps
enabled (bool) : whether detection is enabled
size_threshold (float) : filter small/insignificant gaps that are smaller than this value
fill_mode (series LevelBreakMode)
fill_target_ratio (float) : at which point the FVG is considered as filled
Returns: whether a new FVG was detected and its left_top/right_bottom chart.points
_clear_broken_fvg(mode, upper_boxes, lower_boxes, fill_ratio)
INTERNAL: clear mitigated FVGs (fair value gaps)
Parameters:
mode (int) : detect 1: bullish, -1 bearish gaps
upper_boxes (array) : array that stores the upper parts of the FVG boxes
lower_boxes (array) : array that stores the lower parts of the FVG boxes
fill_ratio (float)
plot_fvg(mode, show, top, btm, border_color, extend_box, fill_ratio)
INTERNAL: plot (and clear broken) FVG (fair value gap)
Parameters:
mode (int) : plot 1: bullish, -1 bearish gap
show (bool) : whether plotting is enabled
top (float) : top level of fvg
btm (float) : bottom level of fvg
border_color (color) : color for the FVG box
extend_box (int) : how many bars into the future the FVG box should be extended after detection
fill_ratio (float) : target fill ratio of FVG (optional, defaults to 50%)
fvgs_values(size_threshold, enabled)
detect FVGs (fair value gaps), and return alerts and level values
Parameters:
size_threshold (float) : filter small/insignificant gaps that are smaller than this value
enabled (bool) : whether detection is enabled
Returns: (bullish_fvg_alert, bull_top, bull_btm): whether a new bullish FVG was detected and its top/bottom levels, (bearish_fvg_alert, bear_top, bear_btm): same for bearish FVGs
method clear_filled(fvgs, filled_buffer, filled_new_buffer, keep_history, discard_buffer)
Namespace types: array
Parameters:
fvgs (array)
filled_buffer (array)
filled_new_buffer (array)
keep_history (int)
discard_buffer (array)
method update(this)
Namespace types: FVG
Parameters:
this (FVG)
method update(fvgs)
Namespace types: array
Parameters:
fvgs (array)
method remove_insignificant(fvgs, size_threshold, removed_buffer)
removes FVGs smaller than size_threshold from fvgs. If a removed_buffer is passed, it adds it to that buffer (plots are not deleted because it would be a 'side effect' in security calls, make sure to call delete() on each removed FVG to remove it from the chart as well.)
Namespace types: array
Parameters:
fvgs (array)
size_threshold (float)
removed_buffer (array)
fvgs_objects(fill_mode, fill_target_ratio, size_threshold, enabled, filled_max_keep, gc_cycle)
detect FVGs (fair value gaps), and return FVG objects
Parameters:
fill_mode (simple LevelBreakMode)
fill_target_ratio (float)
size_threshold (float) : filter small/insignificant gaps that are smaller than this value
enabled (simple bool) : whether detection is enabled
filled_max_keep (simple int)
gc_cycle (simple int)
Returns: (bullish_fvg_alert, bearish_fvg_alert) boolean flag to indicate a new FVG | (buffer_bull, buffer_bear) persistent buffers of unfilled FVGs with latest at the end | (new_bull, new_bear) newly detected FVG objects additionally to being added to the buffer | (filled_bull, filled_bear) non persistent arrays of FVGs filled in this candle
fvgs_plot(bullish_fvg_alert, bull_top, bull_btm, bearish_fvg_alert, bear_top, bear_btm, color_bull, color_bear, extend_box, fill_ratio, show)
detect (and plot / clear broken) FVGs (fair value gaps), and return alerts and level values
Parameters:
bullish_fvg_alert (bool)
bull_top (float)
bull_btm (float)
bearish_fvg_alert (bool)
bear_top (float)
bear_btm (float)
color_bull (color) : color for bullish FVG boxes
color_bear (color) : color for bearish FVG boxes
extend_box (int) : how many bars into the future the FVG box should be extended after detection
fill_ratio (float) : (optional) target fill ratio at which the box is removed (defaults to 0.5)
show (bool) : whether plotting is enabled
Returns: (bullish_fvg_alert, bull_top, bull_mid, bull_btm): whether a new bullish FVG was detected and its top/mid/bottom levels, (bearish_fvg_alert, bear_top, bear_mid, bear_btm): same for bearish FVGs
fvgs(size_threshold, color_bull, color_bear, extend_box, fill_ratio, enabled, show)
detect (and plot / clear broken) FVGs (fair value gaps)
Parameters:
size_threshold (float) : filter small/insignificant gaps that are smaller than this value
color_bull (color) : color for bullish FVG boxes
color_bear (color) : color for bearish FVG boxes
extend_box (int) : how many bars into the future the FVG box should be extended after detection
fill_ratio (float) : (optional) target fill ratio at which the box is removed (defaults to 0.5)
enabled (bool) : whether detection is enabled
show (bool) : whether plotting is enabled
Returns: (bullish_fvg_alert): whether a new bullish FVG was detected, (bearish_fvg_alert): same for bearish FVGs
OrderBlock
Fields:
id (series int)
dir (series int)
left_top (chart.point)
right_bottom (chart.point)
break_price (series float)
break_mode (series LevelBreakMode)
ltf_open (array)
ltf_high (array)
ltf_low (array)
ltf_close (array)
ltf_volume (array)
plot (Box type from robbatt/lib_plot_objects/56)
profile (Profile type from robbatt/lib_profile/44)
probability (series float)
trailing (series bool)
extending (series bool)
awaiting_confirmation (series bool)
touched_break_price_before_confirmation (series bool)
soft_confirmed (series bool)
has_fvg_out (series bool)
has_big_candle (series bool)
hidden (series bool)
broken (series bool)
broken_time (series int)
broken_index (series int)
OrderBlockConfig
Fields:
show (series bool)
show_last (series int)
show_id (series bool)
show_profile (series bool)
show_text (series bool)
show_fvg_out (series bool)
show_probability (series bool)
extend_until_broken (series bool)
args (BoxArgs type from robbatt/lib_plot_objects/56)
txt (series string)
txt_args (BoxTextArgs type from robbatt/lib_plot_objects/56)
use_profile (series bool)
profile_config (ProfileConfig type from robbatt/lib_profile/44)
FVGConfig
Fields:
show_box (series bool)
show_target (series bool)
show_target_label (series bool)
show_last (series int)
show_text (series bool)
show_probability (series bool)
show_profile (series bool)
box_args (BoxArgs type from robbatt/lib_plot_objects/56)
box_text_args (BoxTextArgs type from robbatt/lib_plot_objects/56)
line_args (LineArgs type from robbatt/lib_plot_objects/56)
label_args (LabelArgs type from robbatt/lib_plot_objects/56)
txt (series string)
extend_bars (series int)
extend_until_filled (series bool)
FVG
Fields:
dir (series int)
fill_mode (series LevelBreakMode)
left_top (chart.point)
right_bottom (chart.point)
fvg_fill_target_ratio (series float)
fill_target_level (series float)
fill_current_ratio (series float)
fill_current_level (series float)
total_volume (series float)
probability (series float)
filled (series bool)
fill_time (series int)
fill_index (series int)
plot_box (Box type from robbatt/lib_plot_objects/56)
plot_fill_target_level (Line type from robbatt/lib_plot_objects/56)
plot_fill_target_label (Label type from robbatt/lib_plot_objects/56)
hidden (series bool)
NYCSessionLibrary "NYCSession"
Library for New York trading session time functions
@author abneralvarado
@version 1.0
isInNYSession(sessionStart, sessionEnd)
Determines if the current bar is within New York trading session
Parameters:
sessionStart (simple int) : Starting time of NY session in 24hr format (HHMM) like 0930 for 9:30 AM ET
sessionEnd (simple int) : Ending time of NY session in 24hr format (HHMM) like 1600 for 4:00 PM ET
Returns: True if current bar is within the NY session time, false otherwise
getNYSessionStartTime(lookback, sessionStart)
Gets the start time of NY session for a given bar
Parameters:
lookback (simple int) : Bar index to check (0 is current bar)
sessionStart (simple int) : Starting time of NY session in 24hr format (HHMM)
Returns: Unix timestamp for the start of NY session on the given bar's date
getNYSessionEndTime(lookback, sessionEnd)
Gets the end time of NY session for a given bar
Parameters:
lookback (simple int) : Bar index to check (0 is current bar)
sessionEnd (simple int) : Ending time of NY session in 24hr format (HHMM)
Returns: Unix timestamp for the end of NY session on the given bar's date
isNYSessionOpen(sessionStart)
Checks if current bar opens the NY session
Parameters:
sessionStart (simple int) : Starting time of NY session in 24hr format (HHMM)
Returns: True if current bar marks the session opening, false otherwise
isNYSessionClose(sessionEnd)
Checks if current bar closes the NY session
Parameters:
sessionEnd (simple int) : Ending time of NY session in 24hr format (HHMM)
Returns: True if current bar marks the session closing, false otherwise
isWeekday()
Determines if the current day is a weekday (Mon-Fri)
Returns: True if current bar is on a weekday, false otherwise
getSessionBackgroundColor(sessionStart, sessionEnd, bgColor)
Gets session background color with transparency
Parameters:
sessionStart (simple int) : Starting time of NY session in 24hr format (HHMM)
sessionEnd (simple int) : Ending time of NY session in 24hr format (HHMM)
bgColor (color) : Background color for session highlighting
Returns: Color value for background or na if not in session
DoppelLibLibrary "DoppelLib"
getDailyClose(offset)
Returns the daily close for a specific offset.
For each offset value (from 1 to 21), the function uses a static request.security() call
to retrieve the daily close from the previous day at the specified offset.
Parameters:
offset (int) : (int) The offset value (from 1 to 21) representing the desired close value.
Returns: (float) The daily close for the specified offset or na if offset is out of range.
isVolumeAboveThreshold(vol, mediaPeriod, thresholdPercent)
Checks if the current volume is above the threshold based on its moving average.
The threshold is calculated as the average volume plus a percentage increment.
Parameters:
vol (float) : (series float) The volume series (e.g. the chart volume).
mediaPeriod (int) : (int) The period for calculating the moving average.
thresholdPercent (float) : (float) The percentage to add to the average for the threshold.
Returns: (bool) True if the volume exceeds the threshold, false otherwise.
calcPvsra(pvsraVolume, pvsraHigh, pvsraLow, pvsraClose, pvsraOpen, redVectorColor, greenVectorColor, violetVectorColor, blueVectorColor, darkGreyCandleColor, lightGrayCandleColor)
Calculates the PVSRA candle color, determines if a vector candle has appeared,
and returns additional support parameters (average volume, volume spread, highest volume spread).
- "High" (Climax): volume >= 200% of the average OR (volume * candle spread) >= highest spread over the previous 10 bars.
-> Bull candle: green; Bear candle: red.
- "Medium": volume >= 150% of the average.
-> Bull candle: blue; Bear candle: violet.
- Otherwise, default (non-vector) candle colors are used.
Parameters:
pvsraVolume (float) : (series float) Volume series.
pvsraHigh (float) : (series float) High price series.
pvsraLow (float) : (series float) Low price series.
pvsraClose (float) : (series float) Close price series.
pvsraOpen (float) : (series float) Open price series.
redVectorColor (simple color) : (simple color) Color for bearish candle in high scenario.
greenVectorColor (simple color) : (simple color) Color for bullish candle in high scenario.
violetVectorColor (simple color) : (simple color) Color for bearish candle in medium scenario.
blueVectorColor (simple color) : (simple color) Color for bullish candle in medium scenario.
darkGreyCandleColor (simple color) : (simple color) Color for bearish candle in non-vector situation.
lightGrayCandleColor (simple color) : (simple color) Color for bullish candle in non-vector situation.
Returns: (tuple) A tuple containing: .
NR_VersatilitiesLibrary "NR_Versatilities"
Versatilities (aka, Versatile Utilities) includes:
- Seventeen Price Variants returned as a tuple,
- Eight Smoothing functions rolled into one,
- Pick any Past Value from any series with offset,
- Or just the previous value from any series.
pastVal(src, len)
Fetches past value from src that came len distance ago
Parameters:
src (float) : source series
len (int) : lookback distance - (optional) default is 1
Returns: latest src if len <= 0, else src
previous(src)
Fetches past value from src that came len distance ago
Parameters:
src (float) : source series
Returns: previous value in the series if found, else current value
price_variants()
Computes Several different averages using current and previous OHLC values
Returns: Seventeen Uncommon Average Price Combinations
dynamic_MA(matyp, masrc, malen, lsmaoff, almasgm, almaoff, almaflr)
Dynamically computes Eight different MAs on-demand individually, or an average of all taken together
Parameters:
matyp (string) : pick one of these MAs - ALMA, EMA, HMA, LSMA, RMA, SMA, SWMA, WMA, ALL
masrc (float) : source series to compute MA
malen (simple int) : lookback distance for MA
lsmaoff (simple int) : optional LSMA offset - default is 0
almasgm (simple float) : optional ALMA sigma - default is 5
almaoff (simple float) : optional ALMA offset - default is 0.5
almaflr (simple bool) : optional ALMA floor flag - default is false
Returns: MA series for chosen type or, an average of all of them, if chosen so
projectiontrackingLibrary "projectiontracking"
Library contains few data structures and methods for tracking harmonic patterns and projections via pinescript.
method erase(this)
erase Harmonic Projection Drawing
Namespace types: HarmonicProjectionDrawing
Parameters:
this (HarmonicProjectionDrawing) : HarmonicProjectionDrawing object
Returns: void
method erase(this)
erase HarmonicProjection
Namespace types: HarmonicProjection
Parameters:
this (HarmonicProjection) : HarmonicProjection object
Returns: void
method draw(this)
draw HarmonicProjection
Namespace types: HarmonicProjection
Parameters:
this (HarmonicProjection) : HarmonicProjection object
Returns: HarmonicProjection object
method getRanges(projectionPrzRanges, dir)
Convert PRZRange to Projection ranges
Namespace types: array
Parameters:
projectionPrzRanges (array type from Trendoscope/HarmonicMapLib/1) : array of PrzRange objects
dir (int) : Projection direction
Returns: array
ProjectionRange
Harmonic Projection Range
Fields:
patterns (array) : array of pattern names
start (series float) : Start Range
end (series float) : End Range
status (series int) : Projection Status
ProjectionProperties
Harmonic Projection Properties
Fields:
fillMajorTriangles (series bool) : Use linefill for major triangles
fillMinorTriangles (series bool) : Use linefill for minor triangles
majorFillTransparency (series int) : transparency of major triangles
minorFillTransparency (series int) : transparency of minor triangles
showXABC (series bool) : Show XABC labels
lblSizePivots (series string) : Pivot labels size
showRatios (series bool) : Show ratio labels
useLogScaleForScan (series bool) : Log scale is used for scanning projections
activateOnB (series bool) : Activate projections on reaching B
activationRatio (series float) : Use activation ratio for activation
confirmationRatio (series float) : Confirmation ratio of projection before removal
HarmonicProjectionDrawing
Harmonic Projection Projection drawing objects
Fields:
xa (series line) : line xa
ab (series line) : line ab
bc (series line) : line bc
xb (series line) : line xb
ac (series line) : line ac
x (series label) : Pivot label x
a (series label) : Pivot label a
b (series label) : Pivot label b
c (series label) : Pivot label c
xabRatio (series label) : Label XAB Ratio
abcRatio (series label) : Label ABC Ratio
HarmonicProjection
Harmonic Projection Projection object
Fields:
patternId (series int) : id of the pattern
dir (series int) : projection direction
x (chart.point) : Pivot X
a (chart.point) : Pivot A
b (chart.point) : Pivot B
c (chart.point) : Pivot C
patternColor (series color) : Color in which pattern is displayed
przRange (PrzRange type from Trendoscope/HarmonicMapLib/1) : PRZ Range
activationPrice (series float) : Projection activation price
reversalPrice (series float) : Projection reversal price
status (series int) : Projection status
properties (ProjectionProperties) : Projection properties
projectionRanges (array) : array of Projection Ranges
initialD (series float) : Initial D pivot
d (chart.point) : Pivot D
drawing (HarmonicProjectionDrawing) : HarmonicProjectionDrawing Object