//+------------------------------------------------------------------+
//| This MQL is generated by Expert Advisor Builder                  |
//|                http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/ |
//|                                                                  |
//|  In no event will author be liable for any damages whatsoever.   |
//|                      Use at your own risk.                       |
//|                                                                  |
//+------------------- DO NOT REMOVE THIS HEADER --------------------+

#property copyright "Expert Advisor Builder"
#property link      "http://sufx.core.t3-ism.net/ExpertAdvisorBuilder/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Red

extern int arrowSize = 2;
extern bool AlertON = True;

double upArrow[], dnArrow[];
double Dir[];
datetime lastAlert;

int init() {
	IndicatorBuffers(3);
	SetIndexBuffer(0,upArrow);
	SetIndexBuffer(1,dnArrow);
	SetIndexBuffer(2,Dir);
	SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,arrowSize);
	SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,arrowSize);
	SetIndexArrow(0,233);	
	SetIndexArrow(1,234);
	IndicatorDigits(Digits+1);
	lastAlert = Time[0];
	return(0);
}

int start() {
   int    limit;
   int    counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   if(counted_bars<1) ArrayInitialize(Dir,0.0);
   limit=Bars-counted_bars;
   for(int i=limit; i>0; i--) {
   		int Current = i;
   		int Order = 0;
		double Buy1_1 = iClose(NULL, 0, Current + 1);
		double Buy1_2 = iHigh(NULL, 0, Current + 2);
		double Buy2_1 = iClose(NULL, 0, Current + 0);
		double Buy2_2 = iHigh(NULL, 0, Current + 1);
		double Buy3_1 = iClose(NULL, 0, Current + 0);
		double Buy3_2 = iHigh(NULL, 0, Current + 2);

		double Sell1_1 = iClose(NULL, 0, Current + 1);
		double Sell1_2 = iLow(NULL, 0, Current + 2);
		double Sell2_1 = iClose(NULL, 0, Current + 0);
		double Sell2_2 = iLow(NULL, 0, Current + 1);
		double Sell3_1 = iClose(NULL, 0, Current + 0);
		double Sell3_2 = iLow(NULL, 0, Current + 2);
   		if (Buy1_1 <= Buy1_2 && Buy2_1 > Buy2_2 && Buy3_1 > Buy3_2) Order = 1;
   		if (Sell1_1 >= Sell1_2 && Sell2_1 < Sell2_2 && Sell3_1 < Sell3_2) Order = -1;
   		if(Order==0) Dir[i] = Dir[i+1];
   		else Dir[i] = Order;
   		if(Dir[i]!=Dir[i+1]){
   			if(Dir[i]==1) {
   		 		upArrow[i] = Low[i]-0.5*iATR(NULL,0,10,i+1);
   		 		if(Time[i]>lastAlert){
   		 			lastAlert = Time[i];
   		 			Alert("UP");
   		 		}
   		 	}
   			else if(Dir[i]==-1) {
   				dnArrow[i] = High[i]+0.5*iATR(NULL,0,10,i+1);
   		 		if(Time[i]>lastAlert){
   		 			lastAlert = Time[i];
   		 			Alert("DOWN");
   		 		}
   			}
   		}
   	}
   return(0);
}
//+------------------------------------------------------------------+