TradingView
peacefulLizard50262
20 Jan 2023 pukul 08.31

Exponential Bollinger Bands (EBB) 

Deskripsi

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.
Komentar
chervolino
This script describes a variation of the Bollinger Bands indicator that uses exponential moving averages (EMA) instead of simple moving averages (SMA) as its core calculation. The script defines several helper functions that are used to calculate the moving averages and standard deviations required for the indicator. The script also allows the user to switch between using SMA and EMA as the basis for the indicator and allows the user to specify the length of the moving average and the multiplier for the standard deviation. However, this information is already well-known and it does not contain any new information. What exactly is it useful for?
peacefulLizard50262
@chervolino, the sma is interpolated and the sum of the square differences are calculated using the exponential sum instead of the simple sum. This is the major difference.
peacefulLizard50262
@chervolino, "alpha * math.pow(source-average, 2) + (1 - alpha) * nz(smoothed[1])"
" if length % 1 != 0
sma = (sum - sum[int(length)] + (i.linear(length % 1, sum[int(length)] - sum[int(length)+1], 0, false)))/length"
For example
chervolino
@peacefulLizard50262, And what exactly is the advantage now?
peacefulLizard50262
@chervolino, It is way more responsive than any other deviation band Ive tried. Ive tried to modify the sum to use other styles to take the idea of matching the sum and average styles to the next level but this is the only one that works properly as far as I can tell. Also if you want to use a dynamic length on a simple moving average you have to interpolate it. This is both interpolated sma and stdev. You dont need interpolation with the ema.
peacefulLizard50262
@chervolino, also keep in mind Im a hobbiest. I am loving the feed back.
Lebih lanjut