MACD_4_v1_v1

Download script
MACD_4_v1_v1

This custom technical indicator is designed to help traders analyze price momentum and identify potential trends in the financial markets. By utilizing three distinct layers of data, it provides a visual representation of whether a market is gaining strength, losing steam, or experiencing a shift in direction.

How the Logic Works

The tool operates by calculating the relationship between different moving averages—mathematical tools that smooth out price fluctuations to show the underlying trend. Here is the step-by-step breakdown of the logic:

1. The MACD Line (Trend Distance) The foundation of this indicator is the difference between two moving averages: a "Fast" average and a "Slow" average.

  • The Fast Average reacts quickly to recent price changes.
  • The Slow Average reacts more gradually to broader price movements. By subtracting the Slow Average from the Fast Average, the script creates the MACD Line. When this line is above zero, it suggests that short-term momentum is stronger than long-term momentum (bullish). When it is below zero, it suggests the opposite (bearish).

2. The Signal Line (Momentum Smoothing) To make the data easier to read and filter out "noise," the script takes the MACD Line created in the previous step and applies another moving average to it. This creates the Signal Line. This acts as a smoothed baseline; when the MACD Line crosses above or below this Signal Line, it is often interpreted by traders as a cue that a change in momentum is occurring.

3. The Histogram (The Gap) The final visual component is the Histogram, which represents the mathematical difference between the MACD Line and the Signal Line.

  • A tall histogram indicates a significant divergence between current momentum and the smoothed trend.
  • As the histogram bars shrink toward zero, it suggests that the momentum is losing its strength and may be preparing to reverse or consolidate.

Summary of Visual Outputs

The script organizes this data into three distinct visual elements on your chart:

  • A Primary Line (MACD): Shows the raw difference in momentum.
  • A Secondary Line (Signal): Provides a smoothed benchmark for the primary line.
  • A Histogram: Visually highlights the "gap" between these two lines, making it easier to see at a glance whether a trend is accelerating or slowing down.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
MACD_4_v1_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_color3  LightBlue
#property  indicator_style2  2
#property  indicator_width3  2
//---- indicator parameters
extern int Price=0;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=9;
//---- indicator buffers
double     MacdBuffer[];
double     SignalBuffer[];
double     HistoBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexDrawBegin(1,SignalEMA);
   SetIndexDrawBegin(2,SignalEMA);
   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,SignalBuffer);
   SetIndexBuffer(2,HistoBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalEMA+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
   SetIndexLabel(2,"Histo");
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- 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++)
      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,Price,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,Price,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      {
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalEMA,0,MODE_EMA,i);
      HistoBuffer[i]=MacdBuffer[i]-SignalBuffer[i];
      }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments