#property copyright "Copyright (c) 2009, EA-LABORATORY Engineeeer"
#property link      "http://www.ea-labo.com"
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_color3 Gold
#property indicator_color4 Gold
#property indicator_level1 0.3
#property indicator_level2 -0.3

#import "kernel32.dll"
   void GetSystemTime(int& a0[]);
#import

bool gi_76 = TRUE;
bool gi_unused_80 = TRUE;
bool gi_84 = TRUE;
int gi_88 = D'24.11.2011 20:00';
string gs_unused_92 = "OTTKFilter1";
extern int Bands_Mode_0_2 = 0;
extern int Power_Price_0_6 = 0;
extern int Price_Type_0_3 = 0;
extern int Bands_Period = 20;
extern int Bands_Deviation = 2;
extern int Power_Period = 13;
extern double Range_level = 0.3;
extern int Continue_Priod = 10;
double g_ibuf_136[];
double g_ibuf_140[];
double g_ibuf_144[];
double g_ibuf_148[];
bool gi_unused_152 = FALSE;
bool gi_156 = FALSE;

int init() {
   int li_0;
   string l_dbl2str_4;
   int lia_12[1];
   IndicatorBuffers(4);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 3);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(0, g_ibuf_136);
   SetIndexBuffer(1, g_ibuf_140);
   SetIndexBuffer(2, g_ibuf_144);
   SetIndexBuffer(3, g_ibuf_148);
   SetIndexDrawBegin(0, Bands_Period);
   SetIndexDrawBegin(1, Bands_Period);
   SetIndexDrawBegin(2, Bands_Period + Continue_Priod);
   SetIndexDrawBegin(3, Bands_Period);
   SetIndexLabel(0, "value1");
   SetIndexLabel(1, "value2");
   SetIndexLabel(2, "signal");
   if (gi_76 == TRUE) {
      li_0 = 0;
      l_dbl2str_4 = "";
      lia_12[0] = 15183578;
      gi_unused_80 = TRUE;
      lia_12[0] = 88581357;
      gi_84 = TRUE;
      lia_12[0] = 91258610;
      li_0 = 17570921;
      if (lia_12[0] != 17570921) {
         gi_84 = TRUE;
         gi_88 = 1325354400;
      } else {
         l_dbl2str_4 = DoubleToStr(li_0, 0);
         gi_88 = StrToTime(StringSubstr(l_dbl2str_4, 0, 4) + "." + StringSubstr(l_dbl2str_4, 4, 2) + "." + StringSubstr(l_dbl2str_4, 6, 2));
      }
   }
   if (gi_84 == FALSE) gi_88 = 86399;
   else gi_88 += 86399;
   return (0);
}

int start() {
   int lia_0[1];
   int l_applied_price_4;
   double ld_8;
   double ld_16;
   double ld_24;
   if (gi_84 == TRUE) {
      if (Time_Limit_cal(gi_88) == 0 || check_UTC_TimeLimitOver() == 1) {
         if (gi_156 == FALSE) Print("Error. This Indicator is outside the license. Please install Indicator of a new version. (http://www.ea-labo.com)");
         gi_156 = TRUE;
         g_ibuf_148[0] = EMPTY_VALUE;
         return (0);
      }
   }
   int l_ind_counted_32 = IndicatorCounted();
   if (Bars <= Bands_Period) return (0);
   if (l_ind_counted_32 < Bands_Period) {
      for (int l_shift_36 = 1; l_shift_36 <= Bands_Period; l_shift_36++) g_ibuf_136[Bars - l_shift_36] = 0.0;
      for (l_shift_36 = 1; l_shift_36 <= Bands_Period; l_shift_36++) g_ibuf_140[Bars - l_shift_36] = 0.0;
   }
   if (l_ind_counted_32 < Bands_Period + Continue_Priod) for (l_shift_36 = 1; l_shift_36 <= Bands_Period + Continue_Priod; l_shift_36++) g_ibuf_144[Bars - l_shift_36] = EMPTY_VALUE;
   if (l_ind_counted_32 >= Bands_Period) l_shift_36 = Bars - l_ind_counted_32 - 1;
   if (Bands_Mode_0_2 == 1) l_applied_price_4 = 1;
   if (Bands_Mode_0_2 == 2) l_applied_price_4 = 2;
   if (Bands_Mode_0_2 == 0) l_applied_price_4 = 0;
   if (Power_Price_0_6 == 1) ld_8 = 1;
   if (Power_Price_0_6 == 2) ld_8 = 2;
   if (Power_Price_0_6 == 3) ld_8 = 3;
   if (Power_Price_0_6 == 4) ld_8 = 4;
   if (Power_Price_0_6 == 5) ld_8 = 5;
   if (Power_Price_0_6 == 6) ld_8 = 6;
   if (Power_Price_0_6 == 0) ld_8 = 0;
   for (l_shift_36 = Bars - l_ind_counted_32 - 1; l_shift_36 >= 0; l_shift_36--) {
      if (Price_Type_0_3 == 1) ld_16 = Open[l_shift_36];
      if (Price_Type_0_3 == 2) ld_16 = High[l_shift_36];
      if (Price_Type_0_3 == 3) ld_16 = Low[l_shift_36];
      if (Price_Type_0_3 == 0) ld_16 = Close[l_shift_36];
      g_ibuf_136[l_shift_36] = ld_16 - iBands(NULL, 0, Bands_Period, Bands_Deviation, 0, l_applied_price_4, ld_8, l_shift_36);
      g_ibuf_140[l_shift_36] = -(iBearsPower(NULL, 0, Power_Period, ld_8, l_shift_36) + iBullsPower(NULL, 0, Power_Period, ld_8, l_shift_36));
      if (g_ibuf_136[l_shift_36] < Range_level && g_ibuf_136[l_shift_36] > (-Range_level) && g_ibuf_140[l_shift_36] < Range_level && g_ibuf_140[l_shift_36] > (-Range_level)) g_ibuf_148[l_shift_36] = 0;
      else g_ibuf_148[l_shift_36] = -0.00001;
      ld_24 = 0;
      for (int li_40 = l_shift_36 + Continue_Priod - 1; li_40 >= l_shift_36; li_40--) ld_24 = MathMin(ld_24, g_ibuf_148[li_40]);
      if (ld_24 == 0.0) g_ibuf_144[l_shift_36] = 0;
      else g_ibuf_144[l_shift_36] = EMPTY_VALUE;
   }
   return (0);
}

int check_UTC_TimeLimitOver() {
   int li_0 = get_UTC_time();
   if (gi_88 >= li_0) return (0);
   return (1);
}

int get_UTC_time() {
   int lia_0[4];
   GetSystemTime(lia_0);
   string ls_4 = (lia_0[0] & 65535) + "." + (lia_0[0] >> 16) + "." + (lia_0[1] >> 16) + " " + (lia_0[2] & 65535) + ":" + (lia_0[2] >> 16) + ":" + (lia_0[3] & 65535);
   return (StrToTime(ls_4));
}

int Time_Limit_cal(int ai_0) {
   if (ai_0 <= 86400) return (1);
   if (ai_0 - TimeCurrent() <= 0) return (0);
   return (1);
}