/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website: h ttP:/ /wwW .m e Ta quOtE s . N E T
   E-mail : s u p po r t@ m E T a Q u O T E s.n e T
*/

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red

int Gi_76 = 9;
int G_applied_price_80 = PRICE_CLOSE;
extern double Risk = 3.0;
int Gi_92 = 0;
extern int AlertMode = 0;
double G_ibuf_100[];
double G_ibuf_104[];
double G_ibuf_108[];
double G_ibuf_112[];
double G_ibuf_116[];
double G_ibuf_120[];
double G_ibuf_124[];
bool Gi_128 = FALSE;
bool Gi_132 = FALSE;
int Gi_136;

int init() {
   string Ls_unused_0;
   IndicatorBuffers(7);
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 233);
   SetIndexStyle(1, DRAW_ARROW);
   SetIndexArrow(1, 234);
   SetIndexStyle(2, DRAW_ARROW);
   SetIndexStyle(3, DRAW_ARROW);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS));
   IndicatorShortName("PriceChannel_Signal(" + Gi_76 + ")");
   SetIndexLabel(0, "UpSignal");
   SetIndexLabel(1, "DnSignal");
   SetIndexLabel(2, "UpRe-Entry");
   SetIndexLabel(3, "DnRe-Entry");
   SetIndexDrawBegin(0, Gi_76);
   SetIndexDrawBegin(1, Gi_76);
   SetIndexDrawBegin(2, Gi_76);
   SetIndexDrawBegin(3, Gi_76);
   SetIndexBuffer(0, G_ibuf_100);
   SetIndexBuffer(1, G_ibuf_104);
   SetIndexBuffer(2, G_ibuf_108);
   SetIndexBuffer(3, G_ibuf_112);
   SetIndexBuffer(4, G_ibuf_116);
   SetIndexBuffer(5, G_ibuf_120);
   SetIndexBuffer(6, G_ibuf_124);
   return (0);
}

int start() {
   double ima_12;
   double ima_20;
   double ima_28;
   double high_36;
   double low_44;
   string Ls_52;
   if (Bars <= Gi_76) return (0);
   int Li_4 = IndicatorCounted();
   if (Li_4 < 0) return (-1);
   if (Li_4 > 0) Li_4--;
   int Li_0 = Bars - Li_4;
   for (int Li_8 = Li_0; Li_8 >= 0; Li_8--) {
      ima_12 = iMA(NULL, 0, 1, 0, MODE_SMA, G_applied_price_80, Li_8);
      ima_20 = iMA(NULL, 0, 1, 0, MODE_SMA, G_applied_price_80, Li_8 + 1);
      ima_28 = iMA(NULL, 0, 1, 0, MODE_SMA, G_applied_price_80, Li_8 + 2);
      high_36 = High[iHighest(NULL, 0, MODE_HIGH, Gi_76, Li_8)];
      low_44 = Low[iLowest(NULL, 0, MODE_LOW, Gi_76, Li_8)];
      G_ibuf_116[Li_8] = high_36 - (33 - Risk) * (high_36 - low_44) / 100.0;
      G_ibuf_120[Li_8] = low_44 + (33 - Risk) * (high_36 - low_44) / 100.0;
      G_ibuf_124[Li_8] = G_ibuf_124[Li_8 + 1];
      if (ima_12 > G_ibuf_116[Li_8]) G_ibuf_124[Li_8] = 1;
      if (ima_12 < G_ibuf_120[Li_8]) G_ibuf_124[Li_8] = -1;
      if (G_ibuf_124[Li_8] > 0.0) {
         if (G_ibuf_124[Li_8 + 1] < 0.0) G_ibuf_100[Li_8] = Low[Li_8] - iATR(NULL, 0, Gi_76, Li_8) / 2.0;
         if (Gi_92 > 0 && ima_12 > G_ibuf_116[Li_8] && ima_20 <= G_ibuf_116[Li_8 + 1]) G_ibuf_108[Li_8] = Low[Li_8] - iATR(NULL, 0, Gi_76, Li_8) / 2.0;
         G_ibuf_104[Li_8] = EMPTY_VALUE;
         G_ibuf_112[Li_8] = EMPTY_VALUE;
      } else {
         if (G_ibuf_124[Li_8] < 0.0) {
            if (G_ibuf_124[Li_8 + 1] > 0.0) G_ibuf_104[Li_8] = High[Li_8] + iATR(NULL, 0, Gi_76, Li_8) / 2.0;
            if (Gi_92 > 0 && ima_12 < G_ibuf_120[Li_8] && ima_20 >= G_ibuf_120[Li_8 + 1]) G_ibuf_112[Li_8] = High[Li_8] + iATR(NULL, 0, Gi_76, Li_8) / 2.0;
            G_ibuf_100[Li_8] = EMPTY_VALUE;
            G_ibuf_108[Li_8] = EMPTY_VALUE;
         }
      }
      if (Li_8 == 0 && AlertMode > 0) {
         if (G_ibuf_124[Li_8 + 1] > 0.0 && Volume[0] > 1.0) {
            if (G_ibuf_124[Li_8 + 2] < 0.0 && (!Gi_128)) {
               Ls_52 = " " + Symbol() + " M" + Period() + ": Signal for BUY";
               Alert(Ls_52);
               Gi_128 = TRUE;
               Gi_132 = FALSE;
            }
            if (!(Gi_92 > 0 && G_ibuf_124[Li_8 + 2] > 0.0 && ima_20 > G_ibuf_116[Li_8 + 1] && ima_28 < G_ibuf_116[Li_8 + 2] && Time[Li_8] != Gi_136)) continue;
            Ls_52 = " " + Symbol() + " M" + Period() + ": Re-Entry for BUY";
            Alert(Ls_52);
            Gi_136 = Time[Li_8];
            continue;
         }
         if (G_ibuf_124[Li_8 + 1] < 0.0 && Volume[0] > 1.0) {
            if (G_ibuf_124[Li_8 + 2] > 0.0 && (!Gi_132)) {
               Ls_52 = " " + Symbol() + " M" + Period() + ": Signal for SELL";
               Alert(Ls_52);
               Gi_132 = TRUE;
               Gi_128 = FALSE;
            }
            if (Gi_92 > 0 && G_ibuf_124[Li_8 + 2] < 0.0 && ima_20 < G_ibuf_120[Li_8 + 1] && ima_28 > G_ibuf_120[Li_8 + 2] && Time[Li_8] != Gi_136) {
               Ls_52 = " " + Symbol() + " M" + Period() + ": Re-Entry for SELL";
               Alert(Ls_52);
               Gi_136 = Time[Li_8];
            }
         }
      }
   }
   return (0);
}
