geGapADX





//+------------------------------------------------------------------+
//|																geGapADX.mq4		|
//|                      Copyright © 2007, ver 1.0							|
//|                      Forte928           									|
//+------------------------------------------------------------------+
#property copyright "Forte928"
#property link      ""
#define		IndicatorName "geGapADX"

//#property indicator_chart_window
#property indicator_separate_window

//#property indicator_level1 1.4
//#property indicator_level2 1.2
//#property indicator_level3 1
//#property indicator_level4 0.8

#property indicator_buffers 4
#property indicator_color1 Tomato
#property indicator_color2 YellowGreen
#property indicator_color3 Wheat
#property indicator_color4 LightSeaGreen

extern int		WinSize	=3;
extern int		EMAPrd	=8;
extern int		Shift		=0;
extern int	 	Counter	=2000;

//double  FreqTOL  =0.0001;//Tolerance of frequency calculation for Method 1

double	FxView1[];
double	FxView2[];
double	FxView3[];
double	FxView4[];
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Work Variables ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int Ix;
int Sx;

double	TimeBuf1[];
double	TimeBuf2[];
double	TimeBuf3[];
double	TimeBuf4[];
double	TimeBuf5[];
double	TimeBuf6[];

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Initialization program Buffers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void	InitBufferam(int iBufferSize)
{
	ArrayResize(TimeBuf1,iBufferSize);
	ArrayResize(TimeBuf2,iBufferSize);
	ArrayResize(TimeBuf3,iBufferSize);
	ArrayResize(TimeBuf4,iBufferSize);
	ArrayResize(TimeBuf5,iBufferSize);
	ArrayResize(TimeBuf6,iBufferSize);
	return;
}
void	EmptyBufferam()
{
	ArrayInitialize(TimeBuf1,EMPTY_VALUE);
	ArrayInitialize(TimeBuf2,EMPTY_VALUE);
	ArrayInitialize(TimeBuf3,EMPTY_VALUE);
	ArrayInitialize(TimeBuf4,EMPTY_VALUE);
	ArrayInitialize(TimeBuf5,EMPTY_VALUE);
	ArrayInitialize(TimeBuf6,EMPTY_VALUE);
// -->
	return;
}
void	DoneBufferam()
{
	ArrayResize(TimeBuf1,0);
	ArrayResize(TimeBuf2,0);
	ArrayResize(TimeBuf3,0);
	ArrayResize(TimeBuf4,0);
	ArrayResize(TimeBuf5,0);
	ArrayResize(TimeBuf6,0);
	return;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Program Constants ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int		MaxPeriod=0;
int		CalcCount=0;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator initialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int init()
  {
//---- initialization program values  --------------------------------
	MaxPeriod=MathMax(EMAPrd,WinSize);
	InitBufferam(MaxCounter(Counter,MaxPeriod));
	CalcCount=InitCounter(Counter,MaxPeriod);
//---- initialization indicators -------------------------------------
	SetupChartLine(0,FxView1,0,1,"Gap"+WinSize);// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0);
	SetupChartLine(1,FxView2,0,1,"Plus");// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0);
	SetupChartLine(2,FxView3,0,1,"Minus");// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0);
	SetupChartLine(3,FxView4,0,1,"ADX");// SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); SetIndexBuffer(0,ValueBuf0);
   IndicatorShortName(IndicatorName+"("+WinSize+"("+EMAPrd+"))");
  	IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
	
//----
   return(0);
  }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Custom indicator deinitialization function ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int deinit()
  {
//----
	DoneBufferam();	
//----
   return(0);
  }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~V~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Start defination ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int start()
{
	if (!StartCounter(IndicatorName,Counter,CalcCount,MaxPeriod)) return(-1);
//------------------------------------------------------------------------------------
	EmptyBufferam();
//+-------------------------- Begin Cycle ---------------------------------------------------+\\
	for (Ix=CalcCount-1;Ix>=0;Ix--){
		TimeBuf1[Ix]=(High[iHighest(NULL,0,MODE_HIGH,WinSize,Ix)]-Low[iLowest(NULL,0,MODE_LOW,WinSize,Ix)])/Point;      // Çíà÷åíèå 0 áóôåðà íà i-îì áàðå
		if(Open[Ix+WinSize-1]>Close[Ix])          // Åñëè ñâå÷à ÷¸ðíàÿ..         
		TimeBuf1[Ix]=-TimeBuf1[Ix];        			// .. òî ðåâåðñ çíà÷åíèÿ    
		if (TimeBuf1[Ix]>=0) {
			TimeBuf2[Ix]=TimeBuf1[Ix];
			TimeBuf3[Ix]=0;
		}
		else {
			TimeBuf3[Ix]=-TimeBuf1[Ix];
			TimeBuf2[Ix]=0;
		}
	}
	EMAOnArray(TimeBuf2,TimeBuf4,EMAPrd,CalcCount);
	EMAOnArray(TimeBuf3,TimeBuf5,EMAPrd,CalcCount);
	for (Ix=CalcCount-1;Ix>=0;Ix--)
	{
		double Div=MathAbs(TimeBuf4[Ix]+TimeBuf5[Ix]);
		if(Div==0.00) TimeBuf6[Ix]=0;
		else TimeBuf6[Ix]=100*(MathAbs(TimeBuf4[Ix]-TimeBuf5[Ix])/Div);
	}
	ArrayCopy(FxView1,TimeBuf1,Shift,0,CalcCount);
	ArrayCopy(FxView2,TimeBuf4,Shift,0,CalcCount);
	ArrayCopy(FxView3,TimeBuf5,Shift,0,CalcCount);
	ArrayCopy(FxView4,TimeBuf6,Shift,0,CalcCount);
	
//----
   return(0);
  }
//-----------------------------------------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~														 InitCounter																		~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 int InitCounter(int iPreCount,int iMaxPeriod)
{
	// Rule 1
	//if ((Result==0)||(Result>Bars)) Result=Bars;
	int Result=MaxCounter(iPreCount,iMaxPeriod);
	// Rule 2
	if ((Result+iMaxPeriod)>Bars) Result=Bars-iMaxPeriod;
	// Rule 3
	if (Result<iMaxPeriod) Result=0;
	else Result=Result+iMaxPeriod;
	return(Result);
}
//------------------------------------------ StartCounter --------------------------
bool StartCounter(string WindowName,int iPreCount,int& iCalcCount,int iMaxPeriod)
{
	if ((iPreCount>iCalcCount)||(iPreCount==0)) iCalcCount=InitCounter(iPreCount,iMaxPeriod);
	if (iCalcCount==0) 
	{
		Alert(WindowName+" "+Symbol()+"("+Period()+") - Limited Calculate Period");
		return(false);
	}
	return(true);
	//int iBarCount=IndicatorCounted();
	//if (iBarCount>0) return(true);
	//Print("StartCounter");
	return(false);
}
//------------------------------------------ StartCounter --------------------------
int MaxCounter(int iPreCount,int iMaxPeriod)
{
	int Result=iPreCount;
	// Rule 1
	//if ((Result==0)||(Result>Bars)) Result=Bars;
	if (Result==0) Result=Bars-1;
	if (Result<iMaxPeriod) Result=iMaxPeriod;
	return(Result+iMaxPeriod);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~														 Style active Line																~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void SetupChartLine(int Index,double& ViewAy[],int Style,int Width,string Label)
{
	switch(Style)
	{
		case 0 : SetIndexStyle(Index,DRAW_LINE,STYLE_SOLID,Width);break;
		case 1 : SetIndexStyle(Index,DRAW_HISTOGRAM,STYLE_SOLID,Width);break;
		case 2 : SetIndexStyle(Index,DRAW_ARROW,STYLE_SOLID,Width);break;
		default : SetIndexStyle(Index,DRAW_LINE,STYLE_SOLID,Width);break;
	}
	if (Label!="") SetIndexLabel(Index,Label);
	SetIndexBuffer(Index,ViewAy);
	return(0);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//-------------------------------------------------------------------------------------------------
void EMAOnArray(double aySource[],double& ayResult[],int iPeriod,int iCount)
{
	double iMuver=2/(iPeriod*1.0+1);
	ayResult[iCount-1]=0;
   for(int Ex=iCount-2; Ex>=0; Ex--) {
   	ayResult[Ex]=ayResult[Ex+1]+iMuver*(aySource[Ex]-ayResult[Ex+1]);
   }
	return;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~





Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
Series array that contains close prices for each bar
Series array that contains open prices of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE
Implements a curve of type DRAW_HISTOGRAM
Implements a curve of type DRAW_ARROW


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen