Bollinger-style bands around MACD · Example 10 / 1 / 12 / 26

AK MACD Bollinger Bands: Calculation, Colors and Limits

AK MACD BB compares an EMA-based MACD value with a rolling envelope calculated from that same MACD series. The bands measure dispersion in the oscillator, not support and resistance prices for the asset.

Algokid's original TradingView publication dates to February 24, 2015. The implementation below is the version documented by Pineify. Check its source and color rules rather than assuming every script using the name is identical.

Calculate MACD first, then its envelope

M = EMA(close, fast) − EMA(close, slow)

B = SMA(M, n)

σ = sqrt(Σ(Mᵢ − B)² / n)

Upper = B + kσ; Lower = B − kσ

Width = Upper − Lower = 2kσ

The displayed code uses fast 12, slow 26, n = 10 and k = 1. Pine's default standard-deviation calculation uses the population divisor n. The current bar belongs to the rolling window, so both its MACD value and its comparison bands can change before the close.

Positive MACD means the fast EMA exceeds the slow EMA; negative MACD means the reverse. Being above the upper band is a separate comparison. For example, a MACD value of -1 can exceed an upper band of -1.5 while remaining below zero. A teal dot therefore does not by itself mean MACD is positive or that price is rising.

The function returns MACD, basis, upper and lower. The shown plots draw the two bands and MACD circles; the basis is returned but is not separately plotted. There is no conventional nine-period signal EMA or MACD histogram in this implementation.

Reproduce the bands with a short numerical window

Use a synthetic three-observation MACD window [1, 2, 3] to isolate the band calculation. This is an arithmetic example, not the default ten-bar configuration or an observed price series. Basis is 2. Population variance is (1 + 0 + 1) / 3 = 2/3, so standard deviation is approximately 0.816497. With k = 1, the bands are 2.816497 and 1.183503. The current MACD 3 is strictly above the upper band.

If the next MACD value is 2, the rolling window becomes [2, 3, 2]. Basis is 7/3 and standard deviation is √(2/9), approximately 0.471405. The bands become approximately 2.804738 and 1.861929, placing the current value inside. A return inside the oscillator bands does not tell us the asset's price change; the input closes and EMA states would be needed for that.

Keeping the first window fixed and changing k from 1 to 2 doubles width from 1.632993 to 3.265986. It does not establish how much a dataset's touch count changes. Changing either EMA length changes the MACD observations themselves, so the effect is not just a rescaling of the band width.

Pine Script implementation

The four settings are fixed function arguments in this example; there are no editable input declarations. The MACD plot uses circle markers with a linewidth of three.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// (c) Pineify

//@version=6
indicator(title="AK MACD Bollinger Bands", overlay=false, max_labels_count=500)

p_ta_ak_macd_bb(simple int length, series float dev, simple int fastLength, simple int slowLength) =>
    fastMA = ta.ema(close, fastLength)
    slowMA = ta.ema(close, slowLength)
    macd = fastMA - slowMA
    basis = ta.sma(macd, length)
    Std = ta.stdev(macd, length)
    upper = basis + Std * dev
    lower = basis - Std * dev
    [macd, basis, upper, lower]

[p_ind_1_macd, p_ind_1_middle, p_ind_1_upper, p_ind_1_lower] = p_ta_ak_macd_bb(10, 1, 12, 26)
hline(0, "AK MACD BB - Zero Line", color.rgb(255, 160, 0, 0))
p_ind_1_upper_plot = plot(p_ind_1_upper, "AK MACD BB - Upper", color.rgb(158, 158, 158, 0), 2)
p_ind_1_lower_plot = plot(p_ind_1_lower, "AK MACD BB - Lower", color.rgb(158, 158, 158, 0), 2)
fill(p_ind_1_upper_plot, p_ind_1_lower_plot, color.rgb(33, 150, 243, 75), title="AK MACD BB - Band Fill")
plot(p_ind_1_macd, "AK MACD BB - MACD", style=plot.style_circles, linewidth=3, color=p_ind_1_macd >= p_ind_1_upper ? color.rgb(38, 166, 154, 0) : p_ind_1_macd <= p_ind_1_lower ? color.rgb(255, 82, 82, 0) : color.gray)
barcolor(p_ind_1_macd > p_ind_1_upper ? color.rgb(255, 235, 59, 0) : p_ind_1_macd < p_ind_1_lower ? color.rgb(0, 188, 212, 0) : na)

Open TradingView's Pine Editor, add the script and compare its values on completed bars. Match the symbol, session, price adjustments and interval. This is an indicator: it contains no squeeze detector, strategy orders, alerts, stop prices or measured performance.

Retained chart illustration for the AK MACD Bollinger Bands reference
Existing chart illustration. Use the formula and source for value comparisons; this image does not establish a trading result.

