/*
   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_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 1.0
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Blue
#property indicator_color3 Red

//#include <FDB_File.mqh>

extern int ShowBars = 5000;
double g_ibuf_80[];
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];
string gs_104 = "FXDB_FXT_MAP";
int g_period_112 = 14;
int g_period_116 = 3;
int g_slowing_120 = 5;
double gd_124 = 0.0;
double gd_132 = 0.0;
int gi_140 = 0;
bool gi_144;
int g_str2dbl_148 = EMPTY_VALUE;
int g_str2dbl_152 = EMPTY_VALUE;

int init() {
   IndicatorBuffers(6);
   IndicatorShortName(gs_104);
   SetIndexBuffer(0, g_ibuf_80);
   SetIndexBuffer(1, g_ibuf_84);
   SetIndexBuffer(2, g_ibuf_88);
   SetIndexBuffer(3, g_ibuf_92);
   SetIndexBuffer(4, g_ibuf_96);
   SetIndexBuffer(5, g_ibuf_100);
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   SetIndexEmptyValue(0, 0.0);
   SetIndexEmptyValue(1, 0.0);
   SetIndexEmptyValue(2, 0.0);
   SetIndexEmptyValue(3, 0.0);
   SetIndexEmptyValue(4, 0.0);
   SetIndexEmptyValue(5, 0.0);
//   if (FDB_Open("FDB.rkey")) {
//      if (FDB_GetStatus(1) == 1) g_str2dbl_152 = StrToDouble(FDB_GetValue(1));
//      if (FDB_GetStatus(2) == 1) g_str2dbl_148 = StrToDouble(FDB_GetValue(2));
//      Print("Run_Key loaded from file.");
//   } else Print("Run_Key file not found.");
   gi_144 = TRUE;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double l_istochastic_0;
   double l_istochastic_8;
   double ld_16;
   double ld_24;
   gd_124 = 0.2;
   gd_132 = 1.0 - gd_124;
   if (!IsConnected()) {
      if (gi_140 > 1) Print("No login Connection.");
      gi_140++;
   }
//   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 - 1;
   int li_44 = ShowBars;
   if (ShowBars > li_40) ShowBars = li_40;
   for (li_44 = ShowBars; li_44 >= 0; li_44--) {
      l_istochastic_0 = iStochastic(NULL, 0, g_period_112, g_period_116, g_slowing_120, MODE_SMA, 0, MODE_MAIN, li_44 + 1);
      l_istochastic_8 = iStochastic(NULL, 0, g_period_112, g_period_116, g_slowing_120, MODE_SMA, 0, MODE_SIGNAL, li_44 + 1);
      g_ibuf_92[li_44] = iMA(Symbol(), 0, 12, 0, MODE_EMA, PRICE_CLOSE, li_44) - iMA(Symbol(), 0, 26, 0, MODE_EMA, PRICE_CLOSE, li_44);
      g_ibuf_96[li_44] = gd_124 * g_ibuf_92[li_44] + gd_132 * (g_ibuf_96[li_44 + 1]);
      ld_16 = g_ibuf_92[li_44] - g_ibuf_96[li_44];
      ld_24 = g_ibuf_92[li_44 + 1] - (g_ibuf_96[li_44 + 1]);
      if ((l_istochastic_8 < l_istochastic_0 && l_istochastic_0 > 20.0) || (l_istochastic_0 >= 80.0 && ld_16 > ld_24)) g_ibuf_80[li_44] = 1;
      else g_ibuf_80[li_44] = 0.0;
      if ((l_istochastic_8 >= l_istochastic_0 && l_istochastic_0 < 80.0) || (l_istochastic_0 <= 20.0 && ld_16 < ld_24)) g_ibuf_88[li_44] = 1;
      else g_ibuf_88[li_44] = 0.0;
      if (g_ibuf_80[li_44] == 0.0 && g_ibuf_88[li_44] == 0.0) g_ibuf_84[li_44] = 1;
      else g_ibuf_84[li_44] = 0.0;
   }
   Watermark();
   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_148), 0);
   } else {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_152), 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_144 == TRUE && ld_16 == ld_8) {
      Print("Registration Key expires on the 3rd at Midnite.  Login and generate a new key.");
      gi_144 = FALSE;
   }
   if (ld_16 == ld_0 || ld_16 == ld_8 && ld_16 > 0.0) return (1);
   return (0);
} */

void Watermark() {
   ObjectCreate(gs_104, OBJ_LABEL, WindowFind(gs_104), 0, 0);
   ObjectSetText(gs_104, "Forex Deal Butler", 9, "Lucida Handwriting", RoyalBlue);
   ObjectSet(gs_104, OBJPROP_CORNER, 3);
   ObjectSet(gs_104, OBJPROP_XDISTANCE, 5);
   ObjectSet(gs_104, OBJPROP_YDISTANCE, 5);
}