MACD 5-34-5
Download scriptThis custom technical indicator is designed to provide traders with a visual representation of momentum and trend direction by calculating the relationship between two different moving averages. Unlike standard versions, this specific script allows for personalized settings to tailor the sensitivity of the data to different market conditions.
Core Logic and Mechanics
The indicator operates through a three-step mathematical process to generate its visual output:
1. Establishing the Baseline Trends The script first looks at the closing prices of the asset to calculate two distinct "moving averages."
- A Fast Moving Average tracks short-term price changes quickly.
- A Slow Moving Average tracks longer-term price trends more smoothly.
2. Calculating the Momentum (The Histogram) By subtracting the Slow Moving Average from the Fast Moving Average, the script identifies the "gap" between short-term and long-term momentum.
- When the fast trend is significantly higher than the slow trend, it indicates upward momentum.
- When the fast trend falls below the slow trend, it indicates downward momentum. This result is plotted on your chart as a histogram, providing a quick visual cue of whether the current price movement is accelerating or decelerating.
3. Generating the Signal Line To help filter out "noise" and identify specific entry points, the script takes the momentum data (the histogram values) and performs a second calculation on them. It applies a Simple Moving Average specifically to the histogram itself. This creates a "Signal Line," which acts as a smoothed guide.
How to Interpret the Visuals
The tool provides two primary visual components:
- The Histogram: Shows the immediate strength of the trend.
- The Signal Line: Helps identify potential turning points. When the histogram crosses over or under this signal line, it often suggests a shift in the prevailing market direction.
By adjusting the user-defined parameters (Fast, Slow, and Signal periods), you can modify how reactive or conservative the indicator behaves, making it adaptable to various trading styles ranging from fast-paced scalping to long-term trend following.
//+------------------------------------------------------------------+
//| 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 Lime
#property indicator_color2 Red
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=34;
extern int SignalSMA=5;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
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