/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2011, "
#property link      "http://"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Silver
#property indicator_color2 Red
#property indicator_color3 Green

extern string s.0 = "FX night";
extern string s.1 = "Sound Alerts:";
extern bool SoundAlerts = TRUE;
extern string s.2 = "Email Alerts:";
extern bool EmailAlerts = FALSE;
int g_period_108 = 8;
int gi_112 = 30;
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];

int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(0, g_ibuf_116);
   SetIndexBuffer(1, g_ibuf_120);
   SetIndexBuffer(2, g_ibuf_124);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double ld_0;
   double ld_8;
   double lda_16[];
   ArrayResize(lda_16, gi_112);
   int l_ind_counted_20 = IndicatorCounted();
   int li_24 = Bars - l_ind_counted_20 - 1;
   for (int li_28 = li_24; li_28 >= 0; li_28--) {
      g_ibuf_116[li_28] = iRSI(NULL, 0, g_period_108, PRICE_LOW, li_28);
      ld_8 = 0;
      for (int li_32 = li_28; li_32 < li_28 + gi_112; li_32++) {
         lda_16[li_32 - li_28] = g_ibuf_116[li_32];
         ld_8 += g_ibuf_116[li_32] / gi_112;
      }
      g_ibuf_120[li_28] = ld_8 + 1.3185 * StDev(lda_16, gi_112);
      g_ibuf_124[li_28] = ld_8 - 1.3185 * StDev(lda_16, gi_112);
   }
   if (Open[0] == Close[0] && Open[0] == Low[0] && Open[0] == High[0]) {
      if (g_ibuf_116[1] < g_ibuf_120[1] && g_ibuf_116[2] > g_ibuf_120[2]) {
         ld_0 = High[iHighest(Symbol(), 0, MODE_HIGH, 3, 1)] + 1.0 * Point;
         if (SoundAlerts) Alert(": SHORT signal at " + Symbol() + " [" + Period() + "], Stop loss at " + ld_0);
         if (EmailAlerts) SendMail(" Signal at " + Symbol(), "SHORT signal at " + Symbol() + " [" + Period() + "], Stop loss at " + ld_0);
      }
      if (g_ibuf_116[1] > g_ibuf_124[1] && g_ibuf_116[2] < g_ibuf_124[2]) {
         ld_0 = Low[iLowest(Symbol(), 0, MODE_LOW, 3, 1)] - 1.0 * Point;
         if (SoundAlerts) Alert(": LONG signal at " + Symbol() + " [" + Period() + "], Stop loss at " + ld_0);
         if (EmailAlerts) SendMail(" at " + Symbol(), "LONG signal at " + Symbol() + " [" + Period() + "], Stop loss at " + ld_0);
      }
   }
   return (0);
}

double StDev(double ada_0[], int ai_4) {
   return (MathSqrt(Variance(ada_0, ai_4)));
}

double Variance(double ada_0[], int ai_4) {
   double ld_8;
   double ld_16;
   for (int l_index_24 = 0; l_index_24 < ai_4; l_index_24++) {
      ld_8 += ada_0[l_index_24];
      ld_16 += MathPow(ada_0[l_index_24], 2);
   }
   return ((ld_16 * ai_4 - ld_8 * ld_8) / (ai_4 * (ai_4 - 1)));
}