Author: Copyright � 2005, MetaQuotes Software Corp.
mc

This tool is designed to help traders visualize momentum and identify potential shifts in the market's direction by analyzing price trends over time. It creates a secondary visual window below the main price chart, providing two distinct lines that help filter out market "noise" to reveal underlying patterns.

Core Logic Overview

The script works by comparing two different types of moving averages. A moving average is essentially a tool that smooths out price fluctuations to show the general direction of the market. By looking at two different versions of these averages simultaneously, the tool can tell us how fast or slow the price is moving.

1. The Primary Trend Line (MACD) The first part of the logic calculates the difference between a "fast" moving average and a "slow" moving average.

  • The Fast average reacts quickly to recent price changes.
  • The Slow average takes more time to adjust and represents the broader trend.

When the fast average is significantly higher than the slow average, it suggests upward momentum. When it is lower, it suggests downward momentum. The difference between these two is plotted as the first line in the indicator window.

2. The Signal Line To make this data even easier to interpret, the script takes that primary trend calculation and applies a third layer of smoothing. It calculates a simple average of the primary trend line over a specific period. This creates a secondary "Signal" line.

How it is used visually

By comparing these two lines, traders can look for specific interactions:

  • Momentum Strength: When the lines move away from each other, it indicates that the current price trend is gaining strength.
  • Trend Reversals: Traders often watch for the moments when the primary line crosses over the signal line. A crossover can serve as a visual cue that the momentum is shifting—for example, moving from an upward trend to a downward one, or vice versa.

In summary, this script transforms complex price movements into a simplified visual map, allowing you to see the "health" and "speed" of a market trend at a single glance.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
mc
//+------------------------------------------------------------------+
//|                                                           mc.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Blue
#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_LINE,STYLE_SOLID,1);
   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("+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