threengine_global_automation_libraryLibrary "threengine_global_automation_library"
A collection of functions used for trade automation
getBaseCurrency()
Gets the base currency for the chart's ticker. Supported trade pairs are USD, USDT, USDC, BTC, and PERP.
Returns: Base currency as a string
getChartSymbol()
Get the current chart's symbol without the base currency appended to it. Supported trade paris are USD, USDT, USDC, BTC, and PERP.
Returns: Ssymbol and base currency
getDecimals()
Calculates how many decimals are on the quote price of the current market
Returns: The current deimal places on the market quote price
checkVar()
Plot a string as a label on the chart to test variable value. Use str.tostring() for any variable that isn't a string.
Returns: Label with stringified variable
getStrategyAlertMessage()
Generates stringified JSON for a limit order that can be passed to the strategy alert_message for a long entry.
Returns: Stringifed JSON for a long entry
taGetAdx()
Calculates the Average Directional Index
Returns: The value of ADX as a float
taGetEma()
Calculates the EMA based on a type, source, and length. Supported types are EMA, SMA, RMA, and WMA.
Returns: The value of the selected EMA
isBetweenTwoTimes()
Checks to see if within a rage based on two times
@retunrs true/false boolean
getAllTradeIDs()
This gets all closed trades and open trades
@retunrs an array of all open and closed trade ID's
getOpenTradeIDs()
This gets all open trades
@retunrs an array of all open trade ID's
orderAlreadyExists()
This checks to see if a provided order id uses the getAllTradeIDs() function to check
@retunrs an array of all open and closed trade ID's
orderCurrentlyExists()
This checks to see if a provided order id uses the getAllTradeIDs() function to check
Returns: an array of all open and closed trade ID's
getContractCount()
calulates the number of contracts you can buy with a set amount of capital and a limit price
Returns: number of contracts you can buy based on amount of capital you want to use and a price
getLadderSteps()
Returns: array of ladder entry prices and amounts based on total amount you want to invest across all ladder rungs and either a range between ladderStart and LadderStop based on specificed number of ladderRungs OR ladderStart, ladderRungs, and LadderSpacingPercent
Indicators and strategies
loxxrsxLibrary "loxxrsx"
loxxrsx: Jurik RSX
rsx(src, len)
rsx
Parameters:
src : float
len : int
Returns: result float
loxxpaaspecialLibrary "loxxpaaspecial"
loxxpaaspecial: Ehlers Phase Accumulation Dominant Cycle Period with multiplier and filter
paa(src, mult, filt)
(src, mult, filt)
Parameters:
src : float
mult : float
filt : float
Returns: result float
loxxfsrrdspfiltsLibrary "loxxfsrrdspfilts"
loxxfsrrdspfilts : FATL, SATL, RFTL, & RSTL Digital Signal Filters
fatl(src)
fatl
Parameters:
src : float
Returns: result float
rftl(src)
rftl
Parameters:
src : float
Returns: result float
satl(src)
satl
Parameters:
src : float
Returns: result float
rstl(src)
rstl
Parameters:
src : float
Returns: result float
loxxjuriktoolsLibrary "loxxjuriktools"
loxxjuriktools: Jurik tools used in Loxx's idicators and strategies
jcfbaux(src, len)
jcfbaux
Parameters:
src : float
len : int
Returns: result float
jcfb(src, len, len)
jcfb
Parameters:
src : float
len : int
len : int
Returns: result float
jurik_filt(src, len, phase)
jurik_filt
Parameters:
src : float
len : int
phase : float
Returns: result float
loxxexpandedsourcetypesLibrary "loxxexpandedsourcetypes"
Expanded source types used in Loxx's indicators and strategies.
rclose()
rClose: regular close
Returns: float
ropen()
rClose: regular open
Returns: float
rhigh()
rClose: regular high
Returns: float
rlow()
rClose: regular low
Returns: float
rmedian()
rClose: regular hl2
Returns: float
rtypical()
rClose: regular hlc3
Returns: float
rweighted()
rClose: regular hlcc4
Returns: float
raverage()
rClose: regular ohlc4
Returns: float
ravemedbody()
rClose: median body
Returns: float
rtrendb()
rClose: trend regular
Returns: float
rtrendbext()
rClose: trend extreme
Returns: float
haclose(haclose)
haclose: heiken-ashi close
Parameters:
haclose : float
Returns: float
haopen(haopen)
haopen: heiken-ashi open
Parameters:
haopen : float
Returns: float
hahigh(hahigh)
hahigh: heiken-ashi high
Parameters:
hahigh : float
Returns: float
halow(halow)
halow: heiken-ashi low
Parameters:
halow : float
Returns: float
hamedian(hamedian)
hamedian: heiken-ashi median
Parameters:
hamedian : float
Returns: float
hatypical(hatypical)
hatypical: heiken-ashi typical
Parameters:
hatypical : float
Returns: float
haweighted(haweighted)
haweighted: heiken-ashi weighted
Parameters:
haweighted : float
Returns: float
haaverage(haweighted)
haaverage: heiken-ashi average
Parameters:
haweighted : float
Returns: float
haavemedbody(haclose, haopen)
haavemedbody: heiken-ashi median body
Parameters:
haclose : float
haopen : float
Returns: float
hatrendb(haclose, haopen, hahigh, halow)
hatrendb: heiken-ashi trend
Parameters:
haclose : float
haopen : float
hahigh : float
halow : float
Returns: float
hatrendbext(haclose, haopen, hahigh, halow)
hatrendext: heiken-ashi trend extreme
Parameters:
haclose : float
haopen : float
hahigh : float
halow : float
Returns: float
habclose(smthtype, amafl, amasl, kfl, ksl)
habclose: heiken-ashi better open
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habopen(smthtype, amafl, amasl, kfl, ksl)
habopen: heiken-ashi better open
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habhigh(smthtype, amafl, amasl, kfl, ksl)
habhigh: heiken-ashi better high
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
hablow(smthtype, amafl, amasl, kfl, ksl)
hablow: heiken-ashi better low
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habmedian(smthtype, amafl, amasl, kfl, ksl)
habmedian: heiken-ashi better median
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habtypical(smthtype, amafl, amasl, kfl, ksl)
habtypical: heiken-ashi better typical
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habweighted(smthtype, amafl, amasl, kfl, ksl)
habweighted: heiken-ashi better weighted
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habaverage(smthtype, amafl, amasl, kfl, ksl)
habaverage: heiken-ashi better average
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habavemedbody(smthtype, amafl, amasl, kfl, ksl)
habavemedbody: heiken-ashi better median body
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habtrendb(smthtype, amafl, amasl, kfl, ksl)
habtrendb: heiken-ashi better trend
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
habtrendbext(smthtype, amafl, amasl, kfl, ksl)
habtrendbext: heiken-ashi better trend extreme
Parameters:
smthtype : string
amafl : int
amasl : int
kfl : int
ksl : int
Returns: float
loxxmas - moving averages used in Loxx's indis & stratsLibrary "loxxmas"
TODO:loxx moving averages used in indicators
kama(src, len, kamafastend, kamaslowend)
KAMA Kaufman adaptive moving average
Parameters:
src : float
len : int
kamafastend : int
kamaslowend : int
Returns: array
ama(src, len, fl, sl)
AMA, adaptive moving average
Parameters:
src : float
len : int
fl : int
sl : int
Returns: array
t3(src, len)
T3 moving average, adaptive moving average
Parameters:
src : float
len : int
Returns: array
adxvma(src, len)
ADXvma - Average Directional Volatility Moving Average
Parameters:
src : float
len : int
Returns: array
ahrma(src, len)
Ahrens Moving Average
Parameters:
src : float
len : int
Returns: array
alxma(src, len)
Alexander Moving Average - ALXMA
Parameters:
src : float
len : int
Returns: array
dema(src, len)
Double Exponential Moving Average - DEMA
Parameters:
src : float
len : int
Returns: array
dsema(src, len)
Double Smoothed Exponential Moving Average - DSEMA
Parameters:
src : float
len : int
Returns: array
ema(src, len)
Exponential Moving Average - EMA
Parameters:
src : float
len : int
Returns: array
fema(src, len)
Fast Exponential Moving Average - FEMA
Parameters:
src : float
len : int
Returns: array
hma(src, len)
Hull moving averge
Parameters:
src : float
len : int
Returns: array
ie2(src, len)
Early T3 by Tim Tilson
Parameters:
src : float
len : int
Returns: array
frama(src, len, FC, SC)
Fractal Adaptive Moving Average - FRAMA
Parameters:
src : float
len : int
FC : int
SC : int
Returns: array
instant(src, float)
Instantaneous Trendline
Parameters:
src : float
float : alpha
Returns: array
ilrs(src, int)
Integral of Linear Regression Slope - ILRS
Parameters:
src : float
int : len
Returns: array
laguerre(src, float)
Laguerre Filter
Parameters:
src : float
float : alpha
Returns: array
leader(src, int)
Leader Exponential Moving Average
Parameters:
src : float
int : len
Returns: array
lsma(src, int, int)
Linear Regression Value - LSMA (Least Squares Moving Average)
Parameters:
src : float
int : len
int : offset
Returns: array
lwma(src, int)
Linear Weighted Moving Average - LWMA
Parameters:
src : float
int : len
Returns: array
mcginley(src, int)
McGinley Dynamic
Parameters:
src : float
int : len
Returns: array
mcNicholl(src, int)
McNicholl EMA
Parameters:
src : float
int : len
Returns: array
nonlagma(src, int)
Non-lag moving average
Parameters:
src : float
int : len
Returns: array
pwma(src, int, float)
Parabolic Weighted Moving Average
Parameters:
src : float
int : len
float : pwr
Returns: array
rmta(src, int)
Recursive Moving Trendline
Parameters:
src : float
int : len
Returns: array
decycler(src, int)
Simple decycler - SDEC
Parameters:
src : float
int : len
Returns: array
sma(src, int)
Simple Moving Average
Parameters:
src : float
int : len
Returns: array
swma(src, int)
Sine Weighted Moving Average
Parameters:
src : float
int : len
Returns: array
slwma(src, int)
linear weighted moving average
Parameters:
src : float
int : len
Returns: array
smma(src, int)
Smoothed Moving Average - SMMA
Parameters:
src : float
int : len
Returns: array
super(src, int)
Ehlers super smoother
Parameters:
src : float
int : len
Returns: array
smoother(src, int)
Smoother filter
Parameters:
src : float
int : len
Returns: array
tma(src, int)
Triangular moving average - TMA
Parameters:
src : float
int : len
Returns: array
tema(src, int)
Tripple exponential moving average - TEMA
Parameters:
src : float
int : len
Returns: array
vwema(src, int)
Volume weighted ema - VEMA
Parameters:
src : float
int : len
Returns: array
vwma(src, int)
Volume weighted moving average - VWMA
Parameters:
src : float
int : len
Returns: array
zlagdema(src, int)
Zero-lag dema
Parameters:
src : float
int : len
Returns: array
zlagma(src, int)
Zero-lag moving average
Parameters:
src : float
int : len
Returns: array
zlagtema(src, int)
Zero-lag tema
Parameters:
src : float
int : len
Returns: array
threepolebuttfilt(src, int)
Three-pole Ehlers Butterworth
Parameters:
src : float
int : len
Returns: array
threepolesss(src, int)
Three-pole Ehlers smoother
Parameters:
src : float
int : len
Returns: array
twopolebutter(src, int)
Two-pole Ehlers Butterworth
Parameters:
src : float
int : len
Returns: array
twopoless(src, int)
Two-pole Ehlers smoother
Parameters:
src : float
int : len
Returns: array
UtilityFunctionsLibrary "UtilityFunctions"
Utility functions written by me
printLabelOnLastBar_string(string)
Prints string in a label on the last bar
Parameters:
string : value to print
Returns: void
printLabelOnLastBar_float(float)
Prints float in a label on the last bar
Parameters:
float : value to print
Returns: void
printSeriesInReverseOnLabels(series)
Prints a float series in labels in reverse (the first value is on the last candle, the second value is on the second to last candle, etc.)
Parameters:
series : float values to print
Returns: void
isPeriodDailyBased(string)
Returns true/false if the period is Daily based (1D, 3D, ...)
Parameters:
string : timeframe period
Returns: true/false
get_multiplier(string)
Gets the mutliplier of the timeframe passed compared to the current timeframe. If current TF is 5m and the passed timeframe period is 30m, the result will be 6
Parameters:
string : timeframe param
Returns: simple float of the multiplier
functionStringToMatrixLibrary "functionStringToMatrix"
Provides unbound methods (no error checking) to parse a string into a float or int matrix.
to_matrix_float(str, interval_sep, start_tk, end_tk)
Parse a string into a float matrix.
Parameters:
str : , string, the formated string to parse.
interval_sep : , string, cell interval separator token.
start_tk : , string, row start token.
end_tk : , string, row end token.
Returns: matrix, parsed float matrix.
to_matrix_int(str, interval_sep, start_tk, end_tk)
Parse a string into a int matrix.
Parameters:
str : , string, the formated string to parse.
interval_sep : , string, cell interval separator token.
start_tk : , string, row start token.
end_tk : , string, row end token.
Returns: matrix, parsed int matrix.
CyclicRsiLib█ OVERVIEW
This library is complementary for Cyclic RSI High Low With Noise Filter.
█ CREDITS
LoneSomeTheBlue
WhenToTrade
AlertFrequency()
: AlertFrequency
Parameters:
: : _string
Returns: : _freq
CyclicRSI()
: CyclicRSI
Parameters:
: : _source, _length, _expression
Returns: : osc
Credits to WhenToTrade
AddToZigzag()
: AddToZigzag
Parameters:
: : _id, value, max_array_size
Returns: : array.unshift, array.pop
Credits to LonesomeTheBlue
UpdateZigzag()
: UpdateZigzag
Parameters:
: : _id, value, max_array_size, dir
Returns: : AddToZigzag, array.set
Credits to LonesomeTheBlue
BoolZigzag()
: BoolZigzag
Parameters:
: : ph, pl, dirchanged, _id, dir
Returns: : AddToZigzag, UpdateZigzag
Credits to LonesomeTheBlue
NoiseSwitch()
: NoiseSwitch
Parameters:
: : _string, _id
Returns: : FilterNoise
LineGray()
: LineGray
Parameters:
: : _id
Returns: : LineGray
LabelDir()
: LabelDir
Parameters:
: : _id, _string, _color, _float
Returns: : LabelDir
TernaryLabel()
: TernaryLabel
Parameters:
: : _dir, _bool1, _bool2, _string1, _string2
Returns: : str_label
TernaryColor()
: TernaryColor
Parameters:
: : _dir, _bool1, _bool2
Returns: : col_label
getSeries█ OVERVIEW
This library is a Pine programmer’s tool containing functions that build an array of values meeting specific conditions. Its functions use concepts from our ConditionalAverages library , but instead of returning a single value, they return an array containing all the values meeting the conditions, which can then be processed as needed. This provides more flexibility to the programmer than a single value.
The "getSeries" name of the library stems from the fact that is uses arrays to build the equivalent of custom series which can then be operated on using array-specific functions in the `array.*` namespace, looped through using a for...in structure to implement custom logic, or sent to functions designed to process arrays such as those in these libraries: ArrayStatistics , ArrayOperations , arrayutils or Averages .
The eight examples illustrated in the library's code showcase the diversity of scenarios where the functions can be used.
Look first. Then leap.
█ FUNCTIONS
The library contains the following functions:
whenSince(src, whenCond, sinceCond, length)
Creates an array containing the `length` last `src` values where `whenCond` is true, since the last occurence of `sinceCond`.
Parameters:
src : (series int/float) The source of the values to be included.
whenCond : (series bool) The condition determining which values are included. Optional. The default is `true`.
sinceCond : (series bool) The condition determining when the accumulated series resets. Optional. The default is false, which will not reset.
length : (simple int) The number of last values to return. Optional. The default is all values.
Returns: (float ) The array ID of the accumulated `src` values.
rollOnTimeWhen(src, timeWindow, cond, minBars)
Creates an array of `src` values where `cond` is true, over a moving window of length `timeWindow` milliseconds.
Parameters:
src : (series int/float) The source of the values to be included.
timeWindow : (simple int) The time duration in milliseconds defining the size of the moving window.
cond : (series bool) The condition determining which values are included. Optional. The default is `true`.
minBars : (simple int) The minimum number of values to maintain in the moving window. Optional. The default is 1.
Returns: (float ) The array ID of the accumulated `src` values.
Note that the functions must be called on each bar to work correctly. They must thus be pre-evaluated before using their results in conditional branches.
utilsLibrary "utils"
Few essentials captured together (subset of arrayutils)
timer(timeStart, endTime)
finds difference between two timestamps
Parameters:
timeStart : start timestamp
endTime : end timestamp
Returns:
check_overflow(pivots, barArray, dir)
finds difference between two timestamps
Parameters:
pivots : pivots array
barArray : pivot bar array
dir : 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 : pivots array
length : length for which trend series need to be checked
highLow : filter pivot high or low
trend : Uptrend or Downtrend
Returns: int trendIndexes
get_trend_series(pivots, firstIndex, lastIndex)
finds series of pivots in particular trend
Parameters:
pivots : pivots array
firstIndex : First index of the series
lastIndex : 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 of conditions to include label or not
labels : string array of labels
separator : Separator for concatenating labels
Returns: string labelText
getColors(theme)
gets array of colors based on theme
Parameters:
theme : dark or light theme
Returns: color themeColors
rzigzagLibrary "rzigzag"
Recursive Zigzag Using Matrix allows to create zigzags recursively on multiple levels. After bit of consideration, decided to make this public.
zigzag(length, ohlc, numberOfPivots, offset)
calculates plain zigzag based on input
Parameters:
length : Zigzag Length
ohlc : Array containing ohlc values. Can also contain custom series
numberOfPivots : Number of max pivots to be returned
offset : Offset from current bar. Can be used for calculations based on confirmed bars
Returns:
nextlevel(zigzagmatrix, numberOfPivots)
calculates next level zigzag based on present zigzag coordinates
Parameters:
zigzagmatrix : Matrix containing zigzag pivots, bars, bar time, direction and level
numberOfPivots : Number of max pivots to be returned
Returns: matrix zigzagmatrix
draw(zigzagmatrix, newPivot, doublePivot, lineColor, lineWidth, lineStyle, showLabel, xloc)
draws zigzag based on the zigzagmatrix input
Parameters:
zigzagmatrix : Matrix containing zigzag pivots, bars, bar time, direction and level
newPivot : Flag indicating there is update in the pivots
doublePivot : Flag containing there is double pivot update on same bar
lineColor : Zigzag line color
lineWidth : Zigzag line width
lineStyle : Zigzag line style
showLabel : Flag to indicate display pivot labels
xloc : xloc preference for drawing lines/labels
Returns:
draw(length, ohlc, numberOfPivots, offset, lineColor, lineWidth, lineStyle, showLabel, xloc)
calculates and draws zigzag based on zigzag length and source input
Parameters:
length : Zigzag Length
ohlc : Array containing ohlc values. Can also contain custom series
numberOfPivots : Number of max pivots to be returned
offset : Offset from current bar. Can be used for calculations based on confirmed bars
lineColor : Zigzag line color
lineWidth : Zigzag line width
lineStyle : Zigzag line style
showLabel : Flag to indicate display pivot labels
xloc : xloc preference for drawing lines/labels
Returns:
drawfresh(zigzagmatrix, zigzaglines, zigzaglabels, lineColor, lineWidth, lineStyle, showLabel, xloc)
draws fresh zigzag for all pivots in the input matrix.
Parameters:
zigzagmatrix : Matrix containing zigzag pivots, bars, bar time, direction and level
zigzaglines : array to which all newly created lines will be added
zigzaglabels : array to which all newly created lables will be added
lineColor : Zigzag line color
lineWidth : Zigzag line width
lineStyle : Zigzag line style
showLabel : Flag to indicate display pivot labels
xloc : xloc preference for drawing lines/labels
Returns:
percentageLibLibrary "percentageLib"
: every thing need anout percentage
getPercentage(entry, exit)
: get percentage change of of two value
Parameters:
entry : : value of entry price
exit : : value of exit price
Returns: : negative or positive value
applyPercentageNoAddUp(price, percentage)
: apply percentage change on value decrease or increase
Parameters:
price : : value of price
percentage : : percentage change can be negative or positive
Returns: : return only positive value
applyPercentageAddUp(price, percentage)
: apply percentage change on value decrease or increase
Parameters:
price : : value of price
percentage : : percentage change can be negative or positive
Returns: : return only positive value
reversePercentage(percentage)
: get percentage (positive or negative) and return the percentage need to back to previous price
Parameters:
percentage : : percentage change can be negative or positive
Returns: : return positive/negative value
@example : reversePercentage(10) =>11.11111111111111111111111 , reversePercentage(10) =>9.0909090909090909
getReversePercentage(price, percentage)
: get two prices and return the percentage need to back to previous price
Parameters:
price : : value of price
percentage : : percentage change can be negative or positive
Returns: : return only positive value
@example : getReversePercentage(100,90) =>11.11111111111111111111111
multipeBarTotalPercentage()
drawcandlesLibrary "drawcandles"
simple utility to draw different candles using box and lines. Quite useful for drawing candles such as zigzag candles or MTF candles
draw(o, h, l, c, oBar, cBar)
draws candles based on ohlc values
Parameters:
o : Open Price
h : High Price
l : Low Price
c : Close Price
oBar : Open Time
cBar : Close Time
Returns: void
HarmonicSwitches█ OVERVIEW
This library is complementary for XABCD Harmonic Pattern Custom Range Interactive
TupleSwitchHL()
: Tuple Switch for High Low
Parameters:
: : _bool, low_X, high_X, low_A, high_A, low_B, high_B, low_C, high_C
Returns: : price_X, price_A, price_B, price_C
TupleSwitchStyleColor()
: Tuple switch for style and color
Parameters:
: : _bool
Returns: : style0, style1, col_dir
TupleSwitchString()
: Tuple switch for string
Parameters:
: : _bool
Returns: : str_dir, str_X, str_A
TupleSwitchValid()
: Tuple switch for valid
Parameters:
: : _str
Returns: : str_invalid, str_valid
TupleSwitchTime()
: Tuple switch for time
Parameters:
: : _str, time_1, time_2, time_3
Returns: : E1, E2
SwitchColor()
: Switch color
Parameters:
: : _str
Returns: : col_valid
SwitchExtend()
: Extend line
Parameters:
: : _str
Returns: : _extend
curveLibrary "curve"
Regression array Creator. Handy for weights, Auto Normalizes array while holding curves.
curve(_size, _power)
Curve Regression Values Tool
Parameters:
_size : (float) Number of Steps required (float works, future consideration)
_power : (float) Strength of value decrease
Returns: (float ) Array of multipliers from 1 downwards to 0.
srcCalcLibrary "srcCalc"
Provides functions for converting input strings 'open','high','low','close','hl2','hlc3','ohlc4','hlcc4' to corresponding source values.
get_src(src)
Converts string to source float value
Parameters:
src : String to use (`close` is used if no argument is supplied).
Returns: Returns the float value of the string
xor logical operatorLibrary "xor"
xor(a, b)
xor: Exclusive or, or exclusive disjunction is a logical operation that is true if and only if its arguments differ (one is true, the other is false).
Parameters:
a : first argument
b : second argument
Returns: returns xor (true only if a and b are true, but not both)
Example:
true xor true = false
true xor false = true
false xor true = true
false xor false = false
CommonMarkupLibrary "CommonMarkup"
Provides functions for chart markup, such as indicating recession bands.
markRecessionBands(showBands, lineY, labelY)
Mark vertical bands and show recession band labels if argument showBands is true. Example "markRecessionBands(bar_index ,3.0"
Parameters:
showBands : - show vertical recession bands when true. Functionally equiv to no op when false
lineY : - y-axis value for line positioning
labelY : - y-axis value for label positioning
@return true - always answers the value of showBands
Object: object oriented programming made possible! Hash map's in Pinescript?? Absolutely
This Library is the first step towards bringing a much needed data structure to the Pine Script community.
"Object" allows Pine coders to finally create objects full or unique key:value pairs, which are converted to strings and stored in an array. Data can be stored and accessed using dedicated get and set methods.
The workflow is simple, but has a few nuances:
0. Import this library into your project; you can give it whatever alias you'd like (I'll be using obj)
1. Create your first object using the obj.new() method and assign it a variable or "ID".
2. Use the object's ID as the first argument into the obj.set() method, for the key and value there's one extra step required. They must be added as arguments to the appropriate prop_() method.
Note: While objects in this library technically only store data as strings, any primitive data type can be converted to a string before being stored, meaning that one object can hold data from multiple types at once. There's a trade off though..Pine Script requires that all exported function parameters have pre-defined types, meaning that as convenient as it would be to have a single method for storing and returning data of every type, it's not currently possible. Instead there are functions to add properties for each individual type, which are then converted to strings automatically (the original type is flagged and stored along with the data). Furthermore, since switch/if statements can only return values of the same type, there must also be "get" methods which correspond with each type. Again, a single "get" method which auto-detects the returned value's type was the goal but it's just not currently possible. Instead each get method is only allowed to return a value of its own type. No worries though, all the "get" methods will throw errors if they can't access the data you're trying to access. In that error message, you'll be informed exactly which "get" method you need to use if you ever lose track of what type of data you should be returning.
3. The second argument for obj.set() method is the obj.prop_() method. You just plug in your key as a string and your value and you're done. Easy as that.
Please do not skip this step, properties must be formatted correctly for data to be stored and accessed correctly
4. Obj.get_ (s: string, f: float, b: bool, i: int) methods are even easier, just choose whichever method will return the data type you need, then plug in your ID, and key and that's it. Objects will output data of the same type they were stored as!
There's a short example at the end of the script if you'd like to see more!
prop_string(string: key, string: value)
returns property formatted to string and flagged as string type
prop_float(string: key, float: value)
returns property formatted to string and flagged as float type
prop_bool(string: key, bool: value)
returns property formatted to string and flagged as bool type
prop_int(string: key, int: value)
returns property formatted to string and flagged as int type
Support for lines and shapes coming soon!
new()
returns an empty object
set(string : ID, string: property)
adds new property to object
get_f(string : ID, string: key)
returns float values
get_s(string : ID, string: key)
returns string values
get_b(string : ID, string: key)
returns boolean values
get_i(string : ID, string: key)
returns int values
More methods like Obj.remove(), Obj.size(), Obj.fromString, Obj.fromArray, Obj.toJSON, Obj.keys, & Obj.values coming very soon!!
arraysLibrary "arrays"
Library contains utility functions using arrays.
delete( arr , index)
remove an item from array at specific index. Also deletes the item
Parameters:
arr: - array from which the item needs to be deleted
index: - index of item to be deleted
Returns: void
pop( arr )
remove the last item from array. Also deletes the item
Parameters:
arr: - array from which the last item needs to be removed and deleted
Returns: void
shift( arr )
remove an item from array at index 0. Also deletes the item
Parameters:
arr: - array from which the first item needs to be removed and deleted
Returns: void
unshift( arr , val, maxItems)
add an item to the beginning of an array with max items cap
Parameters:
arr: - array to which the item needs to be added at the beginning
val: - value of item which needs to be added
maxItems: - max items array can hold. After that, items are removed from the other end
Returns: resulting array
clear( arr )
remove and delete all items in an array
Parameters:
arr: - array which needs to be cleared
Returns: void
push( arr , val, maxItems)
add an item to the end of an array with max items cap
Parameters:
arr: - array to which the item needs to be added at the beginning
val: - value of item which needs to be added
maxItems: - max items array can hold. After that, items are removed from the starting index
Returns: resulting array
HarmonicCalculation█ OVERVIEW
This library is complementary for XABCD Harmonic Pattern Custom Range Interactive
PriceDiff()
: Price Difference
Parameters:
: : price_1, price_2
Returns: : PriceDiff
TimeDiff()
: Time Difference
Parameters:
: : time_1, time_2
Returns: : TimeDiff
ReturnIndexOf3Arrays()
: Return Index Of 3 Arrays
Parameters:
: : id1, id2, id3, _int
Returns: : ReturnIndexOf3Arrays
AbsoluteRange()
: Price Difference
Parameters:
: : price, y, point
Returns: : AbsoluteRange
PriceAverage()
: To calculate average of 2 prices
Parameters:
: : price_1, price_2
Returns: : PriceAverage
TimeAverage()
: To calculate average of 2 times
Parameters:
: : time_1, time_2
Returns: : TimeAverage
StringBool()
: To show ratio in 3 decimals format
Parameters:
: : _value, _bool, _text
Returns: : StringBool
PricePercent()
: To show Price in percent format
Parameters:
: : _price, PriceRef, str_dir
Returns: : PricePercent
BoolCurrency()
: To show syminfo.currency
Parameters:
: : _bool
Returns: : BoolCurrency
RatioText()
: To show RatioText in 3 decimals format
Parameters:
: : _value, _text
Returns: : RatioText
RangeText()
: To display RangeText in Harmonic Range Format
Parameters:
: : _id1, _id2, _int, _text
Returns: : RangeText
PriceCurrency()
: To show Currency in Price Format
Parameters:
: : _bool, _value
Returns: : PriceCurrency