#property copyright "Andrej Kidric, September 2013"
#property link      "http://www.magnates.org.uk"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Black

//#include <stdliba.mqh>
#import "stdliba.ex4"
   int MyKidric1(){return(1);} // 8DECE2657DA547300B997B3AF61D4057
   int MyKidric2(){return(2);} // D5A9B32B6B5E083F131E4F5E5973793C
   int MyKidric3(){return(0);} // C1C4134A2DF74388AE4884F78B9BA083
   int ma(){return(89);} // B74DF323E3939B563635A2CBA7A7AFBA
#import

double G_ibuf_76[];
double G_ibuf_80[];
double G_ibuf_84[];
string G_text_88 = "";
string G_text_96 = "";
extern string stringline = "Color line";
extern color downc1a = Red;
extern color upc1a = Lime;
double G_ibuf_120[];
double G_ibuf_124[];
extern bool Gap_Kidric = FALSE;
int Gi_132 = 15;//15
extern int GapSize = 20;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   int Li_0 = MyKidric1();
   int Li_4 = MyKidric2();
   int Li_8 = MyKidric3();
   IndicatorBuffers(5);
   SetIndexBuffer(Li_8, G_ibuf_76);
   ArraySetAsSeries(G_ibuf_76, TRUE);
   SetIndexBuffer(Li_0, G_ibuf_80);
   ArraySetAsSeries(G_ibuf_80, TRUE);
   SetIndexBuffer(4, G_ibuf_84);
   ArraySetAsSeries(G_ibuf_84, TRUE);
   SetIndexStyle(Li_8, DRAW_LINE, STYLE_SOLID, 2, upc1a);//Li_4
   SetIndexStyle(Li_0, DRAW_LINE, STYLE_SOLID, 2, downc1a);//Li_4
   SetIndexStyle(Li_4, DRAW_ARROW, EMPTY, Li_4, upc1a);
   SetIndexArrow(Li_4, 233);
   SetIndexBuffer(Li_4, G_ibuf_120);
   SetIndexStyle(3, DRAW_ARROW, EMPTY, Li_4, downc1a);
   SetIndexArrow(3, 234);
   SetIndexBuffer(3, G_ibuf_124);
   IndicatorShortName("Hangus");
   return (0);
}
				  	    					 	  	 		    		   			  							 				    		  		 										  		  						     		  				    	  		  	 					 		 		 		 											 	 		 		 	
// 52D46093050F38C27267BCE42543EF60
int deinit() {
   ObjectDelete("MA");
   ObjectDelete("MA1");
   ObjectDelete("MA2");
   ObjectDelete("MA3");
   return (0);
}
		  	 	   	  			 			  		  		 	   	  	 				    							 		    						   		  	 							 		   				 			  		   		 	 							   		 	 	 					   		 	   			 	
// D954202506588335BC40071F1425E064
double f0_0(int Ai_0, int A_period_4) {
   int Li_8 = MyKidric1();
   int Li_12 = MyKidric2();
   int timeframe_16 = MyKidric3();
   int ma_method_20 = Li_12 + Li_8;
   return (iMA(NULL, timeframe_16,14 , timeframe_16, ma_method_20, 6, Ai_0));//A_period_4
}
			   	     				 	 		 		   			   		   					 	 				 	  		  	  						 			  			 							    		 					   		  		    					  	 		 										 			 	 	  		 	
// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double close_20;
   double open_28;
   double Ld_36;
   double Ld_44;
   int Li_60;
   int Li_unused_64;
   int Li_unused_68;
   double Lda_88[];
   double Lda_92[];
   int corner_0 = MyKidric1();
   int Li_4 = MyKidric2();
   int Li_8 = MyKidric3();
   int Li_12 = ma();
   int ma_method_16 = Li_4 + corner_0;
   int Li_52 = IndicatorCounted();
   int Li_56 = Li_52;
   if (Li_52 < Li_8) return (-1);
   if (Gap_Kidric) {
      if (Li_56 < Li_8) return (-corner_0);
      if (Li_56 > Li_8) Li_56--;
      Li_60 = Bars - Li_56;
      Li_unused_64 = Li_8;
      Li_unused_68 = Li_8;
      for (int Li_72 = Li_8; Li_72 <= Li_60; Li_72++) {
         close_20 = Close[Li_72 + corner_0];
         open_28 = Open[Li_72];
         Ld_36 = Li_8;
         Ld_44 = Li_8;
         if (close_20 < open_28) {
            Ld_36 = (open_28 - close_20) / Point;
            if (Ld_36 > GapSize) G_ibuf_124[Li_72] = High[Li_72] + Gi_132 * Point;
         }
         if (close_20 > open_28) {
            Ld_44 = (close_20 - open_28) / Point;
            if (Ld_44 > GapSize) G_ibuf_120[Li_72] = Low[Li_72] - Gi_132 * Point;
         }
      }
   }
   int Li_76 = Li_8;
   int period_80 = MathSqrt(Li_12);
   int Li_84 = Bars - Li_52 + Li_12 + corner_0;
   if (Li_84 > Bars) Li_84 = Bars;
   ArrayResize(Lda_88, Li_84);
   ArraySetAsSeries(Lda_88, TRUE);
   ArrayResize(Lda_92, Li_84);
   ArraySetAsSeries(Lda_92, TRUE);
   for (Li_76 = Li_8; Li_76 < Li_84; Li_76++) Lda_88[Li_76] = 2.0 * f0_0(Li_76, Li_12 / Li_4) - f0_0(Li_76, Li_12);
   for (Li_76 = 0; Li_76 < Li_84 - Li_12; Li_76++) G_ibuf_84[Li_76] = iMAOnArray(Lda_88, Li_8, period_80, Li_8, ma_method_16, Li_76);
   for (Li_76 = Li_84 - Li_12; Li_76 >= Li_8; Li_76--) {
      Lda_92[Li_76] = Lda_92[Li_76 + 1];
      if (G_ibuf_84[Li_76] > G_ibuf_84[Li_76 + 1]) Lda_92[Li_76] = corner_0;
      if (G_ibuf_84[Li_76] < G_ibuf_84[Li_76 + 1]) Lda_92[Li_76] = -corner_0;
      if (Lda_92[Li_76] > 0.0) {
         G_ibuf_76[Li_76] = G_ibuf_84[Li_76];
         if (Lda_92[Li_76 + 1] < 0.0) G_ibuf_76[Li_76 + corner_0] = G_ibuf_84[Li_76 + corner_0];
         G_ibuf_80[Li_76] = EMPTY_VALUE;
         G_text_88 = "UP";
         ObjectDelete("MA2");
         ObjectDelete("MA3");
         ObjectCreate("MA", OBJ_LABEL, Li_8, Li_8, Li_8);
         ObjectSetText("MA", G_text_88, 9, "Arial Black", upc1a);
         ObjectSet("MA", OBJPROP_CORNER, corner_0);
         ObjectSet("MA", OBJPROP_XDISTANCE, 7);
         ObjectSet("MA", OBJPROP_YDISTANCE, 84);
      } else {
         if (Lda_92[Li_76] < Li_8) {
            G_ibuf_80[Li_76] = G_ibuf_84[Li_76];
            if (Lda_92[Li_76 + 1] > 0.0) G_ibuf_80[Li_76 + 1] = G_ibuf_84[Li_76 + 1];
            G_ibuf_76[Li_76] = EMPTY_VALUE;
            G_text_96 = "DOWN";
            ObjectDelete("MA");
            ObjectDelete("MA1");
            ObjectCreate("MA2", OBJ_LABEL, Li_8, Li_8, Li_8);
            ObjectSetText("MA2", G_text_96, 9, "Arial Black", downc1a);
            ObjectSet("MA2", OBJPROP_CORNER, corner_0);
            ObjectSet("MA2", OBJPROP_XDISTANCE, 7);
            ObjectSet("MA2", OBJPROP_YDISTANCE, 84);
         }
      }
   }
   return (0);
}