MACD_lines
Download scriptThis custom technical indicator is designed to help traders visualize the momentum and relationship between two different moving averages on a price chart. By analyzing the gap between these averages, it provides a clearer picture of whether a trend is strengthening, weakening, or potentially reversing.
How the Logic Works
The script operates by calculating three distinct layers of data to produce its visual output:
1. The Fast and Slow Moving Averages The tool begins by tracking two different types of "moving averages." One is a Fast Moving Average, which reacts quickly to recent price changes, and the other is a Slow Moving Average, which filters out minor price fluctuations to show the broader trend.
2. The MACD Line (The Difference) The primary visual component (the MACD) is created by subtracting the Slow Moving Average from the Fast Moving Average.
- When the Fast average is significantly higher than the Slow average, the indicator moves in one direction, suggesting upward momentum.
- When the Fast average drops below the Slow average, it moves in the opposite direction, suggesting downward momentum.
- The "gap" between these two averages essentially tells you how far apart the current price action is from its recent history.
3. The Signal Line (The Smoothing Effect) To make the data easier to read and to filter out "noise," the script takes all the data points from the MACD line calculated above and applies a final smoothing process. This creates a Signal Line.
How to Interpret the Results
By plotting both the MACD and the Signal Line in a separate window on your chart, you can observe their interactions:
- Trend Identification: You can see at a glance whether the price momentum is moving up or down based on the position of the lines.
- Crossovers: Traders often look for points where the MACD line crosses over the Signal Line. These intersections are frequently used as cues to identify potential shifts in market direction, such as a move from a bullish (upward) trend to a bearish (downward) trend, or vice versa.
In summary, this script simplifies complex price movements into two distinct lines that highlight the speed and strength of market trends, helping you see the "big picture" of price action more clearly.
//+------------------------------------------------------------------+
//| 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,0);
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