to_ind_Better_Bollinger_Bands

Download script
to_ind_Better_Bollinger_Bands

This tool is designed as a specialized technical analysis indicator for trading platforms. It enhances the standard Bollinger Bands—a common tool used to identify high and low price ranges—by refining how the volatility and "center" of the market are calculated.

Core Logic Overview

Unlike standard indicators that might react too quickly or too slowly to price fluctuations, this script uses a multi-layered smoothing technique. It essentially processes the market data through two distinct stages to create a more stable visual representation of market trends.

How it Works

1. Double Smoothing Mechanism The script does not rely on a single calculation. Instead, it employs a "weighted" approach. It takes current price information and blends it with previous data points using a specific mathematical weight. This helps filter out "market noise"—those random, tiny price movements that can often lead to false signals—resulting in a much smoother trend line.

2. Dynamic Calculation Layers The logic operates in two primary phases:

  • The First Layer: It calculates a baseline movement based on the chosen period and price type. This determines the general direction of the market.
  • The Second Layer: It takes the results of the first layer and applies the smoothing process again. By calculating the difference between these layers, the script identifies the true "core" of the market's movement.

3. Band Construction Once the smoothed core is established, the indicator creates three distinct visual lines:

  • The Center Line: This represents the primary trend or equilibrium of the market.
  • Upper and Lower Bands: These are calculated by taking that smoothed core and adding or subtracting a specific "Deviation" value (which you can customize). Because these bands are based on the double-smoothed logic, they tend to be more resilient and less prone to erratic jumping than standard versions.

Key Features for the User

  • Customizable Sensitivity: You can adjust the number of periods (how much historical data to look at) and the deviation (how wide the bands should be).
  • Visual Clarity: By providing a smoothed "core" along with the upper and lower boundaries, the tool helps traders identify whether the price is overextended or if it is following a stable trend.
  • Stability: The primary goal of this logic is to provide a cleaner, more reliable visual path for price action, making it easier to spot significant shifts in market momentum without being distracted by minor price spikes.
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
to_ind_Better_Bollinger_Bands
//+------------------------------------------------------------------+
//|                                to_ind_Better_Bollinger_Bands.mq4 |
//|                                                                * |
//|                                                                * |
//+------------------------------------------------------------------+
#property copyright "http://dmffx.com"
#property link      "http://dmffx.com"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Red

//---- input parameters
extern int       Periods=20;
extern double    Devs=2;
extern int       Price=1; 
//---- buffers
double mt[];
double ut[];
double mt2[];
double ut2[];
double but[];
double blt[];
double bct[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(7);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,but);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,blt);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,bct);
   
   SetIndexBuffer(3,mt);
   SetIndexBuffer(4,ut);
   SetIndexBuffer(5,mt2);
   SetIndexBuffer(6,ut2);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    limit=Bars-IndicatorCounted()-1;
   double alpha=2.0/(Periods+1);
      for(int i=limit;i>=0;i--){
         mt[i]=alpha*iMA(NULL,0,1,0,0,Price,i)+(1-alpha)*mt[i+1];
         ut[i]=alpha*mt[i]+(1-alpha)*ut[i+1];
         double dt=((2-alpha)*mt[i]-ut[i])/(1-alpha);
         mt2[i]=alpha*MathAbs(iMA(NULL,0,1,0,0,Price,i)-dt)+(1-alpha)*mt2[i+1];
         ut2[i]=alpha*mt2[i]+(1-alpha)*ut2[i+1];
         double dt2=((2-alpha)*mt2[i]-ut2[i])/(1-alpha);         
         but[i]=dt+Devs*dt2;
         blt[i]=dt-Devs*dt2;
         bct[i]=dt;         
      }
   return(0);
  }
//+------------------------------------------------------------------+

Comments