Exponential Bollinger Bands (EBB)This script is a variation of the popular Bollinger Bands indicator, which uses exponential moving averages (EMA) instead of simple moving averages (SMA) as its core calculation. The indicator is designed to provide a visual representation of volatility, with the distance between the upper and lower bands being determined by the standard deviation of the underlying data.
The script starts by defining a number of helper functions that are used to calculate the moving averages and standard deviations required for the indicator. The first helper function is sma(), which calculates the simple moving average of the input data over a specified length. This function uses linear interpolation to smooth the data when the length is not an integer. The stdev() function calculates the standard deviation of the input data using the simple moving average calculated by the sma() function.
The bes() function calculates the exponential moving average of the input data over a specified length. The estdev() function calculates the standard deviation of the input data using the exponential moving average calculated by the bes() function.
The estdev function calculates the standard deviation using an exponential moving average method, rather than the traditional simple moving average method used by the stdev function. The exponential moving average method gives more weight to recent data, which can make the estdev more responsive to recent changes in volatility. This can make it more useful in certain types of analysis, such as identifying trends in volatility. Additionally, it also uses the same EMA algorithm to calculate the average value of the data set, which can help to keep the output of the estdev and average functions consistent.
The script also defines two more helper functions, average() and standard_deviation(), which allow the user to switch between using simple moving averages (SMA) and exponential moving averages (EMA) as the basis for the indicator. These functions take three arguments, the input data, the length of the moving average, and a string that specifies whether to use SMA or EMA.
The script then defines the input parameters for the indicator. The user can choose whether to use SMA or EMA as the basis for the indicator using the select parameter. The user can also specify the length of the moving average and the multiplier for the standard deviation using the length and multiplier parameters, respectively.
Finally, the script calculates the average and standard deviation of the input data using the selected method (SMA or EMA), and plots the upper and lower bands of the indicator. The upper band is calculated as the average plus the standard deviation multiplied by the specified multiplier, while the lower band is calculated as the average minus the standard deviation multiplied by the specified multiplier.
Interpolation
InterpolationLibrary "Interpolation"
Functions for interpolating values. Can be useful in signal processing or applied as a sigmoid function.
linear(k, delta, offset, unbound) Returns the linear adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the line the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
quadIn(k, delta, offset, unbound) Returns the quadratic (easing-in) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
quadOut(k, delta, offset, unbound) Returns the quadratic (easing-out) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
quadInOut(k, delta, offset, unbound) Returns the quadratic (easing-in-out) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
cubicIn(k, delta, offset, unbound) Returns the cubic (easing-in) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
cubicOut(k, delta, offset, unbound) Returns the cubic (easing-out) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
cubicInOut(k, delta, offset, unbound) Returns the cubic (easing-in-out) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
expoIn(k, delta, offset, unbound) Returns the exponential (easing-in) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
expoOut(k, delta, offset, unbound) Returns the exponential (easing-out) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
expoInOut(k, delta, offset, unbound) Returns the exponential (easing-in-out) adjusted value.
Parameters:
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
using(fn, k, delta, offset, unbound) Returns the adjusted value by function name.
Parameters:
fn : The name of the function. Allowed values: linear, quadIn, quadOut, quadInOut, cubicIn, cubicOut, cubicInOut, expoIn, expoOut, expoInOut.
k : A number (float) from 0 to 1 representing where the on the curve the value is.
delta : The amount the value should change as k reaches 1.
offset : The start value.
unbound : When true, k values less than 0 or greater than 1 are still calculated. When false (default), k values less than 0 will return the offset value and values greater than 1 will return (offset + delta).
AnalysisInterpolationLoessLibrary "AnalysisInterpolationLoess"
LOESS, local weighted Smoothing function.
loess(sample_x, sample_y, point_span) LOESS, local weighted Smoothing function.
Parameters:
sample_x : int array, x values.
sample_y : float array, y values.
point_span : int, local point interval span.
aloess(sample_x, sample_y, point_span) aLOESS, adaptive local weighted Smoothing function.
Parameters:
sample_x : int array, x values.
sample_y : float array, y values.
point_span : int, local point interval span.
Example - HTF Step InterpolationAbout this script:
This example aims to highlight an alternative way to view HTF data by providing basic interpolation functionality.
This script does not aim to provide use in itself as an indicator or strategy.
Reason for study:
Educational Purposes Only