_i_MACD

This custom tool is designed to provide traders with a visual representation of market momentum by calculating the relationship between two different price averages. It simplifies complex price movements into three distinct visual elements that help identify potential trends and shifts in market sentiment.

How the Logic Works

The script operates through a three-step calculation process to generate its visual output:

1. Momentum Calculation (The MACD Line) First, the tool looks at the asset's closing prices over two different timeframes simultaneously. It calculates a "Fast" average and a "Slow" average. By subtracting the slow average from the fast average, the script determines the momentum of the market. If the fast average is significantly higher than the slow average, it suggests upward momentum; if it is lower, it suggests downward momentum. This difference is plotted as the primary line on your chart.

2. The Signal Smoothing (The Signal Line) To make the data easier to interpret, the tool takes that "Momentum" result and performs a second calculation. It creates a moving average of the momentum itself. This acts as a "Signal" line, smoothing out minor price fluctuations to help traders identify the overall direction of the trend without being distracted by "noise" or small, erratic price jumps.

3. The Variance Gap (The Histogram) Finally, the script calculates the mathematical distance between the Momentum Line and the Signal Line. This difference is displayed as a histogram at the bottom of the indicator window.

  • When the histogram bars are large, it indicates a significant gap between current momentum and the average trend.
  • When the bars shrink or cross toward zero, it suggests that the momentum is stabilizing or potentially reversing.

Summary of Visual Components

  • MACD Line: Shows the immediate difference between fast and slow price trends.
  • Signal Line: Provides a smoothed path to help identify long-term direction.
  • Histogram: Visually highlights the distance between the two lines, making it easier to spot where momentum is accelerating or slowing down.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
_i_MACD
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, Doji Starr"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Indigo
#property  indicator_color2  Red
#property  indicator_color3  Silver
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];
double     ind_buffer3[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2) && !SetIndexBuffer(2,ind_buffer3))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("_i_MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"Histogram");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      ind_buffer1[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
//---- difference counted in the 3-rd buffer
   for(i=0; i<limit; i++)
      ind_buffer3[i]=ind_buffer1[i]-ind_buffer2[i];
//---- done
   return(0);
  }

Comments