MACD-Alt

This custom technical indicator is designed to help traders visualize market momentum and identify potential trend reversals by calculating the relationship between two different moving averages. Rather than just showing a single price line, it provides a dual-layered analysis of price speed and direction.

How the Logic Works

The script operates in two distinct stages to produce the visual data seen on your trading platform:

1. Calculating the Main Momentum (MACD) The tool first looks at two different types of "moving averages"—which are essentially smoothed versions of the market price. It compares a "Fast" average (reacting quickly to recent price changes) against a "Slow" average (reacting more gradually to long-term trends).

By subtracting the Slow average from the Fast average, the script calculates the distance between them. This result is displayed as a histogram:

  • When the difference is positive and growing, it suggests upward momentum.
  • When the difference is negative and shrinking, it suggests downward momentum.
  • When the difference crosses zero, it indicates a potential shift in the trend's direction.

2. Generating the Signal Line To filter out "noise" and help traders identify significant turning points, the script takes the results of the first step and runs them through a second calculation. It creates a "Signal Line," which is an average of the momentum itself over a specific period.

This second layer acts as a smoother guide. By observing how the main histogram interacts with this Signal Line, traders can look for specific "crossovers." For example, when the momentum moves from below the signal line to above it, it is often interpreted as a cue that buying pressure is increasing.

Summary of Visual Elements

  • The Histogram: Represents the raw difference between short-term and long-term price speeds. It shows you how much "energy" is behind the current move.
  • The Signal Line: Acts as a secondary stabilizer, helping you distinguish between minor price fluctuations and meaningful trend changes.
Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
MACD-Alt
/*-----------------------------+
|			       |
| 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  Silver
#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,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))
      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD-Alt("+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