OPEN-SOURCE SCRIPT

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

Mis à jour
+ %B is, at its simplest, the classic Bollinger Bands %B indicator with a few added bells and whistles.
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. :)
Notes de version
https://www.tradingview.com/x/iceXmWeh/

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.
Notes de version
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, 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
Notes de version
Added Modular Filter as a moving average type.
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.
Notes de version
Just added another moving average: the RexDog Average created by one of the best traders out there in my opinion. You can find his profile here:
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.
Notes de version
Updates include cleaning up the candle coloring code a bunch, and adding a neutral candle color and %B color to the indicator that helps to identify areas of indecision, consolidation, or reversals in the market (same thing I've added to my other indicators). Basically, if the %B is bullish relative to the primary MA, but bearish relative to the median it will be grey (as will candles if you have candle colors on), and if the %B is bearish relative to the primary MA, but above the median it will also be grey.
Added an input for turning candle colors on or off completely.
Changed linewidth to 2.
Notes de version
Made an adjustment to primary moving average color that I forgot in the last update.
Added Jurik phase as an input.
Notes de version
added Arnaud Legoux Moving Average (ALMA) to moving averages lists
added plot shapes for %B MA crosses
added background colors for MA MA2 crosses
Notes de version
changed some verbiage that I missed in the MA+MA Cross BG.... I'm tired....
Notes de version
fresh update!
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
Notes de version
just fixing something with oversold candle colors and the %B that I changed in a previous update that was not a good idea, so, not an update to anything but a fix to a problem I created myself :D
Notes de version
Updated this the same way I've updated my other indicators recently. Mostly cosmetic color themed type stuff using color.from_gradient with different parts of the indicator.
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.
Notes de version
I just changed 'power' to a float from an integer so that you can fine tune the moving average more. It was something that someone pointed out to me in a comment of another indicator I released.
Notes de version
added auto-plotting divergences.
choose from plotting from the %B or from the primary MA (assuming you're using it as a smoothed %B).

snapshot
Notes de version
added alerts for divergences, clarified some alerts messages, and removed crossing up/down moving average alerts keeping crossing moving average alerts
Notes de version
- update to pinescript version 5
- 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
Notes de version
I'm publishing updates to all of my indicators, so I'm just going to comment on everything here since most of the updates are common across most of my indicators.

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)
barcolorbollingerbandspercentbCandlestick analysisDivergenceMomentum OscillatorsMoving AveragesnononsenseforexnononsensefxOscillatorspercentbsignalline

Script open-source

Dans le plus pur esprit TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par nos Règles. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Vous voulez utiliser ce script sur un graphique ?


Aussi sur:

Clause de non-responsabilité