//+------------------------------------------------------------------+
//|                                                         cADX.mq4 |
//|                                                      googolyenfx |
//|                               http://googolyenfx.blog18.fc2.com/ |
//+------------------------------------------------------------------+
#define LINK "http://googolyenfx.blog18.fc2.com/"

#property copyright "googolyenfx"
#property link      LINK

#property indicator_separate_window

#property  indicator_buffers 3
#property  indicator_color1  Turquoise
#property  indicator_color2  Lime
#property  indicator_color3  Red
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  2

extern int ADXLength = 8;
extern int PDILength = 13;
extern int MDILength = 13;

double adx[], pdi[], mdi[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	IndicatorBuffers(3);
	SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
	SetIndexBuffer(0,adx);
	SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
	SetIndexBuffer(1,pdi);
	SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
	SetIndexBuffer(2,mdi);
	IndicatorShortName("cADX " + LINK);
	
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
	int counted_bars = IndicatorCounted();
	if (counted_bars < 0) return(-1);
	int i = Bars - IndicatorCounted() - 1;
	
	while (i >= 0) {
		adx[i] = iADX(Symbol(), Period(), ADXLength, PRICE_CLOSE, MODE_MAIN, i);
		pdi[i] = iADX(Symbol(), Period(), PDILength, PRICE_CLOSE, MODE_PLUSDI, i);
		mdi[i] = iADX(Symbol(), Period(), MDILength, PRICE_CLOSE, MODE_MINUSDI, i);
		i--;
	}
	
	return(0);
}
//+------------------------------------------------------------------+