+ BB %B: MA selection, bar coloring, multi-timeframe, and alerts

However, the right combination of bells and whistles will often improve and make a more adaptable indicator.
Classically, Bollinger Bands %B is an indicator that measures volatility, and the momentum and strength of a trend, and/or price movements.
It shows "overbought" and "oversold" spots on a chart, and is also useful for identifying divergences between price and trend (similar to RSI).
With + %B I've added the options to select one or two moving averages, candle coloring, and a host of others.
Let's start with the moving averages:
There are options for two: one faster and one slower. Or combine them how you will, or omit one or both of them entirely.
Here you will find options for SMA, EMA (as well as double and triple), Hull MA, Jurik MA, Least Squares MA, Triangular MA, Volatility Adjusted MA, and Weighted MA.
A moving average essentially helps to define trend by smoothing the noise of movements of the underlying asset, or, in this case, the output of the indicator.
All of these MAs available track this in a different way, and it's up to the trader to figure out which makes most sense to him/her.
MA's, in my opinion, improve the basic %B by providing a clearer picture of what the indicator is actually "seeing", and may be useful for providing entries and exits.
Next up is candle coloring:
I've added the option for this indicator to color candles on the chart based on where the %B is in relation to its upper and lower bounds, and median line.
If the %B is above the median but below the upper bound, candles will be green (showing bullish market structure). If %B is below the median but above the lower bound, candles will be red (denoting bearish market structure).
Overbought and oversold candles will also be colored on the chart, so that a quick glance will tell you whether price action is bullish/bearish or "oversold"/"overbought".
I've also added functionality that enables candles to be colored based on if the %B has crossed up or crossed down the primary moving average.
One example as a way to potentially use these features is if the candles are showing oversold coloration followed by the %B crossing up your moving average coloration. You might consider a long there (or exit a short position if you are short).
And the last couple of tweaks:
You may set the timeframe to whatever you wish, so maybe you're trading on the hourly, but you want to know where the %B is on the 4h chart. You can do that.
The background fill for the indicator is split into bullish and bearish halves. Obviously you may turn the background off, or make it all one color as well.
I've also added alerts, so you may set alerts for "overbought" and "oversold" conditions.
You may also set alerts for %B crossing over or under the primary moving average, or for crossing the median line.
All of these things may be turned on and off. You can pretty much customize this to your heart's delight. I see no reason why anyone would use the standard %B after playing with this.
I am no coder. I had this idea in my head, though, and I made it happen through referencing another indicator I was familiar with, and watching tutorials on YouTube.
Credits:
Firstly, thanks to tradingview.com/u/ZenAndTheArtOfTrading/ for his brilliant, free tutorials on YouTube.
Secondly, thanks to tradingview.com/u/Mihkel00/ for his beautiful SSL Hybrid indicator (and his clean code) from which I obtained the MAs.
Please enjoy this indicator, and I hope that it serves you well. :)
Added bar coloring for Moving Average crosses. Typically MA crosses lag a lot. In this instance the idea is to smooth the motion of the %B indicator by using the Primary Moving Average to smooth the %B, and the Secondary Moving Average as a signal for trade entries and/or exits.
In the screenshot is an example of this. The Primary MA is a 4 period SMA, and the Secondary MA is a 20 period SMA. One can see how the MA smooths the %B's often choppy movement.
Also, if you're already using the indicator you might notice that the default source setting is as 'hl2'. This is because hl2 produces a smoother line versus simply using the close of the period.
Typically MA crosses lag a lot, and using them for trade entries or exits is less than ideal. In this instance the idea is to smooth the action of the %B indicator by using the Primary Moving Average to smooth the %B (set it to a very short length), and then use the Secondary Moving Average as your signal for trade entries and/or exits.
If you do this I would turn off the actual %B and %B MA crossing candle colors, and just use the MA crossing candle colors, otherwise it’s just a messy chart and a messy indicator.
Also, if you're already using the indicator you might notice that the default source setting is as 'hl2'. This is because hl2 produces a smoother line versus simply using the close of the period
Changed default source to hlc3
Furthermore, as I had a couple of issues with updates of this in the past, I'm going to reiterate the additions, and why I made them, prior to this iteration.
Added bar coloring for Moving Average crosses.
Typically MA crosses lag a lot, and using them for trade entries or exits is less than ideal. In this instance the idea is to smooth the action of the %B indicator by using the Primary Moving Average to smooth the %B (set it to a very short length), and then use the Secondary Moving Average as your signal for trade entries and/or exits.
If you do this I would turn off the actual %B and %B MA crossing candle colors, and just use the MA crossing candle colors, otherwise it’s just a messy chart and a messy indicator.
Also, the default source setting is set as 'hlc3'. This is because hlc3 produces a smoother line versus simply using the close of the period, and that is my preferred way of measuring price movement with an indicator.
tradingview.com/u/xkavalis/
and I would highly recommend joining his Discord and subscribing to his YouTube channel. Not trying to shill the guy, but you can find out how the MA works by looking at his script for it. It's quite simple, though probably better as a chart overlay than as an MA for the %BB, imo.
Also, changed some candle colors, as I'm wanting to keep things aesthetically consistent across my indicators and trading panel. I'll be updating those too with the new RDA.
Added an input for turning candle colors on or off completely.
Changed linewidth to 2.
Added Jurik phase as an input.
added plot shapes for %B MA crosses
added background colors for MA MA2 crosses
added bollinger bands (how meta, but it works quite well as you can see in the picture)
changed background color to reflect %B crossing the mid
two sets of plot shapes for %B and MA crosses, or MA and MA crosses (if you're using the first MA as a smoothed %B)
cleaned up the code a bit, and cleaned up the inputs tab
Added a couple of alerts.
Cleaned up some code.
That's about it.
Most of what's changed has been added to the introductory portion of the indicator's code, so if you want to read more, check there.
- added RMA and VWMA
- added some additional color options for indicator and candles
- color options for plots and background colors for moving average and center line crosses if you use them
User Non-Visible Updates (basically backend stuff that makes:
- changes in code legibility and consistency across all indicators (basically standardizing the coding across as many indicators as possible)
- implementation of libraries into my indicators; which helps significantly in doing what I typed above; which in turn will make creating any new indicators, if they are of the type to use these libraries, much simpler
- updated descriptions for all indicators, which should (it's possible I've forgotten things) reflect changes I've made recently and any I may have made in the past after first publication (this is very minor, but as I was changing so much I thought I may as well--I don't intend to update these much, if at all, in the future)
User Visible Updates:
- as I mentioned everything now uses my moving averages library and volatility bands library--this cuts down the total amount of code significantly, and has made it easier for me to add moving averages, or volatility bands to these indicators because I only had to/have to add it one time (to the library) rather than multiple times across all indicators*
- since creating these libraries I've added several new moving averages (Kaufman Adaptive, Laguerre Filter, McGinley Dynamic (doesn't work for all), and Zero-lag) to them while retaining all the previous with the exception of the UMA, which wasn't implemented consistently across all indicators anyway
- eliminated having two Bollinger Bands with different standard deviations and a fill between them in exchange for one with the band fill implementation that I use on my Donchian Channels Bands
- part of my code consistency across all indicators resulted in a much needed organization of the 'style' tab
*(affects all but the Wavetrend Oscillator, Wavetrend Oscillator Overlay, Jurik KDJ, Average Candle Bodies Range, Bollinger Bands Width, ALMA Trend Detector, Ultimate Moving Average, Donchian Channels, and Dynamic Donchian Channels)
- update to pine v6
- brought code more in alignment with TradingView recommendations
- made more clear that the primary signal line (now called smoothed %B) could be used as a smoothed %B. I'm sure I mentioned that in an old old update, but this is something that I hadn't done with some other indicators, but as of these updates I have been implementing.
- updated to switch operations for selecting moving averages, donchian channel and bollinger bands. This just cuts down on a lot of code and makes the code itself easier to read.
- like every other indicator that has used it, I've eliminated color.gradient from the code, which means you don't get pretty gradient colors when using 'Range' and other color references. My apologies to those who enjoyed that, but part of these updates is cleaning up the UI in the Inputs tab, and getting rid of color inputs was part of that, and due to the way pinescript works, the only way I could eliminate color inputs was to eliminate gradient colors.
- updated divergences code to the latest by TradingView. Hopefully this is an upgrade for those who use them.
- added color by timeframe. There is a tooltip for this, but basically if you're on a daily tf and you select weekly for a higher tf, the %B and bars will be colored based on where the current %B is (on the daily tf) relative to the levels and things on the weekly. So like if the %B is showing overbought on the daily, but it is below the mid level on the weekly the %B color and bar color will reflect this (%B being bearish on the weekly).
I think that's about all.
3njoy.!
- added a signal line fill
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.