Pine Script v5 · Indicator
DBMA - Dual Bollinger Moving Average
A Pine Script v5 indicator built on SMA or EMA or VWMA (close, 20), Stdev (close, 20) and SMA (ta.tr, 20). It draws 5 lines and 4 fills on the price chart. 17 settings; defaults include MA length 20, MA type SMA and MA source close.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does DBMA - Dual Bollinger Moving Average repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 300 of 300 bars.
- How many settings does DBMA - Dual Bollinger Moving Average have?
- 17
- Defaults include MA length 20, MA type SMA, MA source close.
- Does DBMA - Dual Bollinger Moving Average run in Pine Script v6?
- Yes
- Every plotted value identical on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does DBMA - Dual Bollinger Moving Average draw on the price chart?
- Yes
- It is declared with overlay = true.
- Does DBMA - Dual Bollinger Moving Average run in Zeal Terminal?
- Yes
- It compiles in 27 ms and runs 1,000 bars in 49 ms, in the browser.
BTCUSDT · 1D · default settings
- Bollingerised Moving Average
- High-compression Squeeze
- Mid-compression Squeeze
- Low-compression Squeeze
- Fired Squeeze
- No Squeeze
- High-compression Squeeze
- 2.1%
- of bars
- Mid-compression Squeeze
- 27.4%
- of bars
- Low-compression Squeeze
- 27.4%
- of bars
- Fired Squeeze
- 41.1%
- of bars
- No Squeeze
- 2.0%
- of bars
Share of 1,000 bars spent in each state with the default settings.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
The “WMA” option calculates VWMA line 27
Choosing WMA in “MA type” runs ta.vwma, not ta.wma. Anyone picking WMA gets a different average from the one they asked for.
MA_type == 'WMA' ? ta.vwma(MA_type == 'WMA' ? ta.wma( -
Likely bug
ta.stdev(close, 20) ignores the settings line 61
Line 61 hard-codes close where line 32 uses “MA source” and 20 where line 32 uses “MA length”. Changing those settings moves one band but not this one.
ta.stdev(close, 20)ta.stdev(MA_source, MA_length) -
Note
3 settings have no label
In the settings dialog MA_length (line 6), MA_type (line 7), MA_source (line 8) show an empty name. The labels on this page come from the variable names.
-
Note
No alerts
The script declares no alertcondition, so you can't be notified when its state changes.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Moving Average | |||
| MA length (no label in the script) | 20 | int · min 1 · max 1000 | BMA devBB devKC |
| MA type (no label in the script) | SMA | string · options ['SMA', 'EMA', 'WMA'] | BMA |
| MA source (no label in the script) | close | source | BMA devBB |
| MA color (no label in the script) | color.green | color | Bollingerised Moving Average |
| MA line width | 1 | int · min 1 · max 4 | Bollingerised Moving Average |
| Bollinger Bands | |||
| Show Upper Bands | true | bool | Upper Far Band Upper Near Band |
| Show Lower Bands | false | bool | Lower Far Band Lower Near Band |
| Near Band | 0.5 | float · min 0 · max 3 · step 0.5 | devhalf |
| Color Orange Half (no label in the script) | color.new(color.orange, 85) | color | bb_colorHalf |
| Far Band | 1 | float · min 0 · max 3 · step 0.5 | devBB |
| Color Orange One (no label in the script) | color.new(color.orange, 90) | color | bb_colorOne |
| Squeeze | |||
| Squeeze Colors | true | bool | bb_colorOne bb_colorHalf |
| High-compression Squeeze | color.red | color | sq_color |
| Mid-compression Squeeze | color.orange | color | sq_color |
| Low-compression Squeeze | color.yellow | color | sq_color |
| Fired Squeeze | color.green | color | sq_color |
| No Squeeze | color.blue | color | sq_color |
What it calculates
- SMA / EMA / VWMAMA source (close), MA length (20) · chosen by MA type
BMA · line 27 - StdevMA source (close), MA length (20)
devBB · line 32 - SMAta.tr, MA length (20)
devKC · line 33 - Stdevclose, 20
devhalf · line 61
Signal flow
How price data and settings reach what is drawn. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
What it draws
| Output | Call | Value | By default | Line |
|---|---|---|---|---|
| Bollingerised Moving Average | plot | BMA | Shown | 28 |
| Upper Far Band | plot | BB_show_upper ? upper : na | Shown “Show Upper Bands” | 57 |
| Lower Far Band | plot | BB_show_lower ? lower : na | Hidden “Show Lower Bands” | 58 |
| BB Background | fill | p1 | Shown | 59 |
| BB Background | fill | p1 | Shown | 60 |
| Upper Near Band | plot | BB_show_upper ? upperhalf : na | Shown “Show Upper Bands” | 64 |
| Lower Near Band | plot | BB_show_lower ? lowerhalf : na | Hidden “Show Lower Bands” | 65 |
| BB Background | fill | p1 | Shown | 66 |
| BB Background | fill | p1 | Shown | 67 |
The shading takes one of 5 colours on every bar, each a state the script names in its settings: High-compression Squeeze Mid-compression Squeeze Low-compression Squeeze Fired Squeeze No Squeeze
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip or realtime-only state. Values move while a bar forms and settle when it closes, as every indicator's do.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets, each the most recent 1,000 bars.
| Market | High-compression Squeeze | Mid-compression Squeeze | Low-compression Squeeze | Fired Squeeze | No Squeeze |
|---|---|---|---|---|---|
| BTCUSDT 1D | 2% of bars3.9% vs 5.7% | 27% of bars4.9% vs 5.7% | 27% of bars5.6% vs 5.7% | 41% of bars5.7% vs 5.7% | 2% of bars— |
| BTCUSDT 4h | 4% of bars1.4% vs 1.8% | 22% of bars1.9% vs 1.8% | 32% of bars1.9% vs 1.8% | 40% of bars1.6% vs 1.8% | 2% of bars— |
| ETHUSDT 1D | 6% of bars9.2% vs 8.5% | 19% of bars8.6% vs 8.5% | 26% of bars8.5% vs 8.5% | 47% of bars8.0% vs 8.5% | 2% of bars— |
| ETHUSDT 4h | 9% of bars2.1% vs 2.4% | 27% of bars2.3% vs 2.4% | 23% of bars2.5% vs 2.4% | 40% of bars2.7% vs 2.4% | 2% of bars— |
| SOLUSDT 1D | 1% of bars12.3% vs 9.9% | 25% of bars10.3% vs 9.9% | 24% of bars8.4% vs 9.9% | 48% of bars9.4% vs 9.9% | 2% of bars— |
| SOLUSDT 4h | 3% of bars3.0% vs 2.9% | 26% of bars2.5% vs 2.9% | 30% of bars2.7% vs 2.9% | 40% of bars3.0% vs 2.9% | 2% of bars— |
| BNBUSDT 1D | 3% of bars5.6% vs 6.2% | 28% of bars5.1% vs 6.2% | 27% of bars6.3% vs 6.2% | 39% of bars7.7% vs 6.2% | 2% of bars— |
| BNBUSDT 4h | 3% of bars1.8% vs 2.0% | 22% of bars2.0% vs 2.0% | 34% of bars1.6% vs 2.0% | 40% of bars2.0% vs 2.0% | 2% of bars— |
Second line: the average size of the move over the next 10 bars after the colour first appears, against the average 10-bar move on any bar.
Similar scripts
Indicators and strategies built from the same calculations.
| Script | Shares | Type |
|---|---|---|
| Bollinger Band with Fib Golden Ratio (0.618) by mohanee | vwma stdev ema | v4 strategy |
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy |
| Super Breakout day trading by beststockalert | stdev sma ema | v4 strategy |
| Super Auto Breakout Day Trade Volatile stocks by beststockalert | stdev sma ema | v4 strategy |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
Yes
Every plotted value identical on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © finallynitin-//@version=5+//@version=6indicator(title='Dual Bollinger Moving Average', shorttitle='DBMA', overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 27 ms | With a workaround 1,000 bars in 49 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently merges fill() calls that share a title, so it would draw 1 of this script's 4 fills; this page gives each call its own title to draw all of them.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © finallynitin//@version=5indicator(title='Dual Bollinger Moving Average', shorttitle='DBMA', overlay=true)string GRP1 = "════════ Moving Average ═════════"MA_length = input.int(title='', minval=1, maxval=1000, defval=20, inline='line 1', group=GRP1)MA_type = input.string(title='', options=['SMA', 'EMA', 'WMA'], defval='SMA', inline='line 1', group=GRP1)MA_source = input.source(title='', defval=close, inline='line 1', group=GRP1)MA_color = input.color(title='', defval=color.green, inline='line 1', group=GRP1)MA_width = input.int(title='MA line width', defval=1, minval=1, maxval=4, inline='line 2', group=GRP1)string GRP2 = "════════ Bollinger Bands ═════════"BB_show_upper = input.bool(title='Show Upper Bands', defval=true, inline='line 1', group=GRP2)BB_show_lower = input.bool(title='Show Lower Bands', defval=false, inline='line 2', group=GRP2)BB_stdev_near = input.float(title='Near Band', minval=0, maxval=3, defval=0.5, step = 0.5, inline='line 3', group=GRP2)colorOrangeHalf = input.color(color.new(color.orange, 85), '', inline='line 3', group=GRP2)BB_stdev_far = input.float(title='Far Band', minval=0, maxval=3, defval=1, step = 0.5, inline='line 4', group=GRP2)colorOrangeOne = input.color(color.new(color.orange, 90), '', inline='line 4', group=GRP2)string GRP3 = "════════ Squeeze ═════════"toggleSQZColors = input.bool(title='Squeeze Colors', defval=true, inline='line 3', group=GRP3)colorRed = input.color(color.red, 'High-compression Squeeze', group=GRP3)colorOrange = input.color(color.orange, 'Mid-compression Squeeze', group=GRP3)colorYellow = input.color(color.yellow, 'Low-compression Squeeze', group=GRP3)colorGreen = input.color(color.green, 'Fired Squeeze', group=GRP3)colorBlue = input.color(color.blue, 'No Squeeze', group=GRP3)//--------BMA------BMA = 0.0BMA := MA_type == 'SMA' ? ta.sma(MA_source, MA_length) : MA_type == 'EMA' ? ta.ema(MA_source, MA_length) : MA_type == 'WMA' ? ta.vwma(MA_source, MA_length) : nap1 = plot(BMA, title='Bollingerised Moving Average', color=MA_color, linewidth=MA_width)//--------SQUEEZE------// original concept from John Carter's book "Mastering the Trade"// based on LazyBear's script (Squeeze Momentum Indicator) https://in.tradingview.com/script/nqQ1DT5a-Squeeze-Momentum-Indicator-LazyBear/devBB = BB_stdev_far * ta.stdev(MA_source, MA_length)devKC = ta.sma(ta.tr, MA_length)//Bollinger 2xupBB = BMA + devBB * 2lowBB = BMA - devBB * 2//Keltner 2xupKCWide = BMA + devKC * 2lowKCWide = BMA - devKC * 2//Keltner 1.5xupKCNormal = BMA + devKC * 1.5lowKCNormal = BMA - devKC * 1.5//Keltner 1xupKCNarrow = BMA + devKClowKCNarrow = BMA - devKCsqzOnWide = lowBB >= lowKCWide and upBB <= upKCWide //Low-compression Squeeze: YELLOWsqzOnNormal = lowBB >= lowKCNormal and upBB <= upKCNormal //Mid-compression Squeeze: ORANGEsqzOnNarrow = lowBB >= lowKCNarrow and upBB <= upKCNarrow //High-compression Squeeze: REDsqzOffWide = lowBB < lowKCWide and upBB > upKCWide //Fired Squeeze: GREENnoSqz = sqzOnWide == false and sqzOffWide == false //No Squeeze: BLUEsq_color = noSqz ? colorBlue : sqzOnNarrow ? colorRed : sqzOnNormal ? colorOrange : sqzOnWide ? colorYellow : colorGreenbb_colorOne = toggleSQZColors ? color.new(sq_color, 80) : colorOrangeOnebb_colorHalf = toggleSQZColors ? color.new(sq_color, 80) : colorOrangeHalf//--------BOLLINGER BANDS------upper = BMA + devBBlower = BMA - devBBp2 = plot(BB_show_upper ? upper : na, 'Upper Far Band', color=color.new(color.orange, 100))p3 = plot(BB_show_lower ? lower : na, 'Lower Far Band', color=color.new(color.red, 100))fill(p1, p2, title='BB Background', color=bb_colorOne)fill(p1, p3, title='BB Background', color=bb_colorOne)devhalf = BB_stdev_near * ta.stdev(close, 20)upperhalf = BMA + devhalflowerhalf = BMA - devhalfp4 = plot(BB_show_upper ? upperhalf : na, 'Upper Near Band', color=color.new(color.orange, 100))p5 = plot(BB_show_lower ? lowerhalf : na, 'Lower Near Band', color=color.new(color.red, 100))fill(p1, p4, title='BB Background', color=bb_colorHalf)fill(p1, p5, title='BB Background', color=bb_colorHalf)