Hello.
I need the MACD indicator
Well, not really.
By accident I plotted two different MACD indicators on the same chart and what I saw was a little confusing. So, I added a third one.
As you can see in the picture.
From above to below.
MACD 1 is the normal code of Metaquotes MACD standar which comes with the software. With the addition of the histogram.
MACD 2 is a popular version called imacd or realmacd
MACD 3 is Metaquotes "pure" MACD.
If you take a little attention to the picture, the slope of signal line in MACD 2 (middle) is different.
After saw that the first thing comes to my mind was: wrong code.
But, I decided to compare with another charting software to discard any doubt and ouch. VTS have the slope like the middle MACD, also Accucharts, also TS2ki and other one.
Also, to confirm the question I move to a big TF and avoid possible differences in the close of the candles.
Still in doubt I´d take little research. I don´t have the phone of Mr Appel, so I have to search in google.
In this link I´ve found nice material to start.
http://tadoc.org/indicator/MACD.htm
Then I was to Investopedia and found some articles, here´s a cut:
Quote:
|
To completely understand the MACD indicator one needs to recognize that the relationship between the fast line and the slow line is of the utmost importance. The fast line results from the difference between the 26-day EMA of the closing prices subtracted from the 12-day EMA of the closing prices giving the calculation for the fast line. The slow signal is a moving average of the fast line. You can determine the slow signal by calculating the nine-day EMA of the fast line, and this is often referred to as the moving average of the fast line. The calculation for the fast line is 12 and 26 days, or in some cases, weeks, but you will find that all software programs available will use days rather than weeks. The defaults are easily changed if the technician wishes to changes the time period.
|
But lucky, I have the article The MACD indicator revisited. And what´s Mr Ehlers says:
Quote:
|
A 26-day EMA is the first moving average and a 13-day EMA is the second moving average in a traditional MACD. The MACD line is formed by subtracting the long (first) moving average from the short (second) moving average. A signal line is formed by smoothing the MACD line with a third EMA. The third moving average is usually a 10-day EMA
|
Also, the Whealt-lab guys says:
Quote:
Calculation
MACD is constructed by subtracting the value of a 26 day Exponential Moving Average (EMA) from a 12 period EMA. The shorter EMA is constantly converging toward, and diverging away from, the longer EMA. This causes MACD to oscillate around the zero level.
MACD line = EMA(12, close) – EMA(26, close)
MACD Signal = EMA(9, MACD Line)
EMA= Exponential Moving Average
MACD line = MACD fast line, displayed as a solid line on the chart
MACD Signal = MACD signal line or slow line, displayed as a dashed line on the chart
|
Also, take a look at the code of IMACD.
PHP Code:
//+------------------------------------------------------------------+
//| MACD.mq4 |
//| Copyright © 2005, David W. Thomas |
//| mailto:davidwt@usa.net |
//+------------------------------------------------------------------+
// This is the correct computation and display of MACD.
#property copyright "Copyright © 2005, David W. Thomas"
#property link "mailto:davidwt@usa.net"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
//---- input parameters
extern int FastMAPeriod=12;
extern int SlowMAPeriod=26;
extern int SignalMAPeriod=9;
//---- buffers
double MACDLineBuffer[];
double SignalLineBuffer[];
double HistogramBuffer[];
//---- variables
double alpha = 0;
double alpha_1 = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicators
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MACDLineBuffer);
SetIndexDrawBegin(0,SlowMAPeriod);
SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(1,SignalLineBuffer);
SetIndexDrawBegin(1,SlowMAPeriod+SignalMAPeriod);
SetIndexStyle(2,DRAW_HISTOGRAM);
SetIndexBuffer(2,HistogramBuffer);
SetIndexDrawBegin(2,SlowMAPeriod+SignalMAPeriod);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastMAPeriod+","+SlowMAPeriod+","+SignalMAPeriod+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
//----
alpha = 2.0 / (SignalMAPeriod + 1.0);
alpha_1 = 1.0 - alpha;
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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;
for(int i=limit; i>=0; i--)
{
MACDLineBuffer[i] = iMA(NULL,0,FastMAPeriod,0,MODE_EMA,PRICE_CLOSE,i) - iMA(NULL,0,SlowMAPeriod,0,MODE_EMA,PRICE_CLOSE,i);
SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1];
HistogramBuffer[i] = MACDLineBuffer[i] - SignalLineBuffer[i];
}
//----
return(0);
}
//+------------------------------------------------------------------+