OPEN-SOURCE SCRIPT

DT Bollinger Bands

Indicator Overview
Purpose: The script calculates and plots Bollinger Bands, a technical analysis tool that shows price volatility by plotting:

A central moving average (basis line).
Upper and lower bands representing price deviation from the moving average.
Additional bands for a higher deviation threshold (3 standard deviations).
Customization: Users can customize:

The length of the moving average.
The type of moving average (e.g., SMA, EMA).
The price source (e.g., close price).
Standard deviation multipliers for the bands.
Fixed Time Frame: The script can use a fixed time frame (e.g., daily) for calculations, regardless of the chart's time frame.

Key Features
Moving Average Selection:

The user can select the type of moving average for the basis line:
Simple Moving Average (SMA)
Exponential Moving Average (EMA)
Smoothed Moving Average (SMMA/RMA)
Weighted Moving Average (WMA)
Volume Weighted Moving Average (VWMA)
Standard Deviation Multipliers:

Two multipliers are used:
Standard (default = 2.0): For the original Bollinger Bands.
Larger (default = 3.0): For additional bands.
Bands Calculation:

Basis Line: The selected moving average.
Upper Band: Basis + Standard Deviation.
Lower Band: Basis - Standard Deviation.
Additional Bands: Representing ±3 Standard Deviations.
Plots:

Plots the basis, upper, and lower bands.
Fills the area between the bands for visual clarity.
Plots and fills additional bands for ±3 Standard Deviations with lighter colors.
Alerts:

Generates an alert when the price enters the range between the 2nd and 3rd standard deviation bands.
The alert can be used to notify when price volatility increases significantly.
Background Highlighting:

Colors the chart background based on alert conditions:
Green if the price is above the basis line.
Red if the price is below the basis line.
Offset:

Adds an optional horizontal offset to the plots for fine-tuning their alignment.
How It Works
Input Parameters:

The user specifies settings such as moving average type, length, multipliers, and fixed time frame.
Calculations:

The script computes the basis (moving average) and standard deviations on the fixed time frame.
Bands are calculated using the basis and multipliers.
Plotting:

The basis line and upper/lower bands are plotted with distinct colors.
Additional 3 StdDev bands are plotted with lighter colors.
Alerts:

An alert condition is created when the price moves between the 2nd and 3rd standard deviation bands.
Visual Enhancements:

Chart background changes color dynamically based on the price’s position relative to the basis line and alert conditions.

Usage
This script is useful for traders who:

Want a detailed visualization of price volatility.
Use Bollinger Bands to identify breakout or mean-reversion trading opportunities.
Need alerts when the price enters specific volatility thresholds.
Bollinger Bands (BB)

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer