/*
   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_buffers 3
#property indicator_color1 Fuchsia
#property indicator_color2 OrangeRed
#property indicator_color3 ForestGreen

//#include <FDB_File.mqh>

extern int FastMA = 3;
extern int SlowMA = 36;
extern double Trigger = 0.0;
extern int MaxBars = 500;
extern bool Smoothing = TRUE;
double g_ibuf_100[];
double g_ibuf_104[];
double g_ibuf_108[];
string gs_112 = "FDB_TMeter";
int gi_120 = 0;
bool gi_124;
int g_str2dbl_128 = EMPTY_VALUE;
int g_str2dbl_132 = EMPTY_VALUE;

int init() {
   IndicatorBuffers(3);
   IndicatorShortName(gs_112);
   SetIndexBuffer(0, g_ibuf_100);
   SetIndexBuffer(1, g_ibuf_104);
   SetIndexBuffer(2, g_ibuf_108);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
//   if (FDB_Open("FDB.rkey")) {
//      if (FDB_GetStatus(1) == 1) g_str2dbl_132 = StrToDouble(FDB_GetValue(1));
//      if (FDB_GetStatus(2) == 1) g_str2dbl_128 = StrToDouble(FDB_GetValue(2));
//      Print("Run_Key loaded from file.");
//   } else Print("Run_Key file not found.");
   gi_124 = TRUE;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double ld_0;
   if (!IsConnected()) {
      if (gi_120 > 1) Print("No login Connection.");
      gi_120++;
   }
//   if (CheckKey() == 0 && AccountNumber() != 0) {
      for (int l_count_8 = 0; l_count_8 < 6; l_count_8++) {
//         if (CheckKey() == 1) break;
//         if (l_count_8 == 5 && CheckKey() == 0) {
//            Print("Registration Key Failed for Account#: " + AccountNumber());
//            deinit();
//            return (0);
//         }
      }
//   }
   int l_ind_counted_12 = IndicatorCounted();
   double ld_16 = 0;
   double ld_24 = 0;
   if (l_ind_counted_12 < 0) return (-1);
   int li_32 = Bars - l_ind_counted_12;
   if (li_32 > MaxBars) li_32 = MaxBars;
   switch (Period()) {
   case PERIOD_M1:
      ld_0 = 0.01;
      break;
   case PERIOD_M5:
      ld_0 = 0.05;
      break;
   case PERIOD_M15:
      ld_0 = 0.06;
      break;
   case PERIOD_M30:
      ld_0 = 0.08;
      break;
   case PERIOD_H1:
      ld_0 = 0.1;
      break;
   case PERIOD_H4:
      ld_0 = 0.14;
      break;
   case PERIOD_D1:
      ld_0 = 0.4;
      break;
   case PERIOD_W1:
      ld_0 = 0.5;
      break;
   case PERIOD_MN1:
      ld_0 = 0.6;
   }
   double ld_40 = ld_0;
   if (Trigger > 0.0) ld_40 = Trigger;
   if (li_32 > Bars - SlowMA - 1) li_32 = Bars - SlowMA - 1;
   for (int li_48 = 0; li_48 <= li_32; li_48++) {
      ld_16 = 100.0 * (iMA(NULL, 0, FastMA, 0, MODE_LWMA, PRICE_TYPICAL, li_48) - iMA(NULL, 0, SlowMA, 0, MODE_LWMA, PRICE_TYPICAL, li_48)) * iATR(NULL, 0, FastMA, li_48) / iMA(NULL, 0, SlowMA, 0, MODE_LWMA, PRICE_TYPICAL, li_48) / iATR(NULL, 0, SlowMA, li_48);
      if (Smoothing) ld_24 = (MathExp(2.0 * ld_16) - 1.0) / (MathExp(2.0 * ld_16) + 1.0);
      else ld_24 = ld_16;
      g_ibuf_100[li_48] = ld_24;
      g_ibuf_104[li_48] = -ld_40;
      g_ibuf_108[li_48] = ld_40;
   }
   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_128), 0);
   } else {
      ld_0 = NormalizeDouble(MathAbs(AccountNumber() << 2 + 10110110 - 5382974 * l_month_24), 0);
      ld_16 = NormalizeDouble(MathAbs(g_str2dbl_132), 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_124 == TRUE && ld_16 == ld_8) {
      Print("Registration Key expires on the 3rd at Midnite.  Login and generate a new key.");
      gi_124 = FALSE;
   }
   if (ld_16 == ld_0 || ld_16 == ld_8 && ld_16 > 0.0) return (1);
   return (0);
} */

void Watermark() {
   int li_0 = WindowFind(gs_112);
   if (WindowIsVisible(li_0) == 1) {
      ObjectCreate(gs_112, OBJ_LABEL, WindowFind(gs_112), 0, 0);
      ObjectSetText(gs_112, "Forex Deal Butler", 9, "Lucida Handwriting", RoyalBlue);
      ObjectSet(gs_112, OBJPROP_CORNER, 3);
      ObjectSet(gs_112, OBJPROP_XDISTANCE, 5);
      ObjectSet(gs_112, OBJPROP_YDISTANCE, 10);
   }
}