Circle colors and candle colors use different boundaries

Assuming defined values and a positive band width
MACD positionCirclePrice-bar override
Above upperTealYellow
Exactly at upperTealNone
Strictly insideGrayNone
Exactly at lowerRedNone
Below lowerRedCyan

Circles use inclusive comparisons; barcolor uses strict comparisons. The last argument 0 in color.rgb is transparency, meaning fully opaque. The blue fill uses transparency 75. The yellow and cyan bar colors are not invisible.

With a constant valid MACD window, standard deviation is zero and both bands equal MACD. The first circle condition wins, making the dot teal, while neither strict bar-color condition is true. That degenerate result is not evidence of a bullish breakout. Band-width ratios must also guard against a zero denominator.

Dispersion is not a reversal probability

A multiplier of one means one rolling standard deviation from the basis. It does not show that 68% of future values will remain inside, or that a touch has any particular chance of reversing. John Bollinger's own rules warn against statistical assumptions based solely on the standard-deviation construction.

A narrow envelope records lower recent MACD dispersion. It does not guarantee a large move within three, five or seven bars. A wider envelope does not establish a more reliable zero cross. Any such claim requires a specified dataset, event definition, outcome horizon and independent evaluation.

MACD is in quoted price units. Comparing raw MACD values or width between a high-priced instrument and a low-priced one does not compare their percentage volatility. Dividing width by the MACD basis is unstable when the basis is zero or near zero and changes sign when the basis is negative.

Define the event before testing a strategy

Touch versus return inside

A prior upper-band excursion should compare the previous MACD with its own previous upper band. A later return inside requires the current MACD to be between the current lower and upper bands. Decide whether equality qualifies, whether the bar must close and whether one event or every qualifying bar is counted.

A squeeze experiment

Choose a width measure and a historical reference before looking at outcomes. If comparing current width with an earlier average, state whether that average excludes the current bar. Record a maximum time allowed for a subsequent breakout. Treat a threshold such as 35% as an experimental choice, not a proven optimum.

Price stops and costs

Define stops on the price chart. A MACD basis of 0.5 is not a tradable asset price for a security at 100. If a hypothetical entry is 100 and a price-based stop is 98, risk is 2 per share before costs; an oscillator crossing does not guarantee a fill at either price.

Specify entry timing, exits, repeated-entry rules, position size and transaction costs. Compare the full rule with and without an added price EMA or ADX filter on the same observations. Keep a held-out sample and include losing, untriggered and ambiguous events. No benefit percentage is claimed for any filter here.

Compare MACD, MACD bands and price bands

Standard MACD commonly displays its EMA difference, a smoothed signal line and their difference as a histogram. This version uses an SMA and deviation envelope on the MACD series. Price Bollinger Bands instead apply the envelope to a price source. The transformations differ; none automatically removes lag or predicts which trade will succeed.

To customize this implementation in Pineify, specify the EMA lengths, band window, deviation divisor, equality behavior and closed-bar conditions. Ask for positive input bounds and separate plot and alert logic. The AI Coding Agent can draft and revise the script; inspect generated code and compare numerical outputs. Access and usage depend on your plan.

Customize the MACD band specification

AK MACD BB questions

It places a rolling SMA and standard-deviation envelope around an EMA-based MACD series. Algokid published AK MACD BB INDICATOR V 1.00 on TradingView on February 24, 2015. This page documents the Pineify implementation; it does not claim that Pineify invented the indicator.

A touch describes the MACD value relative to its rolling envelope. It does not establish a probability of a pullback, a continuation or a price target. MACD can remain outside a band, and a return inside can occur without a reversal in price.

The code calls the function with a 10-bar band window, deviation multiplier 1, fast EMA length 12 and slow EMA length 26. These are fixed function arguments, not editable Inputs in the displayed script. They are not validated optimal settings for a market or timeframe.

Circles use inclusive comparisons: MACD at or above the upper band is teal, otherwise at or below the lower band is red. Bar colors require strictly above or below. At exact equality with a band, the corresponding strict candle-color condition is false.

No observed coverage rate follows from this multiplier. The rolling window includes the current MACD value, and the series is neither assumed independent nor normally distributed. Measure coverage on a specified dataset if that quantity matters; do not infer trade odds from it.

No. It draws bands, a zero line and colored MACD dots, and can color price bars. It does not define a squeeze threshold, alert conditions, strategy orders, stops or a performance report.

The MACD basis and bands are oscillator values, not the current asset price. A price stop must be defined using a price reference and execution rules. Adding ATR to a near-zero MACD basis does not create a meaningful stop price for an asset trading far above zero.

Primary sources and related reading

Numeric examples are synthetic checks of calculation and display rules. They are not historical returns or personal trading results.