OPEN-SOURCE SCRIPT

Bollinger Bands + Keltner Channel Refurbished

Updated
█ Goals

This is an indicator that brings together Bollinger Bands and Keltner's Channels in one thing.
Both are very similar, so I decided to make a merge of the best features I found out there.
Here there is the possibility of choosing one of these two as needed.

In addition, I added the following resources:
1. Pre-Defined intermediate bands with Fibonacci values;
2. Detachment of the bands in which the price was present;
3. Choice of Moving Average:
"Simple", "Exponential", "Regularized Exponential", "Hull", "Arnaud Legoux", "Weighted Moving Average", "Least Squares Moving Average (Linear Regression)", "Volume Weighted Moving Average", "Smoothed Moving Average", "Median", "VWAP");
4. Statistics: bars count within the bands.


█ Concepts

Keltner Channels vs. Bollinger Bands

"These two indicators are quite similar.
Keltner Channels use ATR to calculate the upper and lower bands while Bollinger Bands use standard deviation instead.
The interpretation of the indicators is similar, although since the calculations are different the two indicators may provide slightly different information or trade signals."
(Investopedia)

Bollinger Bands (BB)

"Bollinger Bands (BB) are a widely popular technical analysis instrument created by John Bollinger in the early 1980’s.
Bollinger Bands consist of a band of three lines which are plotted in relation to security prices.
The line in the middle is usually a Simple Moving Average (SMA) set to a period of 20 days (the type of trend line and period can be changed by the trader; however a 20 day moving average is by far the most popular).
The SMA then serves as a base for the Upper and Lower Bands which are used as a way to measure volatility by observing the relationship between the Bands and price.
Typically the Upper and Lower Bands are set to two standard deviations away from the SMA (The Middle Line); however the number of standard deviations can also be adjusted by the trader."
(TradingView)

Keltner Channels (KC)

"The Keltner Channels (KC) indicator is a banded indicator similar to Bollinger Bands and Moving Average Envelopes.
They consist of an Upper Envelope above a Middle Line as well as a Lower Envelope below the Middle Line.
The Middle Line is a moving average of price over a user-defined time period.
Either a simple moving average or an exponential moving average are typically used. The Upper and Lower Envelopes (user defined) are set a range away from the Middle Line.
This can be a multiple of the daily high/low range, or more commonly a multiple of the Average True Range."
(TradingView)


█ Examples

Bollinger Bands with 200 REMA:
snapshot

Keltner Channel with 200 REMA:
snapshot

Bollinger Bands with 55 ALMA:
snapshot

Keltner Channel with 55 ALMA:
snapshot

Bollinger Bands with 55 Least Squares Moving Average:
snapshot


█ Thanks

- TradingView (BB, KC, ATR, MA's)
- everget (Regularized Exponential Moving Average)
- TimeFliesBuy ("Triple Bollinger Bands")
- Rashad ("Fibonacci Bollinger Bands")
- Dicargo_Beam ("Is the Bollinger Bands assumption wrong?")
Release Notes
Labels was too long
Release Notes
Following is correction of the error reported by the user @huratub.
The counting of the total number of bars within the Bollinger Bands was wrong, failing to count the first bar.
Below is an example of the bug and then the result after the correction.

Bug:
snapshot

After correction:
snapshot

Thanks
Release Notes
1. Standard Deviation for Bollinger Bands now can be calculated based on price (default), or based on central moving average.
In some cases this reduce noise.

2. Added new moving averages (thanks for MightyZinger and TV):

Rolling VWAP (thanks to TV)
Symmetrically Weighted Moving Average
Relative Moving Average
Triangular Simple Moving Average
Triangular Exponential Moving Average
Volatility Adjusted Moving Average
Zero Lag Simple Moving Average
Zero Lag Exponential Moving Average
Variable Index Dynamic Average
Fractal Adaptive Moving Average
Kaufman Adaptive Moving Average (KAMA)
Coefficient of Variation Weighted Moving Average (CVWMA)
Jurik Moving Average
Sine-Weighted Moving Average
Geometric Mean Moving Average
Welles Wilder Moving Average
Geometric Moving Average
Release Notes
Error Handling for VWAP and Rolling VWAP
Release Notes
- Added new moving averages via libraries (credits: CrackingCryptocurrency).
- Added ALMA (Arnaud Legoux Moving Averag) parameterization.
Release Notes
Added End Point Moving Average.
Thanks to Franklin Moormann (cheatcountry).
Release Notes
- Code optimized to use a unique library of moving averages.
- New moving averages available (for more information access the library at:
Moving Averages Proxy

- Added some unique parameters of certain averages.

- Updated list of moving averages:
AARMA = 'Adaptive Autonomous Recursive Moving Average'
ADEMA = '* Alpha-Decreasing Exponential Moving Average'
AHMA = 'Ahrens Moving Average'
ALMA = 'Arnaud Legoux Moving Average'
ALSMA = 'Adaptive Least Squares'
AUTOL = 'Auto-Line'
CMA = 'Corrective Moving average'
CORMA = 'Correlation Moving Average Price'
COVWEMA = 'Coefficient of Variation Weighted Exponential Moving Average'
COVWMA = 'Coefficient of Variation Weighted Moving Average'
DEMA = 'Double Exponential Moving Average'
DONCHIAN = 'Donchian Middle Channel'
EDMA = 'Exponentially Deviating Moving Average'
EDSMA = 'Ehlers Dynamic Smoothed Moving Average'
EFRAMA = '* Ehlrs Modified Fractal Adaptive Moving Average'
EHMA = 'Exponential Hull Moving Average'
EMA = 'Exponential Moving Average'
EPMA = 'End Point Moving Average'
ETMA = 'Exponential Triangular Moving Average'
EVWMA = 'Elastic Volume Weighted Moving Average'
FAME = 'Following Adaptive Moving Average'
FIBOWMA = 'Fibonacci Weighted Moving Average'
FISHLSMA = 'Fisher Least Squares Moving Average'
FRAMA = 'Fractal Adaptive Moving Average'
GMA = 'Geometric Moving Average'
HKAMA = 'Hilbert based Kaufman\'s Adaptive Moving Average'
HMA = 'Hull Moving Average'
JURIK = 'Jurik Moving Average'
KAMA = 'Kaufman\'s Adaptive Moving Average'
LC_LSMA = '1LC-LSMA (1 line code lsma with 3 functions)'
LEOMA = 'Leo Moving Average'
LINWMA = 'Linear Weighted Moving Average'
LSMA = 'Least Squares Moving Average'
MAMA = 'MESA Adaptive Moving Average'
MCMA = 'McNicholl Moving Average'
MEDIAN = 'Median'
REGMA = 'Regularized Exponential Moving Average'
REMA = 'Range EMA'
REPMA = 'Repulsion Moving Average'
RMA = 'Relative Moving Average'
RSIMA = 'RSI Moving average'
RVWAP = '* Rolling VWAP'
SMA = 'Simple Moving Average'
SMMA = 'Smoothed Moving Average'
SRWMA = 'Square Root Weighted Moving Average'
SW_MA = 'Sine-Weighted Moving Average'
SWMA = '*Symmetrically Weighted Moving Average'
THEME = 'Triple Exponential Moving Average'
THMA = 'Triple Hull Moving Average'
UMBRELLA = 'Triangular Exponential Moving Average'
TRSMA = 'Triangular Simple Moving Average'
TT3 = 'Tillson T3'
VAMA = 'Volatility Adjusted Moving Average'
VIDYA = 'Variable Index Dynamic Average'
VWAP = '*VWAP'
VWMA = 'Volume-weighted Moving Average'
WMA = 'Weighted Moving Average'
WWMA = 'Welles Wilder Moving Average'
XEMA = 'Optimized Exponential Moving Average'
ZEMA = 'Zero-Lag Exponential Moving Average'
ZSMA = 'Zero-Lag Simple Moving Average'
Release Notes
- New theme and colors.
- Option to quickly change the level of transparency of the background color of the bands.
- Option to change baseline color according to price position.

* I would like to add other color options, but due to the limited amount of inputs, it was left with shades of green and red.
If you prefer other colors I suggest making a copy of the script and manually changing the variables in the source code.
Release Notes
- Some internal lines were removed to make the script faster. In addition, the excess of lines leaves the graph polluted.
- Possibility to customize colors, background and lines.
Release Notes
- Removed unused parameters.
- For a reason I don't know, the Style tab doesn't save the parameters.
So now, to make it easier to hide certain bands, just enter zero.
Release Notes
🧾Summary:

1. Source code optimization to improve processing speed.
2. Default colors have been modified for better viewing.
3. Added the possibility to customize the horizontal position of the labels.
4. Added new indicator (band style): Parallel Channels.
5. Added new moving average (MA): 'Donchian Middle Channel High-Low Version'

🔎Details:

1. Parallel Channels:

The channels are obtained like this:

a) Capture the maximums and minimums
b) Calculate the respective averages
c) The final average is calculated, taking the amplitude between the top average and the bottom average, dividing by the parameterized divisor, and finally multiplying by the multiplier.

2. Donchian Channel

In the specific case of Donchian, it was decided to perform the calculation a little differently.
The average (base) is obtained in two ways.

In the standard way, the closing high is added to the closing low, and the result is divided by 2.
This is done using the 'Donchian Middle Channel' option.

The other way, which has just been added, is via the 'Donchian Middle Channel High-Low Version' option.
Here, the highs and lows are added (it's not the closing, it's the tip of the wick) and the result is divided by 2.

The two variants of Donchian Channel presented here differ from traditional Donchian.
In traditional Donchian, the chart is limited to just showing the base, plus an upper band (delimited by the high of the last N periods), plus the lower band (delimited by the low of the last N periods).

The improvement shown here in this indicator is that the Donchian is not limited to just an upper and lower band.
There are 3 possibilities: (1) standard deviation of Bollinger Bands, (2) Keltner channels, and the (3) newly added parallel channels.

What defines the location of the bands are the parameters in relation to the base, and not just the highs and lows.
Release Notes
❌ In the 1 second graph, the labels were appearing duplicated, due to a synchronization problem:
snapshot

✅ Problem fixed:
snapshot
Release Notes
Added VWAP standard deviation bands option.
Although these standard deviations are taken from the VWAP, the bands can be used with other averages as well.

snapshot

This allows using this indicator in the conventional way that the VWAP is used, but with the benefits included here.
Below is a comparison between the standard VWAP and the new indicator:
snapshot
ATRAverage True Range (ATR)bollinger_bandsBollinger Bands (BB)bollingersbandkeltnerchannelKeltner Channels (KC)keltnerchannelsbandsmoving_averagemoving_averages

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


To contribute to my work:
⚡Bitcoin Lightning: forwardocean64@walletofsatoshi.com
🟠Bitcoin: bc1qv0j28wjsg6l8fdkphkmgfz4f55xpph893q0pdh
🔵PayPal: paypal.com/donate/?hosted_button_id=D9KRKY5HMSL9S
Also on:

Disclaimer