MACD lines and Metatrader

Hi all,

Could someone please tell me how to put the slow and fast MACD lines on Metatrader. All that I am getting right now is one MACD line and a histogram.

bump

Anyone?

Found it myself:

//+------------------------------------------------------------------+
//| Custom MACD+OsMA.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 3
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_color3 Silver
//---- indicator parameters
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,1);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2) && !SetIndexBuffer(2,ind_buffer3))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"MACD");
SetIndexLabel(1,"Signal");
SetIndexLabel(2,"OsMA");
//---- 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);
for(i=0; i<limit; i++)
ind_buffer3[i]=iOsMA(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,i);
//---- done
return(0);
}

Thanks alot. I appreciate that

I had the same dilemma, but then I figured that the bars represent the divergence/convergence of the 2 average lines. When the bar disappears in the baseline, this is when the lines have crossed!! When the bar above the baseline disappears and then reappears flipped upside-down below the baseline, the line have crossed and the short reversal has started.
Gigio

Check the ZeroLagMACD,more quickly than MACD
//±-----------------------------------------------------------------+
//| ZeroLag MACD.mq4 |
//| RD |
//| <[email protected]> |
//±-----------------------------------------------------------------+
#property copyright “RD”
#property link "[email protected]"
//----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int FastEMA = 12;
extern int SlowEMA = 25;
extern int SignalEMA = 9;
//---- buffers
double MACDBuffer[];
double SignalBuffer[];
double FastEMABuffer[];
double SlowEMABuffer[];
double SignalEMABuffer[];
//±-----------------------------------------------------------------+
//| Custom indicator initialization function |
//±-----------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(5);
SetIndexBuffer(0, MACDBuffer);
SetIndexBuffer(1, SignalBuffer);
SetIndexBuffer(2, FastEMABuffer);
SetIndexBuffer(3, SlowEMABuffer);
SetIndexBuffer(4, SignalEMABuffer);
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE,EMPTY);
SetIndexDrawBegin(0, SlowEMA);
SetIndexDrawBegin(1, SlowEMA);
IndicatorShortName(“ZeroLag MACD(” + FastEMA + “,” + SlowEMA + “,” + SignalEMA + “)”);
SetIndexLabel(0, “MACD”);
SetIndexLabel(1, “Signal”);
//----
return(0);
}
//±-----------------------------------------------------------------+
//| Custor indicator deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//±-----------------------------------------------------------------+
//| Custom indicator iteration function |
//±-----------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
if(counted_bars < 0)
return(-1);
if(counted_bars > 0)
counted_bars–;
limit = Bars - counted_bars;
double EMA, ZeroLagEMAp, ZeroLagEMAq;
for(int i = 0; i < limit; i++)
{
FastEMABuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
SlowEMABuffer[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
}
for(i = 0; i < limit; i++)
{
EMA = iMAOnArray(FastEMABuffer, Bars, FastEMA, 0, MODE_EMA, i);
ZeroLagEMAp = FastEMABuffer[i] + FastEMABuffer[i] - EMA;
EMA = iMAOnArray(SlowEMABuffer, Bars, SlowEMA, 0, MODE_EMA, i);
ZeroLagEMAq = SlowEMABuffer[i] + SlowEMABuffer[i] - EMA;
MACDBuffer[i] = ZeroLagEMAp - ZeroLagEMAq;
}
for(i = 0; i < limit; i++)
SignalEMABuffer[i] = iMAOnArray(MACDBuffer, Bars, SignalEMA, 0, MODE_EMA, i);
for(i = 0; i < limit; i++)
{
EMA = iMAOnArray(SignalEMABuffer, Bars, SignalEMA, 0, MODE_EMA, i);
SignalBuffer[i] = SignalEMABuffer[i] + SignalEMABuffer[i] - EMA;
}
return(0);
}
//±-----------------------------------------------------------------+

Blaz 86,

The information about the code that you posted above could you please explain where that code needs to be inputed. Sorry i am a total newbie and so confused.

Ofcourse,

Tools/MetaQuotes Language Editor, New/Custom Indicator, Choose a name, Next, Finish. And copy/paste… or… copy/paste it in notepad and svate with extension mq4 and put it in \MetaTrader 4\experts\indicators.

Restart MetaTrader and it’s done.

Thank you so much Blaz86 really appreciate it.

i still cant get it.

can u guys elaborate like cut from where till where and then paste it on the notepad with save ext.

sorry i’m too slow on forex.

Thanks. I will try the code too. I’ve been searching for MACD crosses indicator.

Dear blaz86, What on earth is that and how do you use it. Looks like a computer program to me, right?
Gerrie Venter