Stochastic Bollinger Bands B1

Download script
Stochastic Bollinger Bands B1

This custom trading indicator, titled "Stochastic Bollinger Bands," is designed to provide visual data for traders by combining two popular technical analysis tools into a single unified display. Instead of looking at price action directly, this tool analyzes the momentum of the market and then applies volatility boundaries to that momentum.

How the Logic Works

The script operates in a two-step process to generate its visual output:

1. Momentum Analysis (The Foundation) First, the indicator calculates a "Stochastic" value. In trading, this is used to determine whether an asset is overbought or oversold based on its previous price movements. Think of this as measuring the "speed" and "strength" of the current market trend. This calculation serves as the raw data for the rest of the indicator.

2. Volatility Mapping (The Overlay) Once the Stochastic value is established, the script applies a second layer of analysis called "Bollinger Bands" directly onto those Stochastic values. Rather than measuring the volatility of the price, it measures the volatility of the momentum itself.

This results in three specific lines being plotted on your chart:

  • The Middle Line: Represents the average momentum over a set period.
  • The Upper and Lower Bands: These act as dynamic boundaries. They expand when the market momentum is highly volatile and contract when the momentum is stable.

Summary for the User

By nesting Bollinger Bands inside a Stochastic oscillator, this tool helps you see not just where the price is going, but how "stretched" or "compressed" the current momentum is. It allows traders to identify potential extremes in market behavior more clearly than using either tool alone, providing a specialized view of market energy and trend exhaustion.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
Stochastic Bollinger Bands B1
#property  copyright "Copyright © 2007, Matt Edmonds."
#property  link      "matt.edmonds@gmail.com"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Blue
#property  indicator_color2  Red
#property  indicator_color3  Red
#property  indicator_color4  Red



extern int StochasticPeriod=20;
extern int BollingerPeriod=10;
extern int BollingerDeviation = 1;
extern int BollingerShift = 0;

extern int BarsToUse = 500;

//---- indicator buffers
double Stochastic[];
double BollingerUpper[];
double BollingerLower[];
double BollingerMiddle[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(4);
   
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_LINE,STYLE_DOT,1);
   
   SetIndexBuffer(0,Stochastic);
   SetIndexLabel(0,"Stochastic Bollinger Bands");
   SetIndexBuffer(1,BollingerUpper);
   SetIndexBuffer(2,BollingerLower);
   SetIndexBuffer(3,BollingerMiddle);
   SetIndexLabel(3,"Bollinger Middle");
      
//---- name for DataWindow and indicator subwindow label
 IndicatorShortName("Stochastic Bollinger Bands");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
 //  int limit;
   int i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
//   limit=Bars-counted_bars;
 
//---- main loop
   for(i=0; i<BarsToUse; i++)
   {
     Stochastic[i]= iStochastic(NULL, 0, StochasticPeriod, 1, 3, MODE_SMA, 0, MODE_MAIN, i);
    }
  
//---- done

   for(i=0; i<BarsToUse; i++)
   {  
     BollingerLower[i] = iBandsOnArray(Stochastic,0,BollingerPeriod,BollingerDeviation,BollingerShift,MODE_LOWER,i); 
     BollingerUpper[i] = iBandsOnArray(Stochastic,0,BollingerPeriod,BollingerDeviation,BollingerShift,MODE_UPPER,i); 
     BollingerMiddle[i] = iBandsOnArray(Stochastic,0,BollingerPeriod,BollingerDeviation,BollingerShift,MODE_MAIN,i); 
   }   
   
   return(0);
  }
//+------------------------------------------------------------------+

Comments