MACD_v2
Download scriptThis custom trading tool is designed to provide a visual representation of market momentum by analyzing the relationship between two different moving averages. It acts as a secondary gauge on your chart to help identify whether price trends are accelerating or slowing down, making it easier to spot potential shifts in market direction.
How the Logic Works
The script functions through a three-step mathematical process:
1. Calculating Two Speed Tracks The tool first looks at the closing prices of an asset and calculates two distinct types of "Moving Averages." Think of these as two different ways of smoothing out price history:
- The Fast Average: This reacts quickly to recent price changes.
- The Slow Average: This takes a broader view of the price history, reacting more gradually.
2. Identifying the Momentum Gap (The MACD Line) By subtracting the Slow Average from the Fast Average, the script generates the primary visual element (the silver histogram).
- When the Fast Average is higher than the Slow Average, it indicates upward momentum.
- When it is lower, it suggests downward momentum.
- The distance between these two averages tells you the "strength" of the current trend.
3. Determining the Trend Signal (The Signal Line) To help filter out "noise" and provide a clearer picture, the script takes all those results from the previous step and calculates a third average—a Simple Moving Average of the momentum itself. This creates the second visual element (the red line).
How to Interpret the Results
By watching how these two components interact, traders can look for specific behaviors:
- Crossovers: When the momentum histogram crosses over the signal line, it often suggests a potential change in the trend's direction.
- Expansion and Contraction: When the histogram grows tall, it shows a strengthening trend; when it shrinks toward the signal line, it suggests the current move may be losing steam.
In essence, this script simplifies complex price data into a single visual window that highlights the "tug-of-war" between short-term price action and long-term trends.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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,3);
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