Stochastic Bollinger Bands B

Download script
Stochastic Bollinger Bands B

This tool is a custom visual indicator designed to help traders identify potential price momentum and overextended market conditions by combining two well-known technical analysis methods: the Stochastic Oscillator and Bollinger Bands. Instead of looking at these tools independently, this script layers them together to provide a more refined view of market activity.

How the Logic Works

The script functions in two primary stages to generate the visual data on your chart:

1. Base Momentum Tracking (Stochastic Foundation) First, the tool calculates the Stochastic Oscillator. In standard trading, the Stochastic is used to determine if an asset is "overbought" or "oversold" based on its recent price range. The script extracts this movement as its primary data point, creating a baseline of momentum that flows across the bottom window of your chart.

2. Volatility Filtering (Bollinger Band Overlay) The unique logic of this script occurs in the second stage: rather than applying Bollinger Bands directly to the price of the asset (like most traders do), it applies them directly onto the Stochastic Oscillator data.

By doing this, the tool creates a "channel" around the momentum line. It calculates:

  • Upper and Lower Boundaries: These represent the extreme limits of the current momentum.
  • Middle Line: This represents the average momentum over a specific period.

What This Means for the Trader

The resulting visual allows you to see not just where the price is going, but whether the momentum of that price is becoming exhausted.

When the Stochastic line (the blue line) pushes toward or outside the Bollinger Bands, it suggests that the current trend is reaching an extreme point relative to its recent history. This helps traders identify potential turning points where a trend might be losing steam, providing a secondary layer of confirmation that goes beyond simple price action.

Indicators Used
Stochastic oscillator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
Stochastic Bollinger Bands B
#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;

//---- 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<Bars; i++)
   {
     Stochastic[i]= iStochastic(NULL, 0, StochasticPeriod, 1, 3, MODE_SMA, 0, MODE_MAIN, i);
    }
  
//---- done

   for(i=0; i<Bars; 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