Author: Copyright 2014, Roy Philips Jacobs ~ 31/07/2014
bbmacd

This technical tool is designed to provide traders with a visual representation of market dynamics by combining two well-known analytical concepts into a single, dedicated viewing window. Instead of cluttering the main price chart, it creates its own space to display complex data trends clearly.

Here is a breakdown of how the logic works in plain English:

The Core Components

The script processes three distinct types of market information simultaneously to give you a comprehensive view of price action:

1. Trend & Volatility Analysis (Bollinger Bands Logic) The tool looks at the "Median Price" of the assets over specific periods. It calculates two distinct boundaries:

  • Upper and Lower Lines: These represent the extremes of current market volatility. By calculating these relative to a moving average, the script helps identify how far the price is stretching away from its normal "average" behavior.
  • Trend Buffer: This identifies the broader momentum by comparing a short-term average against a much longer-term average. It essentially measures the "velocity" of the trend over time.

2. Momentum & Signal Tracking (MACD Logic) The script also incorporates a modified version of the MACD (Moving Average Convergence Divergence) logic. Rather than just showing you the standard momentum, it blends:

  • A difference between two fast-moving averages.
  • The gap between the standard MACD "Main" and "Signal" lines.

By combining these, the indicator provides a more nuanced look at whether the market is accelerating or slowing down in its current direction.

3. Dynamic Signal Visualization To make this data easy to read at a glance, the script converts raw numbers into a visual histogram:

  • Upward Movement: If the calculated momentum is increasing compared to the previous moment, the tool highlights this as an upward signal (shown in blue).
  • Downward Movement: If the momentum is decreasing, it captures this as a downward signal (shown in white).

How It Works Together

Instead of making you look at three different windows, this script merges these calculations into one cohesive display. It monitors the relationship between volatility (how wide the price swings are), the long-term trend (where the price is heading over months/weeks), and the immediate momentum (how fast it is moving right now).

The result is a multi-layered visual guide that helps traders see not just where the price is going, but how much "strength" or "exhaustion" is behind the current move.

Indicators Used
Moving average indicatorBollinger bands indicatorMACD Histogram
Miscellaneous
Implements a curve of type %1
7 Views
1 Downloads
0 Favorites
bbmacd
//+------------------------------------------------------------------+
//|                                                       BBMACD.mq4 |
//|                 Copyright 2014,  Roy Philips Jacobs ~ 31/07/2014 |
//|                                           http://www.gol2you.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,  Roy Philips Jacobs ~ 31/07/2014"
#property link      "http://www.gol2you.com ~ Forex Videos"
#property description "Forex Indicator Bollinger Bands® and MACD Awesome."
#property description "BBMACD is the Bollinger Bands® and MACD Awesome indicator in the same place at separate window."
#property version   "1.00"
#property strict
//--
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 clrGold
#property indicator_color2 clrGold
#property indicator_color3 clrRed
#property indicator_color4 clrNONE
#property indicator_color5 clrBlue
#property indicator_color6 clrWhite
#property indicator_color7 clrLightSlateGray
//--
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 2
#property indicator_width4 1
#property indicator_width5 3
#property indicator_width6 3
#property indicator_width7 1
//--
input string BBMACD="Copyright © 2014 3RJ ~ Roy Philips-Jacobs";
input int TrendPeriod=66;
//-- indicator_buffers
double bb2lubuf[];
double bb2llbuf[];
double trendbuf[];
double macdbuf[];
double macdupbuf[];
double macddnbuf[];
double cntrbuf[];
//--
int dev=2;
int maf=5;
int mas=34;
int bbper=20;
//--
string symbol;
string CopyR;
//--
void EventSetTimer();
//---
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator property
   symbol=_Symbol;
   CopyR="Copyright © 2014 3RJ ~ Roy Philips-Jacobs";
//---  
//--- indicator buffers mapping
   IndicatorBuffers(7);
   //---
   SetIndexBuffer(0,bb2lubuf);
   SetIndexBuffer(1,bb2llbuf);
   SetIndexBuffer(2,trendbuf);
   SetIndexBuffer(3,macdbuf);
   SetIndexBuffer(4,macdupbuf);
   SetIndexBuffer(5,macddnbuf);
   SetIndexBuffer(6,cntrbuf);
   //--- indicator line drawing
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,EMPTY,clrGold);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,EMPTY,clrGold);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,EMPTY,clrRed);
   SetIndexStyle(3,DRAW_NONE);
   SetIndexStyle(4,DRAW_HISTOGRAM,STYLE_SOLID,EMPTY,clrBlue);
   SetIndexStyle(5,DRAW_HISTOGRAM,STYLE_SOLID,EMPTY,clrWhite);
   SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,EMPTY,clrLightSlateGray);
   //--- name for DataWindow and indicator subwindow label
   SetIndexLabel(0,"UpperLine");
   SetIndexLabel(1,"LowerLine");
   SetIndexLabel(2,"TrendLine");
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,"SignalUp");
   SetIndexLabel(5,"SignalDn");
   SetIndexLabel(6,NULL);
   //--
   IndicatorShortName("BBMACD");
   IndicatorDigits(Digits);
   //--
//---
   return(INIT_SUCCEEDED);
  }
//---  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//----
   EventKillTimer();
   GlobalVariablesDeleteAll();
//----
   return;
  }
//---
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   if(BBMACD!=CopyR) return(0); 
//---
   int i,limit;
   double prv=0.00,cur;
   bool up,dn;
//--- check for bars count
   if(rates_total<=TrendPeriod) return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0) limit++;
   //--
//--- counting from rates_total to 0 
   ArraySetAsSeries(bb2lubuf,true);
   ArraySetAsSeries(bb2llbuf,true);
   ArraySetAsSeries(trendbuf,true);
   ArraySetAsSeries(macdbuf,true);
   ArraySetAsSeries(macdupbuf,true);
   ArraySetAsSeries(macddnbuf,true);
   ArraySetAsSeries(low,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(open,true);
   //--
//--- main cycle
   for(i=limit-1; i>=0; i--)
     {
       //---
       trendbuf[i]=iMA(symbol,0,bbper,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(symbol,0,TrendPeriod,0,MODE_SMA,PRICE_MEDIAN,i);
       bb2lubuf[i]=(iBands(symbol,0,bbper,dev,0,PRICE_MEDIAN,1,i)-iMA(symbol,0,bbper,0,MODE_SMA,PRICE_MEDIAN,i));
       bb2llbuf[i]=(iBands(symbol,0,bbper,dev,0,PRICE_MEDIAN,2,i)-iMA(symbol,0,bbper,0,MODE_SMA,PRICE_MEDIAN,i));
       macdbuf[i]=(iMA(symbol,0,maf,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(symbol,0,mas,0,MODE_SMA,PRICE_MEDIAN,i))+
                  (iMACD(symbol,0,12,26,9,PRICE_CLOSE,MODE_MAIN,i)-iMACD(symbol,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,i));
       cur=macdbuf[i];
       cntrbuf[i]=0.00;
       //--
       if(cur>prv) {up=true; dn=false;}
       if(cur<prv) {dn=true; up=false;}
       //--
       if(up) {macdupbuf[i]=cur; macddnbuf[i]=0.00;}
       if(dn) {macddnbuf[i]=cur; macdupbuf[i]=0.00;}
       //--
       prv=cur;       
       //---
     }
   //---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

Comments