/*
   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 3
#property indicator_color1 Gold
#property indicator_color2 Red
#property indicator_color3 Blue

//#include <FDB_File.mqh>

extern int RSLength = 30;
extern int MaxBars = 500;
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
double g_ibuf_108[];
int gi_112 = 0;
bool gi_116;
int g_str2dbl_120 = EMPTY_VALUE;
int g_str2dbl_124 = EMPTY_VALUE;

int init() {
   IndicatorBuffers(7);
   IndicatorShortName("FDB_DynamicRS");
   SetIndexBuffer(0, g_ibuf_84);
   SetIndexBuffer(1, g_ibuf_88);
   SetIndexBuffer(2, g_ibuf_92);
   SetIndexBuffer(3, g_ibuf_96);
   SetIndexBuffer(4, g_ibuf_100);
   SetIndexBuffer(5, g_ibuf_104);
   SetIndexBuffer(6, g_ibuf_108);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexStyle(4, DRAW_NONE);
   SetIndexStyle(5, DRAW_NONE);
   SetIndexStyle(6, DRAW_NONE);
//   if (FDB_Open("FDB.rkey")) {
//      if (FDB_GetStatus(1) == 1) g_str2dbl_124 = StrToDouble(FDB_GetValue(1));
//      if (FDB_GetStatus(2) == 1) g_str2dbl_120 = StrToDouble(FDB_GetValue(2));
//      Print("Run_Key loaded from file.");
//   } else Print("Run_Key file not found.");
   gi_116 = TRUE;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double l_high_0;
   double l_low_8;
   double l_high_16;
   double l_low_24;
   if (!IsConnected()) {
      if (gi_112 > 1) Print("No login Connection.");
      gi_112++;
   }
//   if (CheckKey() == 0 && AccountNumber() != 0) {
      for (int l_count_32 = 0; l_count_32 < 6; l_count_32++) {
//         if (CheckKey() == 1) break;
//         if (l_count_32 == 5 && CheckKey() == 0) {
//            Print("Registration Key Failed for Account#: " + AccountNumber());
//            deinit();
//            return (0);
//         }
//      }
   }
   int li_36 = IndicatorCounted();
   if (li_36 < 0) return (-1);
   if (li_36 > 0) li_36--;
   int li_40 = Bars - li_36;
   if (li_40 > MaxBars && MaxBars > 0) li_40 = MaxBars;
   for (int li_44 = 0; li_44 < li_40; li_44++) {
      g_ibuf_96[li_44] = High[iHighest(NULL, 0, MODE_HIGH, 5, li_44)];
      g_ibuf_100[li_44] = Low[iLowest(NULL, 0, MODE_LOW, 5, li_44)];
      g_ibuf_104[li_44] = (g_ibuf_96[li_44] + g_ibuf_100[li_44] + Close[li_44]) / 3.0;
   }
   for (int li_48 = MaxBars; li_48 >= 0; li_48--) {
      l_high_0 = High[iHighest(NULL, 0, MODE_HIGH, RSLength, li_48)];
      l_low_8 = Low[iLowest(NULL, 0, MODE_LOW, RSLength, li_48)];
      g_ibuf_108[li_48] = iMAOnArray(g_ibuf_104, 0, 25, 0, MODE_SMA, li_48);
      if (g_ibuf_104[li_48 + 1] >= g_ibuf_108[li_48 + 1] && g_ibuf_104[li_48] <= g_ibuf_108[li_48]) l_high_16 = l_high_0;
      if (g_ibuf_104[li_48 + 1] <= g_ibuf_108[li_48 + 1] && g_ibuf_104[li_48] >= g_ibuf_108[li_48]) l_low_24 = l_low_8;
      g_ibuf_84[li_48] = (l_high_16 + l_low_24) / 2.0;
      g_ibuf_88[li_48] = l_high_16;
      g_ibuf_92[li_48] = l_low_24;
   }
   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_120), 0);
   } else {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_124), 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_116 == TRUE && ld_16 == ld_8) {
      Print("Registration Key expires on the 3rd at Midnite.  Login and generate a new key.");
      gi_116 = FALSE;
   }
   if (ld_16 == ld_0 || ld_16 == ld_8 && ld_16 > 0.0) return (1);
   return (0);
} */