//+------------------------------------------------------------------+
//|                                          Gann HiLo Activator.mq4 |
//|                                              lucidlamp@gmail.com |
//+------------------------------------------------------------------+

#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_style1 STYLE_SOLID
#property indicator_color2 Red
#property indicator_width2 1
#property indicator_style2 STYLE_SOLID

double ExtMapBuffer1[];
double ExtMapBuffer2[];

extern int R=14;

int Swing=0;

int init()
  {
		IndicatorBuffers(2);
		IndicatorShortName("Gann HiLo Activator");
		IndicatorDigits(Digits);
		SetIndexBuffer(0,ExtMapBuffer1);
		SetIndexStyle(0,DRAW_LINE);
		SetIndexLabel(0,"Long");
		SetIndexDrawBegin(0,R);
		SetIndexBuffer(1,ExtMapBuffer2);
		SetIndexStyle(1,DRAW_LINE);
		SetIndexLabel(1,"Sell");
		SetIndexDrawBegin(1,R);
  }

int deinit()
  {
  }

int start()
  {
		int iIndicatorCounted=IndicatorCounted();
		if(iIndicatorCounted<0)
			{
				return;
			}
		int iLimit=Bars-iIndicatorCounted;
		for(int i=iLimit;i>=0;i--)
			{
				double Value1a=iMA(NULL,0,R,0,MODE_SMA,PRICE_HIGH,i+1);
				double Value2a=iMA(NULL,0,R,0,MODE_SMA,PRICE_LOW,i+1);
				double Value1b=iMA(NULL,0,R,0,MODE_SMA,PRICE_HIGH,i+2);
				double Value2b=iMA(NULL,0,R,0,MODE_SMA,PRICE_LOW,i+2);
				if(Close[i]<Value2a && Close[i+1]>=Value2b)
					{
						Swing=-1;
					}
				if(Close[i]>Value1a && Close[i+1]<=Value1b)
					{
						Swing=1;
					}
				if(Swing==1)
					{
						ExtMapBuffer1[i]=Value2a;
						ExtMapBuffer2[i]=EMPTY_VALUE;
					}
				if(Swing==-1)
					{
						ExtMapBuffer1[i]=EMPTY_VALUE;
						ExtMapBuffer2[i]=Value1a;
					}
			}
  }