Author: Copyright � 2005, Nick Bilak
BBhisto

This technical tool is designed to provide traders with a visual representation of market momentum and volatility by utilizing specialized calculations based on the Bollinger Bands methodology. Instead of simply showing price lines, this script converts complex mathematical data into a clear, readable histogram and directional signals.

Core Logic Overview

The primary objective of this tool is to analyze the relationship between the current market price and its historical average. It calculates the "deviation" of the price—essentially measuring how far the market is straying from its normal behavior over a specific timeframe.

By processing these deviations, the script determines the intensity of price movements. It then translates these results into a dedicated visual window where you can see the "strength" of the current trend at a glance.

Key Visual Features

The tool communicates three distinct types of information to the user:

  • Momentum Histogram: The main visual element is a histogram that fluctuates above and below a zero line. This provides a real-time look at whether the price movement is accelerating or decelerating relative to its recent history.
  • Upward Signals: When the logic detects a specific positive momentum, it identifies an "upward" state. These are represented by distinct markers on the chart to help traders quickly spot bullish movements.
  • Downward Signals: Conversely, when the logic detects negative momentum that exceeds certain thresholds, it identifies a "downward" state. These are marked with unique symbols to highlight potential bearish trends.

How It Works for the Trader

Rather than requiring you to manually calculate standard deviations or moving averages, the script does the heavy lifting in the background. It looks at the closing prices of recent candles and performs a multi-step calculation:

  1. It determines the volatility (how much the price is swinging).
  2. It compares the current price against a smoothed average.
  3. It normalizes this data into a numerical value that creates the histogram bars.

The result is a simplified visual environment where "higher" and "lower" bars, paired with specific directional arrows, allow for a much faster interpretation of market sentiment than looking at a standard price chart alone.

Indicators Used
Standard Deviation indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
BBhisto
//+------------------------------------------------------------------+
//|                                                      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