OPEN-SOURCE SCRIPT

MTF BB+KC Avg


Bollinger Bands (BB) are a widely used technical analysis created by John Bollinger in the early 1980’s. Bollinger Bands consist of a band of three lines which are plotted in relation to instrument 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). This indicator does not plot the middle line. The Upper and Lower Bands 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 middle line, however the number of standard deviations can also be adjusted in the indicator.

Keltner Channels (KC) are banded lines similar to Bollinger Bands and Moving Average Envelopes. They consist of an Upper Envelope above a Middle Line (not plotted in this indicator) 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 are set a (user-defined multiple) of 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.

This indicator is built on AVERAGING the BB and KC values for each bar, so you have an efficient metric of AVERAGE volatility. The indicator visualizes changes in volatility which is of course dynamic.

What to look for
High/Low Prices
One thing that must be understood about this indicator's plots is that it averages by adding BB levels to KC levels and dividing by 2. So the plots provide a relative definition of high and low from two very popular indicators. Prices are almost always within the upper and lower bands. Therefore, when prices move up near the upper or lower bands or even break through the band, many traders would see that price action as OVER-EXTENDED (either overbought or oversold, as applicable). This would preset a possible selling or buying opportunity.

Cycling Between Expansion and Contraction
Volatility can generally be seen as a cycle. Typically periods of time with low volatility and steady or sideways prices (known as contraction) are followed by period of expansion. Expansion is a period of time characterized by high volatility and moving prices. Periods of expansion are then generally followed by periods of contraction. It is a cycle in which traders can be better prepared to navigate by using Bollinger Bands because of the indicators ability to monitor ever changing volatility.

Walking the Bands
Of course, just like with any indicator, there are exceptions to every rule and plenty of examples where what is expected to happen, does not happen. Previously, it was mentioned that price breaking above the Upper Band or breaking below the Lower band could signify a selling or buying opportunity respectively. However this is not always the case. “Walking the Bands” can occur in either a strong uptrend or a strong downtrend.

During a strong uptrend, there may be repeated instances of price touching or breaking through the Upper Band. Each time that this occurs, it is not a sell signal, it is a result of the overall strength of the move. Likewise during a strong downtrend there may be repeated instances of price touching or breaking through the Lower Band. Each time that this occurs, it is not a buy signal, it is a result of the overall strength of the move.

Keep in mind that instances of “Walking the Bands” will only occur in strong, defined uptrends or downtrends.

Inputs

TimeFrame
You can select any timeframe froom 1 minute to 12 months for the bar measured.

Length of the internal moving averages
You can select the period of time to be used in calculating the moving averages which create the base for the Upper and Lower Bands. 20 days is the default.

Basis MA Type

Determines the type of Moving Average that is applied to the basis plot line. Default is SMA and you can select EMA.

Source
Determines what data from each bar will be used in calculations. Close is the default.

StdDev/Multiplier
The number of Standard Deviations (for BB) or Multiplier (for KC) away from the moving averages that the Upper and Lower Bands should be. 2 is the default value for each indicator.


Bands and Channelsbollinger_bandsbollingersbandkeltnerchannelkeltnerchannelsbandsVolatility

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?

Disclaimer