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

This tool is designed as a visual momentum indicator for financial charts, specifically engineered to help traders identify the underlying strength and direction of price movements. By analyzing the relationship between different moving averages, it provides a clear, color-coded representation of market trends.

Core Logic and Mechanics

The script operates by calculating two primary mathematical components:

  • The MACD Line: The tool first calculates the difference between a fast-moving average (reacting quickly to price changes) and a slow-moving average (tracking long-term trends). This difference tells the user whether the current momentum is accelerating or slowing down relative to recent history.
  • The Signal Line: It then takes that MACD data and applies a second smoothing calculation over it. This acts as a "buffer" or a baseline, helping to filter out market noise and identify more significant shifts in behavior.

Visual Interpretation

Instead of simply displaying a single line, the script interprets the relationship between these two components to generate a distinct visual output:

  1. Trend Detection: The logic compares the current value of the MACD against its previous value. If the momentum is increasing, the script identifies an "upward" movement; if it is decreasing, it identifies a "downward" movement.
  2. Dynamic Histogram: The tool uses these movements to populate a multi-colored histogram in a separate window below your main chart:
    • When the trend is moving upward, the indicator highlights this activity with one color (Magenta).
    • When the trend shifts downward, it switches to another color (Yellow) to provide an immediate visual cue of the reversal.
  3. Magnitude Scaling: The final values are scaled by a factor of three. This amplifies the visual height of the bars, making it significantly easier for the user to see the intensity of price swings and the speed of market reversals at a glance.

Summary for the User

Essentially, this script acts as a "momentum speedometer." It looks at how fast the price is moving compared to its recent past and translates that data into a color-coded bar chart. This allows you to quickly see not just where the price is going, but how much strength is behind that move, making it easier to spot potential trend changes before they become obvious on a standard price candle chart.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
MACD-2
//+------------------------------------------------------------------+
//| 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 Magenta
#property indicator_color2 Yellow
#property indicator_color3 White
#property indicator_color4 Yellow
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalEMA=8;
//---- 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,2);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
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");
//---- 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