Forex



Go Back   Forex Trading > Downloads > Indicators - Metatrader 4
Forex Forum Register More recent Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-14-2007, 03:37 AM
Linuxser's Avatar
User Root
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 4,413
Blog Entries: 56
Linuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond repute
MACD Code - Question for programmers.

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>0counted_bars--;
   
limit Bars counted_bars;

   for(
int i=limiti>=0i--)
   {
      
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);
}
//+------------------------------------------------------------------+ 
Attached Images
File Type: gif macd.gif (17.0 KB, 450 views)

Last edited by Linuxser; 03-14-2007 at 04:26 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 03-14-2007, 04:47 AM
Linuxser's Avatar
User Root
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 4,413
Blog Entries: 56
Linuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond repute
Ok, now, let´see the a couple of things.

One big difference in the code of iMACD (I´m trying to contact them) is the way to calculate the signal line.

First, he add two vars

PHP Code:
    alpha 2.0 / (SignalMAPeriod 1.0);
    
alpha_1 1.0 alpha
and then he use this values to multiply the signal line.

Why? here´s the answer

PHP Code:
     SignalLineBuffer[i] = alpha*MACDLineBuffer[i] + alpha_1*SignalLineBuffer[i+1]; 
The technical explanation is: because

Mmm, wait a minute. Appel and all explanations says EMA, but I saw an SMA somewhere.

Where? In the original Metaquotes MACD, check by yourself.

Quote:
ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA, i);
Again the same question, who is right? who is wrong?

So, if we change just one letter we can obtain a line like this

Quote:
ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_EMA, i);

And the slope of the signal line start to be close with the aforementioned software.

Take a look at the next picture

Programmers, what you think?

Who is right? Who is wrong? I´m right? I´m wrong?

It´s bug in the Metaquotes MACD code?

macdg.gif
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 03-14-2007, 07:24 AM
Junior Member
 
Join Date: Feb 2007
Posts: 1
4x4ever is on a distinguished road
Looks like a bug in MetaQuotes MACD. Why don't you go to MQL4.com and submit this bug on their forum? Having said thata - it doesn't mean they will fix it. I have submitted at least 5 bugs with them and they refused to fix any of them...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 03-15-2007, 01:42 AM
Linuxser's Avatar
User Root
 
Join Date: May 2006
Location: Helliconia (Spring)
Posts: 4,413
Blog Entries: 56
Linuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond reputeLinuxser has a reputation beyond repute
Quote:
Originally Posted by 4x4ever
Looks like a bug in MetaQuotes MACD. Why don't you go to MQL4.com and submit this bug on their forum? Having said thata - it doesn't mean they will fix it. I have submitted at least 5 bugs with them and they refused to fix any of them...
Well. I have not much luck posting on that forum.

What other bugs did you find?

My solution is my own macd, see picture

First MACD in the picture is the original, other is mine.

macdlnx.gif.

Last edited by Linuxser; 03-15-2007 at 01:46 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
macd traditional, macd code


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to code? samahdi MetaTrader 2188 Yesterday 01:43 PM
Question for programmers onelesstick General Discussion 2 10-27-2006 09:09 PM


All times are GMT. The time now is 09:51 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.