Author: Copyright � 2005, Nick Bilak
bbhisto_v2

This tool is designed to provide a visual representation of market momentum and price volatility by interpreting data from the Bollinger Bands, a common technical analysis indicator. Instead of displaying standard moving averages or lines on your main price chart, this script creates a separate dedicated window to show "histogram" bars and specific signal markers.

How the Logic Works

1. Data Calculation The script begins by analyzing the market's standard deviation—which measures how much the price is fluctuating away from its average—over a specific timeframe (the "Bollinger Period"). It uses this information to determine the relationship between the current closing price and the historical moving average.

2. Histogram Generation The core logic converts these complex mathematical fluctuations into a simplified histogram. The script calculates a specific value based on the distance between the current price and the Bollinger Band limits.

  • This value is normalized into a positive or negative figure.
  • The result is plotted as a bar in the indicator window, allowing you to see the relative "strength" of a price move compared to recent volatility.

3. Visual Signaling To make the data easier to interpret at a glance, the script identifies whether the calculated momentum is trending upward or downward:

  • Upward Momentum: If the calculation results in a positive value, the script marks this as an "up" signal.
  • Downward Momentum: If the calculation results in a negative value, it marks this as a "down" signal.

These signals are then displayed visually using specific markers (arrows/symbols) in the indicator window, helping traders quickly distinguish between bullish and bearish pressure without having to manually calculate the standard deviation or price offsets themselves.

Indicators Used
Standard Deviation indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
17 Views
0 Downloads
0 Favorites
bbhisto_v2
//+------------------------------------------------------------------+
//|                                                      bbhisto.mq4 |
//|                                     Copyright © 2005, Nick Bilak |
//|        http://metatrader.50webs.com/         beluck[at]gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Nick Bilak"
#property link      "http://metatrader.50webs.com/"
//----
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Aqua
#property indicator_color3 Magenta
//---- input parameters
extern int bolingerPeriod=13;
//---- buffers
double bb[];
double up[];
double lo[];
//----
int i,j;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,bb);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,up);
   SetIndexEmptyValue(1,EMPTY_VALUE);
   SetIndexArrow(1,159);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexBuffer(2,lo);
   SetIndexEmptyValue(2,EMPTY_VALUE);
   SetIndexArrow(2,159);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int shift,limit;
   double diff,d,ku,kd,km;
//----
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   limit=Bars-31;
   if(counted_bars>=31) limit=Bars-counted_bars-1;
//----
   for(shift=limit+30;shift>=0;shift--)
     {
      bb[shift]=0;
      d=iStdDev(NULL,0,bolingerPeriod,MODE_SMA,0,PRICE_CLOSE,shift);
      if(d<0.0001) d=0.0001;
      bb[shift]=((Close[shift]+2*d - iMA(NULL,0,bolingerPeriod,0,MODE_SMA,PRICE_CLOSE,shift)) /
         (4*d))*4-2;
      bb[shift]=bb[shift]/3;
      up[shift]=EMPTY_VALUE;
      lo[shift]=EMPTY_VALUE;
      if (bb[shift]>0)
        {
         up[shift]=1;
        }
      if (bb[shift]<0)
        {
         lo[shift]=-1;
        }
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments