MACD line

This custom technical indicator is designed to help traders visualize market momentum and identify potential shifts in price trends by calculating the relationship between two different moving averages. Unlike standard versions of this tool, it utilizes specific customized parameters to smooth out market noise and provide a clearer picture of long-term price behavior.

Core Logic Overview

The tool operates by performing three distinct mathematical steps:

1. Trend Identification (Fast vs. Slow) The script tracks two different "moving averages"—which are essentially smoothed versions of the market price over time.

  • The Fast Average reacts more quickly to recent price changes.
  • The Slow Average follows the broader, long-term trend of the market.

2. The MACD Line (The Gap) The primary line you see on the indicator represents the "gap" between these two averages. By subtracting the Slow Average from the Fast Average, the script shows how far apart they are currently moving.

  • When the gap widens, it indicates that momentum is increasing in a specific direction.
  • When the gap narrows, it suggests that the current trend may be losing steam.

3. The Signal Line (The Confirmation) To provide an extra layer of confirmation, the script takes the resulting MACD line and calculates yet another average based specifically on those results. This "Signal Line" acts as a secondary filter.

How to Interpret the Data

By using these three layers of logic, the indicator helps users look for two main types of movements:

  • Momentum Shifts: When the primary MACD line crosses over the Signal Line, it can suggest a change in the trend’s strength or direction.
  • Trend Strength: The physical distance between the lines helps traders gauge whether a move is becoming aggressive or beginning to plateau.

In summary, this script automates the complex math of comparing short-term speed against long-term history, providing a visual "pulse" of the market's current energy.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
MACD line
//+------------------------------------------------------------------+
//|                                                  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 2
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_width1  2
//---- indicator parameters
extern int FastEMA=38;
extern int SlowEMA=120;
extern int SignalSMA=20;
//---- indicator buffers
double     MacdBuffer[];
double     SignalBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(Digits+1);
//---- indicator buffers mapping
   SetIndexBuffer(0,MacdBuffer);
   SetIndexBuffer(1,SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
//---- 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_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++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments