Author: Copyright � 2006, Akuma99.
BB_Diff

This tool is designed to provide traders with a real-time measurement of market volatility by calculating the vertical distance between two specific boundaries on a price chart. Specifically, it utilizes the Bollinger Bands—a common technical analysis indicator used to identify whether a market is in a state of high or low activity.

How the Logic Works

The script focuses on the relationship between the upper and lower limits of the Bollinger Bands. Rather than just showing you the lines themselves, this tool performs the following calculations:

  • Data Gathering: The script looks at a specific timeframe of historical price data (based on a user-defined period) to determine the current "Upper Band" and "Lower Band."
  • Difference Calculation: It subtracts the value of the lower band from the upper band to find the exact mathematical "gap" between them.
  • Volatility Translation: Because the raw numerical difference can sometimes be difficult to interpret at a glance, the script automatically converts this value into Pips. This allows you to see exactly how wide the market "channel" is in terms of standard trading units.

What This Means for the Trader

By displaying this information directly on your screen as a text comment, the tool helps you monitor market expansion and contraction instantly.

  • High Difference: When the distance between the bands increases significantly, it indicates high volatility and large price swings.
  • Low Difference: When the bands squeeze closer together, it suggests a period of consolidation or low activity, which often precedes a major breakout.

Essentially, this script acts as a "volatility ruler," providing a constant, easy-to-read metric of how much room the market is currently moving within its technical boundaries.

Indicators Used
Bollinger bands indicator
9 Views
1 Downloads
0 Favorites
BB_Diff
//+------------------------------------------------------------------+
//|                                                      BB_Diff.mq4 |
//|                                       Copyright © 2006, Akuma99. |
//|                                    http://www.beginnertrader.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Akuma99."
#property link      "http://www.beginnertrader.com"

#property indicator_chart_window

extern double bbPeriod=20;
extern double bbDev=2.0;
extern string displayText="Bollinger Band Difference:";

int start() {

   int    counted_bars=IndicatorCounted();
   
   double upperBand = iBands(NULL,0,bbPeriod,bbDev,0,PRICE_CLOSE,MODE_UPPER,0);
   double lowerBand = iBands(NULL,0,bbPeriod,bbDev,0,PRICE_CLOSE,MODE_LOWER,0);
   
   double bandDifference = upperBand-lowerBand;
   
   Comment("\n",displayText," ", bandDifference, " (", bandDifference/Point," Pips)");
   
   return(0);

}

Comments