na_skip_highestLibrary "na_skip_highest"
Finds the highest historic value over len bars but skip na valued bars (eg, off days). In other words, this will ensure we find the highest value over len bars with a real value, and if there are any na bars in-between, we skip over but the loop will continue. This allows to mimic calculations on markets with off days (eg, weekends).
na_skip_highest(src, len)
Finds the highest historic value over len bars but skip na valued bars (eg, off days). In other words, this will ensure we find the highest value over len bars with a real value, and if there are any na bars in-between, we skip over but the loop will continue. This allows to mimic calculations on markets with off days (eg, weekends).
Parameters:
src : series float source (eg, close)
len : int length, number of recent bars to consider in the window to find the highest value
Returns: highest float highest value found over the len window
MATH
KernelFunctionsLibrary "KernelFunctions"
This library provides non-repainting kernel functions for Nadaraya-Watson estimator implementations. This allows for easy substitution/comparison of different kernel functions for one another in indicators. Furthermore, kernels can easily be combined with other kernels to create newer, more customized kernels. Compared to Moving Averages (which are really just simple kernels themselves), these kernel functions are more adaptive and afford the user an unprecedented degree of customization and flexibility.
rationalQuadratic(_src, _lookback, _relativeWeight, _startAtBar)
Rational Quadratic Kernel - An infinite sum of Gaussian Kernels of different length scales.
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_relativeWeight : Relative weighting of time frames. Smaller values result in a more stretched-out curve, and larger values will result in a more wiggly curve. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Rational Quadratic Kernel.
gaussian(_src, _lookback, _startAtBar)
Gaussian Kernel - A weighted average of the source series. The weights are determined by the Radial Basis Function (RBF).
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Gaussian Kernel.
periodic(_src, _lookback, _period, _startAtBar)
Periodic Kernel - The periodic kernel (derived by David Mackay) allows one to model functions that repeat themselves exactly.
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_period : The distance between repititions of the function.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Periodic Kernel.
locallyPeriodic(_src, _lookback, _period, _startAtBar)
Locally Periodic Kernel - The locally periodic kernel is a periodic function that slowly varies with time. It is the product of the Periodic Kernel and the Gaussian Kernel.
Parameters:
_src : The source series.
_lookback : The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars.
_period : The distance between repititions of the function.
_startAtBar : Bar index on which to start regression. The first bars of a chart are often highly volatile, and omitting these initial bars often leads to a better overall fit.
Returns: yhat The estimated values according to the Locally Periodic Kernel.
ahpuhelperLibrary "ahpuhelper"
Helper Library for Auto Harmonic Patterns UltimateX. It is not meaningful for others. This is supposed to be private library. But, publishing it to make sure that I don't delete accidentally. Some functions may be useful for coders.
insert_open_trades_table_column(showOpenTrades, table_id, column, colors, values, intStatus, harmonicTrailingStartState, lblSizeOpenTrades)
add data to open trades table column
Parameters:
showOpenTrades : flag to show open trades table
table_id : Table Id
column : refers to pattern data
colors : backgroud and text color array
values : cell values
intStatus : status as integer
harmonicTrailingStartState : trailing Start state as per configs
lblSizeOpenTrades : text size
Returns: nextColumn
populate_closed_stats(ClosedStatsPosition, bullishCounts, bearishCounts, bullishRetouchCounts, bearishRetouchCounts, bullishSizeMatrix, bearishSizeMatrix, bullishRR, bearishRR, allPatternLabels, flags, rowMain, rowHeaders)
populate closed stats for harmonic patterns
Parameters:
ClosedStatsPosition : Table position for closed stats
bullishCounts : Matrix containing bullish trade stats
bearishCounts : Matrix containing bearish trade stats
bullishRetouchCounts : Matrix containing bullish trade stats for those which retouched entry
bearishRetouchCounts : Matrix containing bearish trade stats for those which retouched entry
bullishSizeMatrix : Matrix containing data about size of bullish patterns
bearishSizeMatrix : Matrix containing data about size of bearish patterns
bullishRR : Matrix containing Risk Reward data of bullish patterns
bearishRR : Matrix containing Risk Reward data of bearish patterns
allPatternLabels : array containing pattern labels
flags : display flags
rowMain : Pattern header data
rowHeaders : header grouping data
Returns: void
get_rr_details(patternTradeDetails, harmonicTrailingStartState, disableTrail, breakEvenTrail)
calculate and return risk reward based on targets and stops
Parameters:
patternTradeDetails : array containing stop, entry and targets
harmonicTrailingStartState : trailing point
disableTrail : If set, ignores trailing point
breakEvenTrail : If set, trailing does not go beyond breakeven.
Returns: nextColumn
fastlog2Library "fastlog2"
Description:
Returns the approximation of Log2 with the maximal error of: 0.000061011436
Reference:
www.anycodings.com
fastlog2(x)
Returns the approximation of Log2 with the maximal error of: 0.000061011436
Parameters:
x : float
Returns: float, log2 of x
combinLibrary "combin"
Description:
The combin function is a the combination function
as it calculates the number of possible combinations for two given numbers.
This function takes two arguments: the number and the number_chosen.
For example, if the number is 5 and the number chosen is 1,
there are 5 combinations, giving 5 as a result.
Reference:
ideone.com
support.microsoft.com
combin(n, kin)
Returns the number of combinations for a given number of items. Use to determine the total possible number of groups for a given number of items.
Parameters:
n : int, The number of items.
kin : int, The number of items in each combination.
Returns: int.
FibonacciLibrary "Fibonacci"
General Fibonacci functions. Get fib numbers, ratios, etc.
fib_precise(f, precision)
Get the precise Fibonacci ratio, to the specified number of decimal places
Parameters:
f : Fibonacci ratio (string, in form #.###)
precision : Number of decimal places (optional int, dft = 16, max = 32)
Returns: Precise Fibonacci ratio (float)
fib_n(n)
Calculate the Nth number in the Fibonacci sequence
Parameters:
n : Index/number in sequence (int)
Returns: Fibonacci number (int)
TrigLibrary "Trig"
Trigonometric functions
rt_get_angleAlpha(a, b, c, deg)
Get angle α of a right triangle, given the lengths of its sides
Parameters:
a : length of leg a (float)
b : length of leg b (float)
c : length of hypotenuse (float)
deg : flag to return angle in degrees (bool - default = false)
Returns: angle α in radians (or degrees if deg == true)
rt_get_angleAlphaFromLine(x1, y1, x2, y2, l, deg)
Get angle α of a right triangle formed by the given line
Parameters:
x1 : x coordinate 1 (int - optional, required if argument l is not specified)
y1 : y coordinate 1 (float - optional, required if argument l is not specified)
x2 : x coordinate 2 (int - optional, required if argument l is not specified)
y2 : y coordinate 2 (float - optional, required if argument l is not specified)
l : line object (line - optional, required if x1, y1, x2, and y2 agruments are not specified)
deg : flag to return angle in degrees (bool - default = false)
Returns: angle α in radians (or degrees if deg == true)
rt_get_angleBeta(a, b, c, deg)
Get angle β of a right triangle, given the lengths of its sides
Parameters:
a : length of leg a (float)
b : length of leg b (float)
c : length of hypotenuse (float)
deg : flag to return angle in degrees (bool - default = false)
Returns: angle β in radians (or degrees if deg == true)
rt_get_angleBetaFromLine(x1, y1, x2, y2, l, deg)
Get angle β of a right triangle formed by the given line
Parameters:
x1 : x coordinate 1 (int - optional, required if argument l is not specified)
y1 : y coordinate 1 (float - optional, required if argument l is not specified)
x2 : x coordinate 2 (int - optional, required if argument l is not specified)
y2 : y coordinate 2 (float - optional, required if argument l is not specified)
l : line object (line - optional, required if x1, y1, x2, and y2 agruments are not specified)
deg : flag to return angle in degrees (bool - default = false)
Returns: angle β in radians (or degrees if deg == true)
AlgebraLibrary "Algebra"
Algebra functions.
line_fromXy(x1, y1, x2, y2)
Get line slope and y-intercept from coordinates
Parameters:
x1 : x coordinate 1 (int - bar index)
y1 : y coordinate 1 (float - price/value)
x2 : x coordinate 2 (int - bar index)
y2 : y coordinate 2 (float - price/value)
Returns: of line
line_getPrice(x, slope, yInt)
Get line slope and y-intercept from coordinates
Parameters:
x : x coordinate to solve for y (int - bar index)
slope : slope of line (float)
yInt : y-intercept of line (float)
Returns: y (price/value)
L_BetaLibrary "L_Beta"
TODO: add library description here
length()
beta()
simple_beta()
index_selector()
FunctionLAPACKdsyrkLibrary "FunctionLAPACKdsyrk"
subroutine part of LAPACK: Linear Algebra Package,
performs one of the symmetric rank k operations
.
C := alpha*A*A**T + beta*C, or C := alpha*A**T*A + beta*C,
.
where alpha and beta are scalars, C is an n by n symmetric matrix
and A is an n by k matrix in the first case and a k by n matrix
in the second case.
.
reference:
netlib.org
dsyrk(uplo, trans, n, k, alpha, a, lda, beta, c, ldc)
performs one of the symmetric rank k operations
.
C := alpha*A*A**T + beta*C, or C := alpha*A**T*A + beta*C,
.
where alpha and beta are scalars, C is an n by n symmetric matrix
and A is an n by k matrix in the first case and a k by n matrix
in the second case.
.
Parameters:
uplo : string specifies whether the upper or lower triangular part of
the array C is to be referenced as follows:
UPLO = 'U' or 'u' Only the upper triangular part of C is to be referenced.
UPLO = 'L' or 'l' Only the lower triangular part of C is to be referenced.
.
trans : string specifies the operation to be performed as follows:
TRANS = 'N' or 'n' C := alpha*A*A**T + beta*C.
TRANS = 'T' or 't' C := alpha*A**T*A + beta*C.
TRANS = 'C' or 'c' C := alpha*A**T*A + beta*C.
.
n : int specifies the order of the matrix C. N must be at least zero.
k : int On entry with:
TRANS = 'N' or 'n', K specifies the number of columns of the matrix A.
TRANS = 'T' or 't' or 'C' or 'c', K specifies the number of rows of the matrix A.
K must be at least zero.
.
alpha : float scalar.
a : matrix matrix A.
lda : int specifies the first dimension of A.
beta : float scalar.
c : matrix matrix C, is overwritten by the lower triangular part of the updated matrix.
ldc : int specifies the first dimension of C
Returns: void, C is overwritten by the lower triangular part of the updated matrix.
FunctionLAPACKdtrsmLibrary "FunctionLAPACKdtrsm"
subroutine in the LAPACK:linear algebra package, used to solve one of the following matrix equations:
op( A )*X = alpha*B, or X*op( A ) = alpha*B,
where alpha is a scalar, X and B are m by n matrices, A is a unit, or
non-unit, upper or lower triangular matrix and op( A ) is one of
op( A ) = A or op( A ) = A**T.
The matrix X is overwritten on B.
reference:
netlib.org
dtrsm(side, uplo, transa, diag, m, n, alpha, a, lda, b, ldb)
solves one of the matrix equations
op( A )*X = alpha*B, or X*op( A ) = alpha*B,
where alpha is a scalar, X and B are m by n matrices, A is a unit, or
non-unit, upper or lower triangular matrix and op( A ) is one of
op( A ) = A or op( A ) = A**T.
The matrix X is overwritten on B.
Parameters:
side : string , On entry, SIDE specifies whether op( A ) appears on the left or right of X as follows:
SIDE = 'L' or 'l' op( A )*X = alpha*B.
SIDE = 'R' or 'r' X*op( A ) = alpha*B.
uplo : string , specifies whether the matrix A is an upper or lower triangular matrix as follows:
UPLO = 'U' or 'u' A is an upper triangular matrix.
UPLO = 'L' or 'l' A is a lower triangular matrix.
transa : string , specifies the form of op( A ) to be used in the matrix multiplication as follows:
TRANSA = 'N' or 'n' op( A ) = A.
TRANSA = 'T' or 't' op( A ) = A**T.
TRANSA = 'C' or 'c' op( A ) = A**T.
diag : string , specifies whether or not A is unit triangular as follows:
DIAG = 'U' or 'u' A is assumed to be unit triangular.
DIAG = 'N' or 'n' A is not assumed to be unit triangular.
m : int , the number of rows of B. M must be at least zero.
n : int , the number of columns of B. N must be at least zero.
alpha : float , specifies the scalar alpha. When alpha is zero then A is not referenced and B need not be set before entry.
a : matrix, Triangular matrix.
lda : int , specifies the first dimension of A.
b : matrix, right-hand side matrix B, and on exit is overwritten by the solution matrix X.
ldb : int , specifies the first dimension of B.
Returns: void, modifies matrix b.
usage:
dtrsm ('L', 'U', 'N', 'N', 5, 3, 1.0, a, 7, b, 6)
BoxLine_LibLibrary "BoxLine_Lib"
personal Library for line and box built in functions
lineXY(x)
get x1,y1,x2,y2 in a tuple
Parameters:
x : TODO: line
Returns: tuple of x1,y1,x2,y2
line(x)
Create line with only the y1 value(when line == na) or all
when line != na set x1,y1,x2,y2 individually just 1 or all
- use just the line value to set the x2 to current bar or time will set to time
- will auto pick xloc.bar_index or xloc.bar_time if not used
Parameters:
x : (line line,int x1,float y1,int x2,float y2,
string xloc,string extend,color color,string style,int width)
Returns: Line
boxXY(x)
get left,top,right,bottom in a tuple
Parameters:
x : box
Returns: tuple of left,top,right,bottom
box(x)
Create line with only the top,bottom value(when line == na) or all
when box != na set left,top,right,bottom individually just 1 or all
- use just the box value to set the right to current bar or time will set to time
- if right is above a number that a bar_index wouldnt be
Parameters:
x : box box,int left,float top,int right,
float bottom,color border_color, int border_width,
string border_style,string extend,string xloc,
color bgcolor,string text,string text_size, color text_color,
string text_halign,string text_valign,string text_wrap)
Returns: TODO: Box
HelperFunctionsLibrary "HelperFunctions"
A collection of my most used functions
apply_smoothing()
Apply one of Pine Script's built-in smoothing functions to a series
calcLibrary "calc"
Library for math functions. will expand over time.
split(_sumTotal, _divideBy, _forceMinimum, _haltOnError)
Split a large number into integer sized chunks
Parameters:
_sumTotal : (int) Total numbert of items
_divideBy : (int) Groups to make
_forceMinimum : (bool) force minimum number 1/group
_haltOnError : (bool) force error if too few groups
Returns: int array of items per group
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
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()
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
Moving_AveragesLibrary "Moving_Averages"
This library contains majority important moving average functions with int series support. Which means that they can be used with variable length input. For conventional use, please use tradingview built-in ta functions for moving averages as they are more precise. I'll use functions in this library for my other scripts with dynamic length inputs.
ema(src, len)
Exponential Moving Average (EMA)
Parameters:
src : Source
len : Period
Returns: Exponential Moving Average with Series Int Support (EMA)
alma(src, len, a_offset, a_sigma)
Arnaud Legoux Moving Average (ALMA)
Parameters:
src : Source
len : Period
a_offset : Arnaud Legoux offset
a_sigma : Arnaud Legoux sigma
Returns: Arnaud Legoux Moving Average (ALMA)
covwema(src, len)
Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
Parameters:
src : Source
len : Period
Returns: Coefficient of Variation Weighted Exponential Moving Average (COVWEMA)
covwma(src, len)
Coefficient of Variation Weighted Moving Average (COVWMA)
Parameters:
src : Source
len : Period
Returns: Coefficient of Variation Weighted Moving Average (COVWMA)
dema(src, len)
DEMA - Double Exponential Moving Average
Parameters:
src : Source
len : Period
Returns: DEMA - Double Exponential Moving Average
edsma(src, len, ssfLength, ssfPoles)
EDSMA - Ehlers Deviation Scaled Moving Average
Parameters:
src : Source
len : Period
ssfLength : EDSMA - Super Smoother Filter Length
ssfPoles : EDSMA - Super Smoother Filter Poles
Returns: Ehlers Deviation Scaled Moving Average (EDSMA)
eframa(src, len, FC, SC)
Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
Parameters:
src : Source
len : Period
FC : Lower Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
SC : Upper Shift Limit for Ehlrs Modified Fractal Adaptive Moving Average
Returns: Ehlrs Modified Fractal Adaptive Moving Average (EFRAMA)
ehma(src, len)
EHMA - Exponential Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Exponential Hull Moving Average (EHMA)
etma(src, len)
Exponential Triangular Moving Average (ETMA)
Parameters:
src : Source
len : Period
Returns: Exponential Triangular Moving Average (ETMA)
frama(src, len)
Fractal Adaptive Moving Average (FRAMA)
Parameters:
src : Source
len : Period
Returns: Fractal Adaptive Moving Average (FRAMA)
hma(src, len)
HMA - Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Hull Moving Average (HMA)
jma(src, len, jurik_phase, jurik_power)
Jurik Moving Average - JMA
Parameters:
src : Source
len : Period
jurik_phase : Jurik (JMA) Only - Phase
jurik_power : Jurik (JMA) Only - Power
Returns: Jurik Moving Average (JMA)
kama(src, len, k_fastLength, k_slowLength)
Kaufman's Adaptive Moving Average (KAMA)
Parameters:
src : Source
len : Period
k_fastLength : Number of periods for the fastest exponential moving average
k_slowLength : Number of periods for the slowest exponential moving average
Returns: Kaufman's Adaptive Moving Average (KAMA)
kijun(_high, _low, len, kidiv)
Kijun v2
Parameters:
_high : High value of bar
_low : Low value of bar
len : Period
kidiv : Kijun MOD Divider
Returns: Kijun v2
lsma(src, len, offset)
LSMA/LRC - Least Squares Moving Average / Linear Regression Curve
Parameters:
src : Source
len : Period
offset : Offset
Returns: Least Squares Moving Average (LSMA)/ Linear Regression Curve (LRC)
mf(src, len, beta, feedback, z)
MF - Modular Filter
Parameters:
src : Source
len : Period
beta : Modular Filter, General Filter Only - Beta
feedback : Modular Filter Only - Feedback
z : Modular Filter Only - Feedback Weighting
Returns: Modular Filter (MF)
rma(src, len)
RMA - RSI Moving average
Parameters:
src : Source
len : Period
Returns: RSI Moving average (RMA)
sma(src, len)
SMA - Simple Moving Average
Parameters:
src : Source
len : Period
Returns: Simple Moving Average (SMA)
smma(src, len)
Smoothed Moving Average (SMMA)
Parameters:
src : Source
len : Period
Returns: Smoothed Moving Average (SMMA)
stma(src, len)
Simple Triangular Moving Average (STMA)
Parameters:
src : Source
len : Period
Returns: Simple Triangular Moving Average (STMA)
tema(src, len)
TEMA - Triple Exponential Moving Average
Parameters:
src : Source
len : Period
Returns: Triple Exponential Moving Average (TEMA)
thma(src, len)
THMA - Triple Hull Moving Average
Parameters:
src : Source
len : Period
Returns: Triple Hull Moving Average (THMA)
vama(src, len, volatility_lookback)
VAMA - Volatility Adjusted Moving Average
Parameters:
src : Source
len : Period
volatility_lookback : Volatility lookback length
Returns: Volatility Adjusted Moving Average (VAMA)
vidya(src, len)
Variable Index Dynamic Average (VIDYA)
Parameters:
src : Source
len : Period
Returns: Variable Index Dynamic Average (VIDYA)
vwma(src, len)
Volume-Weighted Moving Average (VWMA)
Parameters:
src : Source
len : Period
Returns: Volume-Weighted Moving Average (VWMA)
wma(src, len)
WMA - Weighted Moving Average
Parameters:
src : Source
len : Period
Returns: Weighted Moving Average (WMA)
zema(src, len)
Zero-Lag Exponential Moving Average (ZEMA)
Parameters:
src : Source
len : Period
Returns: Zero-Lag Exponential Moving Average (ZEMA)
zsma(src, len)
Zero-Lag Simple Moving Average (ZSMA)
Parameters:
src : Source
len : Period
Returns: Zero-Lag Simple Moving Average (ZSMA)
evwma(src, len)
EVWMA - Elastic Volume Weighted Moving Average
Parameters:
src : Source
len : Period
Returns: Elastic Volume Weighted Moving Average (EVWMA)
tt3(src, len, a1_t3)
Tillson T3
Parameters:
src : Source
len : Period
a1_t3 : Tillson T3 Volume Factor
Returns: Tillson T3
gma(src, len)
GMA - Geometric Moving Average
Parameters:
src : Source
len : Period
Returns: Geometric Moving Average (GMA)
wwma(src, len)
WWMA - Welles Wilder Moving Average
Parameters:
src : Source
len : Period
Returns: Welles Wilder Moving Average (WWMA)
ama(src, _high, _low, len, ama_f_length, ama_s_length)
AMA - Adjusted Moving Average
Parameters:
src : Source
_high : High value of bar
_low : Low value of bar
len : Period
ama_f_length : Fast EMA Length
ama_s_length : Slow EMA Length
Returns: Adjusted Moving Average (AMA)
cma(src, len)
Corrective Moving average (CMA)
Parameters:
src : Source
len : Period
Returns: Corrective Moving average (CMA)
gmma(src, len)
Geometric Mean Moving Average (GMMA)
Parameters:
src : Source
len : Period
Returns: Geometric Mean Moving Average (GMMA)
ealf(src, len, LAPercLen_, FPerc_)
Ehler's Adaptive Laguerre filter (EALF)
Parameters:
src : Source
len : Period
LAPercLen_ : Median Length
FPerc_ : Median Percentage
Returns: Ehler's Adaptive Laguerre filter (EALF)
elf(src, len, LAPercLen_, FPerc_)
ELF - Ehler's Laguerre filter
Parameters:
src : Source
len : Period
LAPercLen_ : Median Length
FPerc_ : Median Percentage
Returns: Ehler's Laguerre Filter (ELF)
edma(src, len)
Exponentially Deviating Moving Average (MZ EDMA)
Parameters:
src : Source
len : Period
Returns: Exponentially Deviating Moving Average (MZ EDMA)
pnr(src, len, rank_inter_Perc_)
PNR - percentile nearest rank
Parameters:
src : Source
len : Period
rank_inter_Perc_ : Rank and Interpolation Percentage
Returns: Percentile Nearest Rank (PNR)
pli(src, len, rank_inter_Perc_)
PLI - Percentile Linear Interpolation
Parameters:
src : Source
len : Period
rank_inter_Perc_ : Rank and Interpolation Percentage
Returns: Percentile Linear Interpolation (PLI)
rema(src, len)
Range EMA (REMA)
Parameters:
src : Source
len : Period
Returns: Range EMA (REMA)
sw_ma(src, len)
Sine-Weighted Moving Average (SW-MA)
Parameters:
src : Source
len : Period
Returns: Sine-Weighted Moving Average (SW-MA)
vwap(src, len)
Volume Weighted Average Price (VWAP)
Parameters:
src : Source
len : Period
Returns: Volume Weighted Average Price (VWAP)
mama(src, len)
MAMA - MESA Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: MESA Adaptive Moving Average (MAMA)
fama(src, len)
FAMA - Following Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: Following Adaptive Moving Average (FAMA)
hkama(src, len)
HKAMA - Hilbert based Kaufman's Adaptive Moving Average
Parameters:
src : Source
len : Period
Returns: Hilbert based Kaufman's Adaptive Moving Average (HKAMA)
Price Displacement - Candlestick (OHLC) CalculationsA Magical little helper friend for Candle Math.
When composing scripts, it is often necessary to manipulate the math around the OHLC. At times, you want a scalar (absolute) value others you want a vector (+/-). Sometimes you want the open - close and sometimes you want just the positive number of the body size. You might want it in ticks or you might want it in points or you might want in percentages. And every time you try to put it together you waste precious time and brain power trying to think about how to properly structure what you're looking for. Not to mention it's normally not that aesthetically pleasing to look at in the code.
So, this fixes all of that.
Using this library. A function like 'pd.pt(_exp)' can call any kind of candlestick math you need. The function returns the candlestick math you define using particular expressions.
Candle Math Functions Include:
Points:
pt(_exp) Absolute Point Displacement. Point quantity of given size parameters according to _exp.
vpt(_exp) Vector Point Displacement. Point quantity of given size parameters according to _exp.
Ticks:
tick(_exp) Absolute Tick Displacement. Tick quantity of given size parameters according to _exp.
vtick(_exp) Vector Tick Displacement. Tick quantity of given size parameters according to _exp.
Percentages:
pct(_exp, _prec) Absolute Percent Displacement. (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
vpct(_exp, _prec) Vector Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Expressions You Can Use with Formulas:
The expressions are simple (simple strings that is) and I did my best to make them sensible, generally using just the ohlc abreviations. I also included uw, lw, bd, and rg for when you're just trying to pull a candle component out. That way you don't have to think about which of the ohlc you're trying to get just use pd.tick("uw") and now the variable is assigned the length of the upper wick, absolute value, in ticks. If you wanted the vector in pts its pd.vpt("uw"). It also makes changing things easy too as I write it out.
Expression List:
Combinations
"oh" = open - high
"ol" = open - low
"oc" = open - close
"ho" = high - open
"hl" = high - low
"hc" = high - close
"lo" = low - open
"lh" = low - high
"lc" = low - close
"co" = close - open
"ch" = close - high
"cl" = close - low
Candle Components
"uw" = Upper Wick
"bd" = Body
"lw" = Lower Wick
"rg" = Range
Pct() Only
"scp" = Scalar Close Position
"sop" = Scalar Open Position
"vcp" = Vector Close Position
"vop" = Vector Open Position
The attributes are going to be available in the pop up dialogue when you mouse over the function, so you don't really have to remember them. I tried to make that look as efficient as possible. You'll notice it follows the OHLC pattern. Thus, "oh" precedes "ho" (heyo) because "O" would be first in the OHLC. Its a way to help find the expression you're looking for quickly. Like looking through an alphabetized list for traders.
There is a copy/paste console friendly helper list in the script itself.
Additional Notes on the Pct() Only functions:
This is the original reason I started writing this. These concepts place a rating/value on the bar based on candle attributes in one number. These formulas put a open or close value in a percentile of the bar relative to another aspect of the bar.
Scalar - Non-directional. Absolute Value.
Scalar Position: The position of the price attribute relative to the scale of the bar range (high - low)
Example: high = 100. low = 0. close = 25.
(A) Measure price distance C-L. How high above the low did the candle close (e.g. close - low = 25)
(B) Divide by bar range (high - low). 25 / (100 - 0) = .25
Explaination: The candle closed at the 25th percentile of the bar range given the bar range low = 0 and bar range high = 100.
Formula: scp = (close - low) / (high - low)
Vector = Directional.
Vector Position: The position of the price attribute relative to the scale of the bar midpoint (Vector Position at hl2 = 0)
Example: high = 100. low = 0. close = 25.
(A) Measure Price distance C-L: How high above the low did the candle close (e.g. close - low = 25)
(B) Measure Price distance H-C: How far below the high did the candle close (e.g. high - close = 75)
(C) Take Difference: A - B = C = -50
(D) Divide by bar range (high - low). -50 / (100 - 0) = -0.50
Explaination: Candle close at the midpoint between hl2 and the low.
Formula: vcp = { / (high - low) }
Thank you for checking this out. I hope no one else has already done this (because it took half the day) and I hope you find value in it. Be well. Trade well.
Library "PD"
Price Displacement
pt(_exp) Absolute Point Displacement. Point quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Point size of given expression as an absolute value.
vpt(_exp) Vector Point Displacement. Point quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Point size of given expression as a vector.
tick(_exp) Absolute Tick Displacement. Tick quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Tick size of given expression as an absolute value.
vtick(_exp) Vector Tick Displacement. Tick quantity of given size parameters according to _exp.
Parameters:
_exp : (string) Price Parameter
Returns: Tick size of given expression as a vector.
pct(_exp, _prec) Absolute Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Parameters:
_exp : (string) Expression
_prec : (int) Overload - Place value precision definition
Returns: Percent size of given expression as decimal.
vpct(_exp, _prec) Vector Percent Displacement (w/rounding overload). Percent quantity of bar range of given size parameters according to _exp.
Parameters:
_exp : (string) Expression
_prec : (int) Overload - Place value precision definition
Returns: Percent size of given expression as decimal.
Strategy Table LibraryLibrary "table_library"
TODO: With this library, you can add tables to your strategies.
strategy_table()
Returns: Strategy Profit Table
Adds a table to the graph of the strategy for which you are calling the function. You can see data such as net profit in this table.
No parameters. Just call the function inside the strategy.
Example Code :
import only_fibonacci/table_lib/1 as st
st.strategy_table()
AutoFiboRetraceLibrary "AutoFiboRetrace"
TODO: add library description here
fun(x) TODO: add function description here
Parameters:
x : TODO: add parameter x description here
Returns: TODO: add what function returns
honest personal libraryLibrary "honestpersonallibrary"
thestratnumber() this will return the number 1,2 or 3 using the logic from Rob Smiths #thestrat which uses these type of bars for setups
getBodySize() Gets the current candle's body size (in POINTS, divide by 10 to get pips)
Returns: The current candle's body size in POINTS
getTopWickSize() Gets the current candle's top wick size (in POINTS, divide by 10 to get pips)
Returns: The current candle's top wick size in POINTS
getBottomWickSize() Gets the current candle's bottom wick size (in POINTS, divide by 10 to get pips)
Returns: The current candle's bottom wick size in POINTS
getBodyPercent() Gets the current candle's body size as a percentage of its entire size including its wicks
Returns: The current candle's body size percentage
strictBearPinBar(float, float) This it to find pinbars with a very long wick compared to the body that are bearish
Parameters:
float : minTopMulitplier (default=4) The minimum number of times that the top wick has to be bigger than the candle body size
float : maxBottomMultiplier (default=2) The maximum number of times that the bottom wick can be bigger than the candle body size
Returns: a bool function true if current candle is withing the parameters
strictBullPinBar(float, float) This it to find pinbars with a very long wick compared to the body that are bearish
Parameters:
float : minTopMulitplier (default=4) The minimum number of times that the top wick has to be bigger than the candle body size
float : maxBottomMultiplier (default=2) The maximum number of times that the bottom wick can be bigger than the candle body size
Returns: a bool function true if current candle is withing the parameters
FunctionIntrabarCrossValueLibrary "FunctionIntrabarCrossValue"
intrabar_cross_value(a, b, step) Find the minimum difference of a intrabar cross and return its median value.
Parameters:
a : float, series a.
b : float, series b.
step : float, step to iterate x axis, default=0.01
Returns: float