MACD Custom

MACD Custom

This script is a custom technical analysis tool designed to help traders identify momentum and potential trend reversals in the financial markets. It functions by calculating and displaying two distinct moving average components on a separate sub-window of your trading platform.

Core Logic and Functionality

The tool works by comparing two different types of "moving averages"—which are essentially smoothed versions of price data—to determine if an asset's price is accelerating or decelerating. Here is the step-by-step logic used:

1. Calculating the MACD Line The script first looks at the current closing prices of the asset. It calculates two different averages: a "Fast" average (which reacts quickly to recent price changes) and a "Slow" average (which tracks the broader, long-term trend). By subtracting the Slow average from the Fast average, the tool produces the primary indicator line (shown in Aqua).

  • What this tells you: When this line is above zero, it suggests bullish momentum; when it is below zero, it suggests bearish momentum.

2. Generating the Signal Line Once the first line is calculated, the script performs a second layer of analysis. It takes all the data points from the primary MACD line and applies a third moving average to them. This creates a "Signal" line (shown in Red).

  • What this tells you: The Signal line acts as a smoothed guide for the primary indicator. It helps filter out "noise" and provides a clearer picture of where the momentum is heading.

How Traders Use This Information

The main purpose of this logic is to identify "crossovers." When the Aqua line crosses above the Red line, it often suggests that upward momentum is gaining strength. Conversely, when the Aqua line crosses below the Red line, it can signal that downward pressure is increasing.

By visualizing these two interacting lines together, the script allows you to see not just where the price has been, but how fast it is moving in its current direction, providing a clearer map of market sentiment.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
MACD Custom
/*-----------------------------+
|			       |
| 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 2
#property  indicator_color1  Aqua
#property  indicator_color2  Red
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,STYLE_SOLID,STYLE_SOLID,0);
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
   if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD & Signal("+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();
//---- 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);
//---- done
   return(0);
  }

Comments