#property copyright "Copyright © 2013, Lucifer"
#property link      "Hell_Underground"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red

double G_ibuf_76[];
double G_ibuf_80[];
extern int Numberofbars = 2000;
double Gda_unused_88[];
extern int RSIPeriod = 12;
extern int CCIPeriod = 21;
extern int STKPeriod = 5;
extern int STDPeriod = 3;
extern int STSlowing = 2;
extern int STOBought = 60;
extern int STOVSold = 40;
extern int ADXPeriod = 34;
extern int BULSPeriod = 50;
extern int BEARPeriod = 50;
extern int BollingerbandsPeriod = 20;
extern int BollingerbandsShift = 0;
extern double BollingerbandsDeviation = 1.6;
extern bool Alerts = TRUE;
bool Gi_unused_152 = FALSE;
bool Gi_156 = FALSE;
bool Gi_160 = FALSE;
bool Gi_164 = FALSE;
bool Gi_168 = FALSE;
bool Gi_172 = FALSE;
bool Gi_unused_176 = FALSE;
bool Gi_180 = FALSE;
bool Gi_184 = FALSE;
bool Gi_188 = FALSE;
bool Gi_192 = FALSE;
bool Gi_196 = FALSE;
bool Gi_200 = FALSE;
bool Gi_204 = FALSE;
int Gi_208 = 0;
bool Gi_212 = FALSE;
bool Gi_216 = FALSE;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 221);
   SetIndexDrawBegin(0, Bars - Numberofbars);
   SetIndexBuffer(0, G_ibuf_76);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 222);
   SetIndexDrawBegin(1, Bars - Numberofbars);
   SetIndexBuffer(1, G_ibuf_80);
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Li_0;
   double irsi_36;
   double irsi_44;
   double icci_52;
   double icci_60;
   double istochastic_68;
   double istochastic_76;
   double istochastic_84;
   double istochastic_92;
   double iadx_100;
   double iadx_108;
   double iadx_116;
   double iadx_124;
   double ibullspower_132;
   double ibullspower_140;
   double ibearspower_148;
   double ibearspower_156;
   double Ld_172;
   double Ld_180;
   double ibands_192;
   double ibands_200;
   double ibands_208;
   double ibands_216;
   int Li_188 = IndicatorCounted();
   if (Li_188 < 0) return (-1);
   if (Li_188 > 0) Li_188--;
   int Li_164 = Bars - Li_188;
   for (int Li_168 = 0; Li_168 <= Li_164; Li_168++) {
      Li_0 = Li_168;
      Ld_172 = 0;
      Ld_180 = 0;
      for (Li_0 = Li_168; Li_0 <= Li_168 + 21; Li_0++) Ld_180 += MathAbs(High[Li_0] - Low[Li_0]);
      Ld_172 = Ld_180 / 10.0;
      irsi_36 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, Li_168);
      irsi_44 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, Li_168 + 1);
      icci_52 = iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, Li_168);
      icci_60 = iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, Li_168 + 1);
      istochastic_68 = iStochastic(NULL, 0, STKPeriod, STDPeriod, STSlowing, MODE_SMA, 0, MODE_MAIN, Li_168);
      istochastic_84 = iStochastic(NULL, 0, STKPeriod, STDPeriod, STSlowing, MODE_SMA, 0, MODE_MAIN, Li_168 + 1);
      istochastic_76 = iStochastic(NULL, 0, STKPeriod, STDPeriod, STSlowing, MODE_SMA, 0, MODE_SIGNAL, Li_168);
      istochastic_92 = iStochastic(NULL, 0, STKPeriod, STDPeriod, STSlowing, MODE_SMA, 0, MODE_SIGNAL, Li_168 + 1);
      iadx_100 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI, Li_168 + 1);
      iadx_116 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI, Li_168);
      iadx_108 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, Li_168 + 1);
      iadx_124 = iADX(NULL, 0, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, Li_168);
      ibullspower_132 = iBullsPower(NULL, 0, BULSPeriod, PRICE_CLOSE, Li_168);
      ibullspower_140 = iBullsPower(NULL, 0, BULSPeriod, PRICE_CLOSE, Li_168 + 1);
      ibearspower_148 = iBearsPower(NULL, 0, BEARPeriod, PRICE_CLOSE, Li_168);
      ibearspower_156 = iBearsPower(NULL, 0, BEARPeriod, PRICE_CLOSE, Li_168 + 1);
      ibands_192 = iBands(NULL, 0, BollingerbandsPeriod, BollingerbandsDeviation, BollingerbandsShift, PRICE_CLOSE, MODE_UPPER, Li_168);
      ibands_200 = iBands(NULL, 0, BollingerbandsPeriod, BollingerbandsDeviation, BollingerbandsShift, PRICE_CLOSE, MODE_LOWER, Li_168);
      ibands_208 = iBands(NULL, 0, BollingerbandsPeriod, BollingerbandsDeviation, BollingerbandsShift, PRICE_CLOSE, MODE_UPPER, Li_168 + 1);
      ibands_216 = iBands(NULL, 0, BollingerbandsPeriod, BollingerbandsDeviation, BollingerbandsShift, PRICE_CLOSE, MODE_LOWER, Li_168 + 1);
      if (Close[Li_168] > ibands_192 && Close[Li_168 + 1] >= ibands_208) {
         Gi_200 = FALSE;
         Gi_204 = TRUE;
      }
      if (Close[Li_168] < ibands_200 && Close[Li_168 + 1] <= ibands_216) {
         Gi_200 = TRUE;
         Gi_204 = FALSE;
      }
      if (ibullspower_132 > 0.0 && ibullspower_140 > ibullspower_132) {
         Gi_172 = FALSE;
         Gi_196 = TRUE;
      }
      if (ibearspower_148 < 0.0 && ibearspower_156 < ibearspower_148) {
         Gi_172 = TRUE;
         Gi_196 = FALSE;
      }
      if (iadx_100 < iadx_108 && iadx_116 > iadx_124) {
         Gi_168 = TRUE;
         Gi_192 = FALSE;
      }
      if (iadx_100 > iadx_108 && iadx_116 < iadx_124) {
         Gi_168 = FALSE;
         Gi_192 = TRUE;
      }
      if (istochastic_68 > istochastic_76 && istochastic_84 < istochastic_92 || istochastic_68 > STOVSold && istochastic_84 < STOVSold || istochastic_76 > STOVSold && istochastic_92 < STOVSold) {
         Gi_164 = TRUE;
         Gi_188 = FALSE;
      }
      if (istochastic_68 < istochastic_76 && istochastic_84 > istochastic_92 || istochastic_68 < STOBought && istochastic_84 > STOBought || istochastic_76 < STOBought &&
         istochastic_84 > STOBought) {
         Gi_164 = FALSE;
         Gi_188 = TRUE;
      }
      if (icci_52 > -100.0 && icci_60 < -100.0) {
         Gi_160 = TRUE;
         Gi_184 = FALSE;
      }
      if (icci_52 < 100.0 && icci_60 > 100.0) {
         Gi_160 = FALSE;
         Gi_184 = TRUE;
      }
      if (irsi_36 > 50.0 && irsi_44 < 50.0) {
         Gi_156 = TRUE;
         Gi_180 = FALSE;
      }
      if (irsi_36 < 50.0 && irsi_44 > 50.0) {
         Gi_156 = FALSE;
         Gi_180 = TRUE;
      }
      if (Gi_156 == TRUE && Gi_160 == TRUE && Gi_164 == TRUE && Gi_168 == TRUE && Gi_172 && Gi_200 == TRUE && Gi_208 != 1) {
         G_ibuf_76[Li_168] = Low[Li_168] - 1.3 * Ld_172;
         if (Li_168 <= 2 && Alerts && (!Gi_212)) {
            Alert(Symbol(), " ", Period(), "BUY");
            SendMail(" BUY " + Symbol(), "");
            Gi_212 = TRUE;
            Gi_216 = FALSE;
         }
         Gi_208 = 1;
      } else {
         if (Gi_180 == TRUE && Gi_184 == TRUE && Gi_188 == TRUE && Gi_192 == TRUE && Gi_196 && Gi_204 == TRUE && Gi_208 != 2) {
            G_ibuf_80[Li_168] = High[Li_168] + 1.3 * Ld_172;
            if (Li_168 <= 2 && Alerts && (!Gi_216)) {
               Alert(Symbol(), " ", Period(), "SELL");
               SendMail(" SELL " + Symbol(), "");
               Gi_216 = TRUE;
               Gi_212 = FALSE;
            }
            Gi_208 = 2;
         }
      }
   }
   return (0);
}
