#property copyright "Arik Karish"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_color2 Lime
#property indicator_color3 Lime
#property indicator_color4 Lime

#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1


extern int Firstma_period = 1;
extern int Second_ma_Period = 2;
extern int First_ma_Method = MODE_EMA;
extern int Second_ma_Method = MODE_LWMA;
extern int First_ma_Applied_Price = PRICE_CLOSE;
extern int Second_ma_Applied_Price = PRICE_CLOSE;

bool Changer = TRUE;
string xxxxx = "";
double MA1[];
double MA2[];
double UpArrow[];
double DownArrow[];
bool bChanger = FALSE;
bool cChanger = FALSE;


int init() {
   SetIndexLabel(0,NULL); //NAME KILLER! <<
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   SetIndexLabel(3,NULL);
   SetIndexLabel(4,NULL);
   SetIndexLabel(5,NULL);
   SetIndexLabel(6,NULL);
   SetIndexLabel(7,NULL);
   SetIndexLabel(8,NULL);
   //////////////////////////////////////////////
   IndicatorShortName(" ");
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexStyle(2, DRAW_ARROW, EMPTY);
   SetIndexArrow(2, 233);
   SetIndexStyle(3, DRAW_ARROW, EMPTY);
   SetIndexArrow(3, 234);
   SetIndexBuffer(0, MA1);
   SetIndexBuffer(1, MA2);
   SetIndexBuffer(2, UpArrow);
   SetIndexBuffer(3, DownArrow);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));

   return (0);
}
			 			 	     			  			 	    	  	 		 												 	 	 	  	 	 		   			    	  		 			  	          	   		   			  		 						 		 				   			 		   			 		 	

int start() {
   
   //string character[256]; Don't lnow why this array is included, it doesn't get used.
   bool liner1;
   bool liner2;
   double double1;
   double double2;
   int XYZ;
   
   //for (int pix = 0; pix < 256; pix++) character[pix] = CharToStr(pix);
   
   
   int Counter = IndicatorCounted();
   if (Counter < 0) return (-1);
   if (Counter > 0) Counter--;
   int xct = Bars - Counter;
   for (int Count = xct; Count >= 0; Count--) {
      MA1[Count] = iMA(NULL, 0, Firstma_period, 0, First_ma_Method, First_ma_Applied_Price, Count);
      MA2[Count] = iMA(NULL, 0, Second_ma_Period, 0, Second_ma_Method, Second_ma_Applied_Price, Count);
      double2 = 0;
      liner1 = FALSE;
      liner2 = FALSE;
      XYZ = Count;
      while (XYZ <= Count + 9) {
         double2 += MathAbs(High[XYZ] - Low[XYZ]);
         XYZ++;
      }
      double1 = double2 / 10.0;
      liner1 = MA1[Count + 2] >= MA2[Count + 2] && MA1[Count + 3] <= MA2[Count + 3] 
               && MA1[Count+1] > MA2[Count+1];
      liner2 = MA1[Count + 2] <= MA2[Count + 2] && MA1[Count + 3] >= MA2[Count + 3]
               && MA1[Count+1] < MA2[Count+1];
      if (liner1) {
         UpArrow[Count + 1] = MA2[Count + 1] - 0.7 * double1;
         DownArrow[Count + 1] = EMPTY_VALUE;
         liner2 = FALSE;
      }
      if (liner2) {
         DownArrow[Count + 1] = MA2[Count + 1] + 0.7 * double1;
         UpArrow[Count + 1] = EMPTY_VALUE;
         liner1 = FALSE;
      }
      if ((!liner1) && !liner2) {
         DownArrow[Count + 1] = EMPTY_VALUE;
         UpArrow[Count + 1] = EMPTY_VALUE;
      }
      if (liner1 && (!(bChanger == TRUE)) && Count == 0 && Changer) {
         bChanger = TRUE;
         cChanger = FALSE;
         Alert(Symbol(), " ", Period(), "BUY BUY BUY");
         if (xxxxx != "") PlaySound(xxxxx);
      }
      if (liner2 && (!(cChanger == TRUE)) && Count == 0 && Changer) {
         bChanger = FALSE;
         cChanger = TRUE;
         Alert(Symbol(), " ", Period(), "SELL SELL SELL");
         if (xxxxx != "") PlaySound(xxxxx);
      }
   }
   return (0);
}