MathHelpersLibrary "MathHelpers"
Overview
A collection of helper functions for designing indicators and strategies.
calculateATR(length, log)
Calculates the Average True Range (ATR) or Log ATR based on the 'log' parameter. Sans Wilder's Smoothing
Parameters:
length (simple int)
log (simple bool)
Returns: float The calculated ATR value. Returns Log ATR if `log` is true, otherwise returns standard ATR.
CDF(z)
Computes the Cumulative Distribution Function (CDF) for a given value 'z', mimicking the CDF function in "Statistically Sound Indicators" by Timothy Masters.
Parameters:
z (simple float)
Returns: float The CDF value corresponding to the input `z`, ranging between 0 and 1.
logReturns(lookback)
Calculates the logarithmic returns over a specified lookback period.
Parameters:
lookback (simple int)
Returns: float The calculated logarithmic return. Returns `na` if insufficient data is available.
Mathematics
Mad_MATHLibrary "MAD_MATH"
This is a mathematical library where I store useful kernels, filters and selectors for the different types of computations.
This library also contains opensource code from other scripters.
Future extensions are very likely, there are some functions I would like to add, but I have to wait for approvals so i can include them.
Ehlers_EMA(_src, _length)
Calculates the Ehlers Exponential Moving Average (Ehlers_EMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers EMA
Returns: The Ehlers EMA value
Ehlers_Gaussian(_src, _length)
Calculates the Ehlers Gaussian Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Gaussian Filter
Returns: The Ehlers Gaussian Filter value
Ehlers_supersmoother(_src, _length)
Calculates the Ehlers Supersmoother
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Supersmoother
Returns: The Ehlers Supersmoother value
Ehlers_SMA_fast(_src, _length)
Calculates the Ehlers Simple Moving Average (SMA) Fast
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers SMA Fast
Returns: The Ehlers SMA Fast value
Ehlers_EMA_fast(_src, _length)
Calculates the Ehlers Exponential Moving Average (EMA) Fast
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers EMA Fast
Returns: The Ehlers EMA Fast value
Ehlers_RSI_fast(_src, _length)
Calculates the Ehlers Relative Strength Index (RSI) Fast
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers RSI Fast
Returns: The Ehlers RSI Fast value
Ehlers_Band_Pass_Filter(_src, _length)
Calculates the Ehlers BandPass Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers BandPass Filter
Returns: The Ehlers BandPass Filter value
Ehlers_Butterworth(_src, _length)
Calculates the Ehlers Butterworth Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Butterworth Filter
Returns: The Ehlers Butterworth Filter value
Ehlers_Two_Pole_Gaussian_Filter(_src, _length)
Calculates the Ehlers Two-Pole Gaussian Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Two-Pole Gaussian Filter
Returns: The Ehlers Two-Pole Gaussian Filter value
Ehlers_Two_Pole_Butterworth_Filter(_src, _length)
Calculates the Ehlers Two-Pole Butterworth Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Two-Pole Butterworth Filter
Returns: The Ehlers Two-Pole Butterworth Filter value
Ehlers_Band_Stop_Filter(_src, _length)
Calculates the Ehlers Band Stop Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Band Stop Filter
Returns: The Ehlers Band Stop Filter value
Ehlers_Smoother(_src)
Calculates the Ehlers Smoother
Parameters:
_src (float) : The source series for calculation
Returns: The Ehlers Smoother value
Ehlers_High_Pass_Filter(_src, _length)
Calculates the Ehlers High Pass Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers High Pass Filter
Returns: The Ehlers High Pass Filter value
Ehlers_2_Pole_High_Pass_Filter(_src, _length)
Calculates the Ehlers Two-Pole High Pass Filter
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the Ehlers Two-Pole High Pass Filter
Returns: The Ehlers Two-Pole High Pass Filter value
pr(_src, _length)
pr Calculates the percentage rank (PR) of a value within a range.
Parameters:
_src (float) : The source value for which the percentage rank is calculated. It represents the value to be ranked within the range.
_length (simple int) : The _length of the range over which the percentage rank is calculated. It determines the number of bars considered for the calculation.
Returns: The percentage rank (PR) of the source value within the range, adjusted by adding 50 to the result.
smma(_src, _length)
Calculates the SMMA (Smoothed Moving Average)
Parameters:
_src (float) : The source series for calculation
_length (simple int)
Returns: The SMMA value
hullma(_src, _length)
Calculates the Hull Moving Average (HullMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the HullMA
Returns: The HullMA value
tma(_src, _length)
Calculates the Triple Moving Average (TMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the TMA
Returns: The TMA value
dema(_src, _length)
Calculates the Double Exponential Moving Average (DEMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the DEMA
Returns: The DEMA value
tema(_src, _length)
Calculates the Triple Exponential Moving Average (TEMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the TEMA
Returns: The TEMA value
w2ma(_src, _length)
Calculates the Normalized Double Moving Average (N2MA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the N2MA
Returns: The N2MA value
wma(_src, _length)
Calculates the Normalized Moving Average (NMA)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The _length of the NMA
Returns: The NMA value
nma(_open, _close, _length)
Calculates the Normalized Moving Average (NMA)
Parameters:
_open (float) : The open price series
_close (float) : The close price series
_length (simple int) : The _length for finding the highest and lowest values
Returns: The NMA value
lma(_src, _length)
Parameters:
_src (float)
_length (simple int)
zero_lag(_src, _length, gamma1, zl)
Calculates the Zero Lag Moving Average (ZeroLag)
Parameters:
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average
gamma1 (simple int) : The coefficient for calculating 'd'
zl (simple bool) : Boolean flag for applying Zero Lag
Returns: An array containing the ZeroLag Moving Average and a boolean flag indicating if it's flat
copyright HPotter, thanks for that great function
chebyshevI(src, len, ripple)
Calculates the Chebyshev Type I Filter
Parameters:
src (float) : The source series for calculation
len (int) : The length of the filter
ripple (float) : The ripple factor for the filter
Returns: The output of the Chebyshev Type I Filter
math from Pafnuti Lwowitsch Tschebyschow (1821–1894)
Thanks peacefulLizard50262 for the find and translation
chebyshevII(src, len, ripple)
Calculates the Chebyshev Type II Filter
Parameters:
src (float) : The source series for calculation
len (int) : The length of the filter
ripple (float) : The ripple factor for the filter
Returns: The output of the Chebyshev Type II Filter
math from Pafnuti Lwowitsch Tschebyschow (1821–1894)
Thanks peacefulLizard50262 for the find
wavetrend(_src, _n1, _n2)
Calculates the WaveTrend indicator
Parameters:
_src (float) : The source series for calculation
_n1 (simple int) : The period for the first EMA calculation
_n2 (simple int) : The period for the second EMA calculation
Returns: The WaveTrend value
f_getma(_type, _src, _length, ripple)
Calculates various types of moving averages
Parameters:
_type (simple string) : The type of indicator to calculate
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average or indicator
ripple (simple float)
Returns: The calculated moving average or indicator value
f_getfilter(_type, _src, _length)
Calculates various types of filters
Parameters:
_type (simple string) : The type of indicator to calculate
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average or indicator
Returns: The filtered value
f_getoszillator(_type, _src, _length)
Calculates various types of Deviations and other indicators
Parameters:
_type (simple string) : The type of indicator to calculate
_src (float) : The source series for calculation
_length (simple int) : The length for the moving average or indicator
Returns: The calculated moving average or indicator value
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
LibraryPrivateUsage001This is a public library that include the functions explained below. The libraries are considered public domain code and permission is not required from the author if you reuse these functions in your open-source scripts