/*
   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 1
#property indicator_color1 Black

extern int TimeFrame = 0;
extern int KPeriod = 14;
extern int DPeriod = 3;
extern int Slowing = 5;
extern int MAMethod = 0;
extern int PriceField = 0;
double g_ibuf_100[];
double g_ibuf_104[];

int init() {
   string ls_0;
   IndicatorBuffers(2);
   SetIndexBuffer(0, g_ibuf_100);
   SetIndexBuffer(1, g_ibuf_104);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexStyle(1, DRAW_NONE);
   switch (TimeFrame) {
   case 1:
      ls_0 = "Period M1";
      break;
   case 5:
      ls_0 = "Period M5";
      break;
   case 15:
      ls_0 = "Period M15";
      break;
   case 30:
      ls_0 = "Period M30";
      break;
   case 60:
      ls_0 = "Period H1";
      break;
   case 240:
      ls_0 = "Period H4";
      break;
   case 1440:
      ls_0 = "Period D1";
      break;
   case 10080:
      ls_0 = "Period W1";
      break;
   case 43200:
      ls_0 = "Period MN1";
      break;
   default:
      ls_0 = "Current Timeframe";
   }
   IndicatorShortName(ls_0 + " FDB_FXT");
   return (0);
}

int start() {
   int lia_0[];
   int li_4;
   int l_shift_8;
   int l_datetime_12;
   int l_shift_16;
   double ld_20;
   int l_error_28 = 0;
   bool li_32 = FALSE;
   ArrayCopySeries(lia_0, 5, Symbol(), TimeFrame);
   l_error_28 = GetLastError();
   if (l_error_28 == 4066/* HISTORY_WILL_UPDATED */) {
      Print("Waiting for data on " + Symbol());
      for (int l_index_36 = 0; l_index_36 < 50000; l_index_36++) {
         ArrayCopySeries(lia_0, 5, Symbol(), TimeFrame);
         li_4 = lia_0[0];
         if (Year() == TimeYear(li_4) && Month() == TimeMonth(li_4) && Day() == TimeDay(li_4) && Hour() == TimeHour(li_4) && Minute() == TimeMinute(li_4)) {
            li_32 = TRUE;
            break;
         }
         if (li_32 == FALSE) {
            Print("Waiting for data on " + Symbol());
            return (777);
         }
      }
   }
   int li_40 = IndicatorCounted();
   if (li_40 < 0) return (-1);
   if (li_40 > 0) li_40--;
   int li_44 = Bars - li_40 - 1;
   for (l_index_36 = li_44; l_index_36 >= 0; l_index_36--) {
      l_shift_8 = iBarShift(NULL, TimeFrame, Time[l_index_36]);
      l_datetime_12 = iTime(NULL, TimeFrame, l_shift_8);
      l_shift_16 = iBarShift(NULL, 0, l_datetime_12);
      g_ibuf_100[l_shift_16] = iStochastic(NULL, TimeFrame, KPeriod, DPeriod, Slowing, MAMethod, PriceField, MODE_MAIN, l_shift_8);
      g_ibuf_104[l_shift_16] = iStochastic(NULL, TimeFrame, KPeriod, DPeriod, Slowing, MAMethod, PriceField, MODE_SIGNAL, l_shift_8);
      if (TimeFrame > Period()) {
         if (l_shift_8 == 0) {
            for (int li_48 = 1; l_shift_16 - li_48 >= 0; li_48++) {
               g_ibuf_100[l_shift_16 - li_48] = g_ibuf_100[l_shift_16];
               g_ibuf_104[l_shift_16 - li_48] = g_ibuf_104[l_shift_16];
            }
         }
         for (li_48 = 1; l_shift_16 + li_48 < Bars && Time[l_shift_16 + li_48] > iTime(NULL, TimeFrame, iBarShift(NULL, TimeFrame, Time[l_shift_16 + li_48], TRUE)); li_48++) {
         }
         ld_20 = 1.0 / li_48;
         for (int li_52 = 1; li_52 < li_48; li_52++) {
            g_ibuf_100[l_shift_16 + li_52] = li_52 * ld_20 * (g_ibuf_100[l_shift_16 + li_48]) + (1.0 - li_52 * ld_20) * g_ibuf_100[l_shift_16];
            g_ibuf_104[l_shift_16 + li_52] = li_52 * ld_20 * (g_ibuf_104[l_shift_16 + li_48]) + (1.0 - li_52 * ld_20) * g_ibuf_104[l_shift_16];
         }
      }
   }
   return (0);
}
