Bollinger_Bands_b
Download scriptThis custom indicator is designed to provide traders with a precise measurement of where the current price sits relative to the upper and lower boundaries of a Bollinger Band. While standard Bollinger Bands show you the volatility and potential range of a market, this specific tool converts that data into a numerical percentage-like value, making it easier to identify overbought or oversold conditions at a glance.
How the Logic Works
The script operates by analyzing two primary components: a moving average (the "center" of the band) and the standard deviation (which determines how wide the bands stretch based on market volatility).
Instead of simply plotting the price on the chart, the logic performs the following steps:
- Boundary Identification: The tool automatically calculates the upper and lower limits of the Bollinger Band for every point in time based on the settings you choose (the timeframe period and the standard deviation).
- Relative Position Calculation: It looks at the current closing price and determines exactly where it sits between those two boundaries.
- Normalization to a Scale: The core "logic" of this script is its formula for positioning. It calculates the distance from the lower boundary and divides it by the total width of the band (the distance between the upper and lower limits).
What This Means for the Trader
The result is a single line displayed in a separate window below your main price chart.
- When the value is near 0: It indicates that the price is hugging the lower Bollinger Band, suggesting the market may be undervalued or experiencing significant downward pressure.
- When the value is near 1: It indicates that the price is touching or exceeding the upper Bollinger Band, suggesting the market may be overextended or "overbought."
- Mid-range values: These represent a neutral position where the price is trading within the expected range of the current volatility.
By using this script, you move away from looking at "raw" price movements and instead get a standardized view of market momentum. It allows you to see instantly if a price movement is becoming extreme relative to recent historical volatility, providing a clearer signal for potential trend reversals or breakouts.
//+-------------------------------------------------------------------+
//| Bollinger Bands %b.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//| Modified by Alejandro Galindo |
//| |
//| You are free to use it |
//| |
//| If you want and if this work/modification is helpful to you |
//| you can send me a PayPal donation to ag@elcactus.com |
//+-------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow
//---- input parameters
extern int BBPeriod=20;
extern int StdDeviation=2;
//---- buffers
double BLGBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,BLGBuffer);
//---- name for DataWindow and indicator subwindow label
short_name="BBpB("+BBPeriod+","+StdDeviation+")";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
SetIndexDrawBegin(0,BBPeriod);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Momentum |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=BBPeriod) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=BBPeriod;i++) BLGBuffer[Bars-i]=0.0;
//----
i=Bars-BBPeriod-1;
if(counted_bars>=BBPeriod) i=Bars-counted_bars-1;
while(i>=0)
{
BLGBuffer[i]=(Close[i]-iBands(NULL,0,BBPeriod,StdDeviation,0,0,MODE_HIGH,i))/(iBands(NULL,0,BBPeriod,StdDeviation,0,0,MODE_LOW,i)-iBands(NULL,0,BBPeriod,StdDeviation,0,0,MODE_HIGH,i));
i--;
}
return(0);
}
//+------------------------------------------------------------------+
Comments