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

This custom indicator is designed to provide traders with a visual representation of market momentum by analyzing the relationship between two different moving averages. It operates in its own window below the main price chart, offering a clearer view of trend changes and potential reversal points.

Core Mechanics

The logic follows a three-step process to determine market direction:

1. Calculating the Difference (The MACD Base) The script first looks at two different types of averages: a "Fast" average and a "Slow" average. By subtracting the Slow average from the Fast average, the tool identifies the gap between short-term price action and long-term price trends. This difference tells the user whether the market is accelerating in one direction or slowing down.

2. Creating the Signal Line The script then takes that difference calculated in the first step and applies a third moving average to it. This creates what is known as a "Signal Line." Think of this as a smoothed version of the momentum; it helps filter out minor market "noise" so that traders can see the broader movement more clearly.

3. Visualizing Momentum (The Histogram) To make the data easy to read, the script compares the current difference against the previous difference. It then visualizes this result as a histogram:

  • Directional Identification: The tool detects whether the momentum is increasing or decreasing relative to the previous period.
  • Dynamic Coloring: Based on the direction of the move, it assigns colors to the bars. Typically, these are used to distinguish between bullish (upward) momentum and bearish (downward) momentum.
  • Magnification: The script multiplies the final values by a factor of three. This is done to make the visual fluctuations more prominent and easier for the human eye to track on the chart.

Summary for the Trader

Instead of just showing you raw price numbers, this tool translates complex price movements into a color-coded histogram. It allows you to quickly see if the market's current "speed" is gaining strength or losing steam, helping you identify potential entries and exits based on the shift in momentum.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
MACD-2_v1
//+------------------------------------------------------------------+
//| 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