Stochastic Bollinger Bands2
Download scriptThis tool is designed to provide traders with a visual representation of market momentum combined with volatility boundaries. Instead of looking at standard price action alone, it focuses on the behavior of a momentum oscillator, allowing for a more nuanced view of whether an asset is overextended or finding a stable range.
Core Logic and Functionality
The script operates through a two-stage calculation process:
1. Momentum Identification (The Stochastic Foundation) First, the tool calculates a "Stochastic" value. In simple terms, this measures the current price relative to its recent price range. It helps identify the speed and strength of price movements. By using this as the base layer, the tool focuses on the "pulse" of the market rather than just the raw price.
2. Volatility Mapping (The Bollinger Bands) Next, the script applies a set of moving averages—known as Bollinger Bands—directly onto those Stochastic values. This is the unique step that distinguishes this tool from a standard indicator:
- Upper and Lower Boundaries: It creates a dynamic "channel" around the momentum line. These bands expand when the market is volatile and contract when the market is calm.
- Middle Reference Point: It establishes a center line to represent the average momentum over a specific period.
How it Works in Practice
By wrapping a volatility envelope (Bollinger Bands) around a momentum indicator (Stochastic), the tool allows you to see three things simultaneously:
- Trend Strength: The position of the primary line relative to the middle reference point.
- Overextended Movements: When the momentum line pushes outside the upper or lower bands, it suggests that the current move may be reaching an extreme.
- Stability Zones: When the momentum line stays within the bands, it indicates a period of more predictable, contained movement.
In summary, this script provides a visual "safety zone" for momentum, helping traders identify when a trend is becoming unusually aggressive or when it is beginning to stabilize.
#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 Yellow
#property indicator_color2 White
#property indicator_color3 White
#property indicator_color4 White
extern int StochasticPeriod=1;
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