Navigation:Home > Content >

#14xMACD_Colored_v22.mq4

Time: 2014-03-19 | Download file:#14xMACD_Colored_v22.mq4

//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2007, Herb Spirit, Inc."
#property  link      "http://www.herbspirit.com/mql"

#define INDICATOR_NAME		"MACD_Colored"
#define INDICATOR_VERSION	"v102"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Lime
#property  indicator_color2  Red
#property  indicator_color3  Yellow
#property  indicator_color4  Silver
#property  indicator_style4  STYLE_DOT
#property  indicator_levelcolor  Gray
#property  indicator_levelstyle  STYLE_DOT
//---- indicator parameters
extern int FastEMA=5;
extern int SlowEMA=13;
extern int SignalSMA=1;
extern double MinDiff=0;
extern int FontSize=8;
extern color FontColor=Silver;
//---- indicator buffers
double     MacdBuffer[];
double     MacdBufferUp[];
double     MacdBufferDn[];
double     MacdBufferEq[];
double     SignalBuffer[];

//bool firsttime=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexDrawBegin(1,SignalSMA);
   IndicatorDigits(1);
//---- indicator buffers mapping
   SetIndexBuffer(0,MacdBufferUp);
   SetIndexBuffer(1,MacdBufferDn);
   SetIndexBuffer(2,MacdBufferEq);
   SetIndexBuffer(3,SignalBuffer);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName(WindowExpertName()+" ("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0,"MACD UP");
   SetIndexLabel(1,"MACD DN");
   SetIndexLabel(2,"MACD EQ");
   SetIndexLabel(3,"Signal");
//---- initialization done
   return(0);
}

int deinit()
{
	string objname=WindowExpertName()+","+Symbol()+","+Period();
	ObjectDelete(objname);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   limit=MathMin(Bars-SlowEMA,Bars-counted_bars+1);
//   if(!firsttime)
//   	Print("LIMIT=",limit);
   ArrayResize(MacdBuffer,limit);
   ArraySetAsSeries(MacdBuffer,true);
//---- macd counted in the 1-st buffer
   for(int i=0;i=0;i--)
   {
   	if(MathAbs(MacdBuffer[i]-MacdBuffer[i+1])MacdBuffer[i+1])
	   	{
   			MacdBufferUp[i]=MacdBuffer[i];
   			MacdBufferDn[i]=0;
   			MacdBufferEq[i]=0;
	   	}
   		else
   		{
   			MacdBufferDn[i]=MacdBuffer[i];
	   		MacdBufferUp[i]=0;
   			MacdBufferEq[i]=0;
   		}
   	}
   }
//---- signal line counted in the 2-nd buffer
   for(i=0; i        

Recommend