/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2008,FXDB, LLC"
#property link      "http://www.ForexDealButler.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Lime
#property indicator_color3 Blue
#property indicator_color4 Blue

//#include <FDB_File.mqh>

bool gi_76;
int g_timeframe_80 = 0;
int g_period_84 = 13;
int g_period_88 = 12;
int g_period_92 = 26;
int gi_96 = 9;
int gi_100 = 0;
int g_str2dbl_104 = EMPTY_VALUE;
int g_str2dbl_108 = EMPTY_VALUE;
int gi_112 = 0;
double g_ibuf_116[];
double g_ibuf_120[];
double g_ibuf_124[];
double g_ibuf_128[];
double g_ibuf_132[];
double g_ibuf_136[];
double g_ibuf_140[];

int init() {
   IndicatorBuffers(7);
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 3);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 3);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 3);
   SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 3);
   SetIndexBuffer(0, g_ibuf_116);
   SetIndexBuffer(1, g_ibuf_120);
   SetIndexBuffer(2, g_ibuf_124);
   SetIndexBuffer(3, g_ibuf_128);
   SetIndexBuffer(4, g_ibuf_132);
   SetIndexBuffer(5, g_ibuf_136);
   SetIndexBuffer(6, g_ibuf_140);
   SetIndexDrawBegin(0, g_period_92);
   SetIndexDrawBegin(1, g_period_92);
   SetIndexDrawBegin(2, g_period_92);
   SetIndexDrawBegin(3, g_period_92);
   SetIndexEmptyValue(4, 0.0);
   SetIndexEmptyValue(5, 0.0);
   SetIndexEmptyValue(6, 0.0);
//   if (FDB_Open("FDB.rkey")) {
//      if (FDB_GetStatus(1) == 1) g_str2dbl_104 = StrToDouble(FDB_GetValue(1));
//      if (FDB_GetStatus(2) == 1) g_str2dbl_108 = StrToDouble(FDB_GetValue(2));
//      Print("Run_Key loaded from file.");
//   } else Print("Run_Key file not found.");
   gi_76 = TRUE;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double l_ima_8;
   double l_ima_16;
   double ld_24;
   double ld_32;
   double ld_40;
   double ld_48;
   int l_shift_4 = 0;
   double ld_56 = 2.0 / (gi_96 + 1.0);
   double ld_64 = 1.0 - ld_56;
   if (!IsConnected()) {
      if (gi_100 > 1) Print("No login Connection.");
      gi_100++;
   }
//   if (CheckKey() == 0 && AccountNumber() != 0) {
      for (int l_count_0 = 0; l_count_0 < 6; l_count_0++) {
//         if (CheckKey() == 1) break;
//         if (l_count_0 == 5 && CheckKey() == 0) {
//            Print("Registration Key Failed for Account#: " + AccountNumber());
//            deinit();
//            return (0);
//         }
//      }
   }
   if (Bars <= 10) return (0);
   gi_112 = IndicatorCounted();
   if (gi_112 < 0) return (-1);
   if (gi_112 > 0) gi_112--;
   for (int li_72 = Bars - gi_112 - 1; li_72 >= 0; li_72--) {
      l_shift_4 = iBarShift(NULL, g_timeframe_80, Time[li_72]);
      l_ima_16 = iMA(NULL, g_timeframe_80, g_period_84, 0, MODE_EMA, PRICE_CLOSE, l_shift_4);
      l_ima_8 = iMA(NULL, g_timeframe_80, g_period_84, 0, MODE_EMA, PRICE_CLOSE, l_shift_4 + 1);
      g_ibuf_136[l_shift_4] = iMA(NULL, g_timeframe_80, g_period_88, 0, MODE_EMA, PRICE_CLOSE, l_shift_4) - iMA(NULL, g_timeframe_80, g_period_92, 0, MODE_EMA, PRICE_CLOSE, l_shift_4);
      g_ibuf_132[l_shift_4] = ld_56 * g_ibuf_136[l_shift_4] + ld_64 * (g_ibuf_132[l_shift_4 + 1]);
      g_ibuf_140[l_shift_4] = g_ibuf_136[l_shift_4] - g_ibuf_132[l_shift_4];
      ld_32 = g_ibuf_140[l_shift_4];
      ld_24 = g_ibuf_140[l_shift_4 + 1];
      ld_40 = Open[li_72];
      ld_48 = Close[li_72];
      if (l_ima_16 < l_ima_8 && ld_32 < ld_24) {
         if (ld_40 < ld_48) {
            g_ibuf_116[li_72] = ld_48;
            g_ibuf_120[li_72] = ld_40;
            g_ibuf_124[li_72] = EMPTY_VALUE;
            g_ibuf_128[li_72] = EMPTY_VALUE;
         } else {
            g_ibuf_116[li_72] = ld_40;
            g_ibuf_120[li_72] = ld_48;
            g_ibuf_124[li_72] = EMPTY_VALUE;
            g_ibuf_128[li_72] = EMPTY_VALUE;
         }
      } else {
         if (l_ima_16 > l_ima_8 && ld_32 > ld_24) {
            if (ld_40 < ld_48) {
               g_ibuf_116[li_72] = ld_40;
               g_ibuf_120[li_72] = ld_48;
               g_ibuf_124[li_72] = EMPTY_VALUE;
               g_ibuf_128[li_72] = EMPTY_VALUE;
            } else {
               g_ibuf_116[li_72] = ld_48;
               g_ibuf_120[li_72] = ld_40;
               g_ibuf_124[li_72] = EMPTY_VALUE;
               g_ibuf_128[li_72] = EMPTY_VALUE;
            }
         } else {
            g_ibuf_124[li_72] = ld_40;
            g_ibuf_128[li_72] = ld_48;
            g_ibuf_116[li_72] = EMPTY_VALUE;
            g_ibuf_120[li_72] = EMPTY_VALUE;
         }
      }
   }
   return (0);
}

/*int CheckKey() {
   double ld_0;
   double ld_8;
   double ld_16;
   int l_month_24 = TimeMonth(TimeCurrent());
   if (IsDemo() == TRUE) {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 - 3912671 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_108), 0);
   } else {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_104), 0);
   }
   if (TimeMonth(TimeCurrent() - 259200) == l_month_24 - 1 && ld_16 > 0.0) {
      if (IsDemo() == TRUE) ld_8 = NormalizeDouble(MathAbs(AccountNumber() << 2 - 3912671 * (l_month_24 - 1)), 0);
      else ld_8 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * (l_month_24 - 1)), 0);
   }
   if (gi_76 == TRUE && ld_16 == ld_8) {
      Print("Registration Key expires on the 3rd at Midnite.  Login and generate a new key.");
      gi_76 = FALSE;
   }
   if (ld_16 == ld_0 || ld_16 == ld_8 && ld_16 > 0.0) return (1);
   return (0);
} */