Author: Copyright ?2004, MetaQuotes Software Corp.
MACD-2_v2

The MACD-2 indicator is a technical analysis tool designed to help traders identify momentum and potential trend reversals by calculating the relationship between two different moving averages of a currency pair's price. It provides a visual representation of whether the market is gaining strength or losing steam, making it easier to spot shifts in price action.

How the Logic Works

The script operates through a three-step calculation process to translate raw price data into actionable visual signals:

1. Measuring Price Velocity (The Core Difference) The indicator begins by comparing two "Exponential Moving Averages" (EMAs). One is calculated over a fast period and the other over a slightly slower period. By subtracting the slower average from the faster one, the script determines the distance between these two lines. This difference represents the market's immediate momentum: if the fast line is significantly above the slow line, it suggests upward pressure; if it is below, it suggests downward pressure.

2. Creating the Signal Smoothing To prevent "noisy" data from creating false signals, the script takes that initial momentum value and calculates a second moving average (the Signal Line) based on the momentum itself. This smoothing process helps filter out minor price fluctuations, allowing traders to see the broader direction of the trend more clearly.

3. Determining Directional Color Coding The final logic step determines how the data is displayed on your chart. The script compares the current momentum value against its previous value:

  • Upward Momentum: If the current difference is increasing compared to the previous point, the indicator identifies an upward trend and highlights it in Lime Green.
  • Downward Momentum: If the difference is decreasing or falling, the indicator identifies a downward trend and highlights it in Red.

Summary for Traders

Essentially, this tool acts as a "momentum speedometer." Instead of just looking at where the price is, it shows you how fast it is moving and in which direction. The visual histogram allows you to see at a glance whether the market is accelerating (growing bars) or decelerating (shrinking bars), providing a clear distinction between bullish and bearish sentiment.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
MACD-2_v2
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| macd-2.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 4
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 Black
#property indicator_color4 Black
//---- indicator parameters
extern int FastEMA=13;
extern int SlowEMA=17;
extern int SignalEMA=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(5);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,1);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2 );
SetIndexDrawBegin(0,SignalEMA);
SetIndexDrawBegin(1,SignalEMA);
//---- 4 indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) &&
!SetIndexBuffer(1,ind_buffer2) &&
!SetIndexBuffer(2,ind_buffer3) &&
!SetIndexBuffer(3,ind_buffer4))
Print("cannot set indicators\' buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD-2 ("+FastEMA+","+SlowEMA+","+SignalEMA+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Oscillator |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
double prev,current;
//---- 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 additional buffer
for(int i=0; i<limit; i++)
ind_buffer3[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 additional buffer
for(i=0; i<limit; i++)
ind_buffer4[i]=iMAOnArray(ind_buffer3,Bars,SignalEMA,0,MODE_EMA, i);
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=ind_buffer3[i]-ind_buffer4[i];
prev=ind_buffer3[i+1]-ind_buffer4[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
ind_buffer2[i]=3*current;
ind_buffer1[i]=0.0;
}
else
{
ind_buffer1[i]=3*current;
ind_buffer2[i]=0.0;
}
}
return(0);
}

Comments