OPEN-SOURCE SCRIPT
[Mad]Triple Bollinger Bands Forecast

Triple Bollinger Bands Forecast (BBx3+F)
This open-source indicator is an advanced version of the classic Bollinger Bands, designed to provide a more comprehensive and forward-looking view of market volatility and potential price levels.
It plots three distinct sets of Bollinger Bands and projects them into the future based on statistical calculations.
How It Is Built and Key Features
Differences from a Classical Bollinger Bands Indicator
The Mathematics Behind the Future Predictions
The core challenge in forecasting Bollinger Bands is that a future band value depends on future prices, which are unknown. This indicator solves this by simulating a future price series. Here is the step-by-step logic:
Usage as a Forecast Extension
This indicator's functionality is designed to be modular. It can be used in conjunction with as example Mad Triple Bollinger Bands MTF script to separate the rendering of historical data from the forward-looking forecast.
Configuration for Combined Use:
This configuration prevents the rendering of duplicate historical bands. The Mad Triple Bollinger Bands MTF script will be responsible for visualizing the historical and current bands, while this script will overlay only the forward-projected polyline data.
This open-source indicator is an advanced version of the classic Bollinger Bands, designed to provide a more comprehensive and forward-looking view of market volatility and potential price levels.
It plots three distinct sets of Bollinger Bands and projects them into the future based on statistical calculations.
How It Is Built and Key Features
- Triple Bollinger Bands: Instead of a single set of bands, this indicator plots three. All three share the same central basis line (a Simple Moving Average), but each has a different standard deviation multiplier. This creates three distinct volatility zones for analyzing price deviation from its mean.
- Multi-Timeframe (MTF) Capability: The indicator can calculate and display Bollinger Bands from a higher timeframe (e.g., showing daily bands on a 4-hour chart). This allows for contextualizing price action within the volatility structure of a more significant trend.
(Lower HTF selection will result in script-crash!) - Future Forecasting: This is the indicator's main feature. It projects the calculated Bollinger Bands up to 8 bars into the future. This forecast is a recalculation of the Simple Moving Average and Standard Deviation based on a projected future source price.
- Selectable Forecast Methods: The mathematical model for estimating the future source price can be selected:
Flat: A model that uses the most recent closing price as the price for all future bars in the calculation window.
Linreg (Linear Regression): A model that calculates a linear regression trend on the last few bars and projects it forward to estimate the future source price. - Efficient Drawing with Polylines: The future projections are drawn on the chart using Pine Script's polyline object. This is an efficient method that draws the forecast data only on the last bar, which avoids repainting issues.
Differences from a Classical Bollinger Bands Indicator
- Band Count: A classical indicator shows one set of bands. This indicator plots three sets for a multi-layered view of volatility.
- Perspective: Classical Bollinger Bands are purely historical. This indicator is both historical and forward-looking.
- Forecasting: The classic version has no forecasting capability. This indicator projects the bands into the future.
- Timeframe: The classic version works only on the current timeframe. This indicator has full Multi-Timeframe (MTF) support.
The Mathematics Behind the Future Predictions
The core challenge in forecasting Bollinger Bands is that a future band value depends on future prices, which are unknown. This indicator solves this by simulating a future price series. Here is the step-by-step logic:
- Forecast the Source Price for the Next Bar
First, the indicator estimates what the price will be on the next bar.
Flat Method: The forecasted price is the current bar's closing price.
Price_forecast = close[0]Linreg Method: A linear regression is calculated on the last few bars and extrapolated one step forward.
Price_forecast = ta.linreg(close, linreglen, 1) - Calculate the Future SMA (Basis)
To calculate the Simple Moving Average for the next bar, a new data window is simulated. This window includes the new forecasted price and drops the oldest historical price. For a 1-bar forecast, the calculation is:Pine Script® SMA_future = (Price_forecast + close[0] + close[1] + ... + close[length-2]) / length - Calculate the Future Standard Deviation
Similarly, the standard deviation for the next bar is calculated over this same simulated window of prices, using the new SMA_future as its mean.Pine Script® // 1. Calculate the sum of squared differences from the new mean d_f = Price_forecast - SMA_future d_0 = close[0] - SMA_future // ... and so on for the rest of the window's prices SumOfSquares = (d_f)^2 + (d_0)^2 + ... + (d_length-2)^2 // 2. Calculate future variance and then the standard deviation Var_future = SumOfSquares / length StDev_future = sqrt(Var_future) - Extending the Forecast (2 to 8 Bars)
For forecasts further into the future (e.g., 2 bars), the script uses the same single Price_forecast for all future steps in the calculation. For a 2-bar forecast, the simulated window effectively contains the forecasted price twice, while dropping the two oldest historical prices. This provides a statistically-grounded projection of where the Bollinger Bands are likely to form.
Usage as a Forecast Extension
This indicator's functionality is designed to be modular. It can be used in conjunction with as example Mad Triple Bollinger Bands MTF script to separate the rendering of historical data from the forward-looking forecast.
Configuration for Combined Use:
- Add both the Mad Triple Bollinger Bands MTF and this Triple Bollinger Bands Forecast indicator to your chart.
- Open the Settings for this indicator (BBx3+F).
- In the 'General Settings' tab, disable the Activate Plotting option.
- To ensure data consistency, the Bollinger Length, Multipliers, and Higher Timeframe settings should be identical across both indicators.
This configuration prevents the rendering of duplicate historical bands. The Mad Triple Bollinger Bands MTF script will be responsible for visualizing the historical and current bands, while this script will overlay only the forward-projected polyline data.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.