This tool is a specialized technical analysis indicator designed to help traders identify momentum and trend changes in the financial markets. It builds upon the classic Moving Average Convergence Divergence (MACD) framework but replaces standard smoothing methods with a more responsive mathematical approach.
Core Logic Overview
The primary objective of this script is to compare two different price averages to see if they are converging (moving toward each other) or diverging (moving away from each other). By analyzing the distance between these two averages, traders can gauge the strength and direction of an underlying trend.
Key Components of the Logic:
-
Enhanced Smoothing (TEMA): Unlike standard indicators that may lag behind current price action, this script utilizes the Triple Exponential Moving Average (TEMA). This mathematical formula is designed to reduce "lag" while still filtering out market noise. It achieves this by calculating a series of overlapping averages and subtracting them from one another, resulting in a much faster reaction to sudden price movements than a traditional moving average.
-
The MACD Line: The script calculates two distinct TEMA values based on different timeframes (defined by the "Fast" and "Slow" settings). By subtracting the slow average from the fast average, it produces a primary line. When this line is above zero, it generally suggests bullish momentum; when below zero, it suggests bearish momentum.
-
The Signal Line: To help filter out minor fluctuations, the script takes the resulting MACD line and applies a secondary smoothing process (a Simple Moving Average). This creates a "Signal" line. When the MACD line crosses over this Signal line, it is often interpreted by traders as a potential entry or exit point for a trade.
-
The Visual Histogram: Finally, the script calculates the mathematical difference between the MACD line and the Signal line. This result is displayed as a histogram (a series of vertical bars).
- If the MACD line is above the Signal line, the bars grow upward in one color.
- If the MACD line falls below the Signal line, the bars grow downward in another color.
Summary for the User
In simple terms, this script acts as a "momentum tracker." It uses advanced math to smooth out market noise so that you can see the true direction of the price more clearly. By watching the relationship between the lines and the height of the histogram bars, you can more quickly identify when a trend is gaining strength or when it is beginning to exhaust itself.
//+------------------------------------------------------------------+
//| MACD_TEMA.mq4 |
//| Copyright © 2007, Robert Hill |
//| Standard MACD modified to use TEMA instead of EMA |
//| |
//| Based on the formula developed by Patrick Mulloy |
//| |
//| It can be used in place of EMA or to smooth other indicators. |
//| |
//| TEMA = 3 * EMA - 3 * (EMA of EMA) + EMA of EMA of EMA |
//| |
//+------------------------------------------------------------------+
#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 Aqua
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double MACD_buffer[];
double Signal_buffer[];
double HistogramBufferUp[];
double HistogramBufferDown[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(0,MACD_buffer);
SetIndexDrawBegin(0,SlowEMA);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(1,Signal_buffer);
SetIndexDrawBegin(1,SignalSMA);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(2,HistogramBufferUp);
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
SetIndexBuffer(3,HistogramBufferDown);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD_TEMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"Histogram");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
double temp;
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++)
MACD_buffer[i]=iCustom(NULL, 0, "TEMA_RLH", FastEMA, 2, i)- iCustom(NULL, 0, "TEMA_RLH", SlowEMA, 2, i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
Signal_buffer[i]=iMAOnArray(MACD_buffer,Bars,SignalSMA,0,MODE_EMA,i);
//---- done
for(i=0; i<limit; i++)
{
HistogramBufferUp[i] = 0;
HistogramBufferDown[i] = 0;
temp = MACD_buffer[i] - Signal_buffer[i];
if (temp >= 0)
HistogramBufferUp[i] = temp;
else
HistogramBufferDown[i] = temp;
}
return(0);
}
Comments