/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2010, Forex Impact LLC."
#property link      "http://www.foreximpact.com"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Yellow

#import "FXI.dll"
   string gGrab(string a0, string a1);
#import "corr_upd.dll"
   string returnReg(string a0, string a1);
#import

extern string Copyright = "Copyright 2010, Forex Impact LLC.";
extern string First = "FXI+SignalArrows";
extern string Last = "---------------";
extern color UpArrow = LimeGreen;
extern color DownArrow = Red;
double gda_108[];
double gd_112 = 1.01;
bool gi_120 = TRUE;
int gi_124 = 5;
int gi_128 = 40;
int gi_unused_132 = 5;
double gd_unused_136 = 100.0;
double gd_unused_144 = 0.0;
double gd_unused_152 = 100.0;
double gd_unused_160 = 0.0;
int gi_unused_168 = 5;
int gi_unused_172 = 5;
double gd_unused_176 = 100.0;
int g_period_184 = 14;
int g_period_188 = 3;
int g_slowing_192 = 3;
int gi_196 = 50;
int gi_200 = 50;
bool gi_unused_204 = FALSE;
bool gi_unused_208 = TRUE;
bool gi_unused_212 = FALSE;
bool gi_unused_216 = FALSE;
int gi_unused_220 = 1000;
double g_ibuf_224[];
double g_ibuf_228[];
double gda_unused_232[];
double gda_unused_236[];
double gda_unused_240[];
double gda_unused_244[];
int gi_248 = -1;
int gi_252 = -1;
int gi_unused_276 = -1;
int gi_unused_284 = 0;
double g_icustom_288;
double g_icustom_296;
double g_icustom_304;
double g_icustom_312;
int gi_unused_320;
bool gi_unused_324 = FALSE;
double gda_unused_328[];
double gda_unused_332[];
double g_icustom_336;
double g_icustom_344;
double g_icustom_352;
double g_icustom_360;
double g_icustom_384;
double g_icustom_392;
double g_icustom_400;
double g_icustom_408;
double g_istochastic_424;
double g_ibuf_432[];
double g_ibuf_436[];
int gt_unused_440 = -1;
int gt_unused_444 = -1;
int gi_unused_448 = -1;
int gi_452 = 0;
double g_icustom_456;
int g_time_464 = 0;
string gs_unused_468;
double gd_476 = 100.0;
double gd_484 = 0.0;
double gd_492 = 100.0;
double gd_500 = 0.0;
int gi_508 = 5;
int gi_512 = 5;
double g_pips_516 = 100.0;
double gda_524[50];
double gda_528[50];
double g_ibuf_532[];
double g_ibuf_536[];
double g_ibuf_540[];
double g_ibuf_544[];
bool gi_548 = TRUE;
bool gi_552 = TRUE;
double g_ibuf_556[];
double g_ibuf_560[];
double g_ibuf_564[];
double g_ibuf_568[];
double g_ibuf_572[];
int g_time_576 = 0;
double gd_580;
double g_ibuf_588[];
double g_ibuf_592[];
double g_ibuf_596[];
double g_ibuf_600[];
int gi_604 = 0;
string gs_dummy_608;
double g_ibuf_616[];
double g_ibuf_620[];
string gs_624 = "FXI+SignalArrows";
int g_file_632;
bool gi_636 = FALSE;
string gs_unused_640;

int doTFInit() {
   string ls_0;
   if (Copyright == "koaijdsoDUDFIUONUIN") {
      IndicatorBuffers(4);
      SetIndexBuffer(0, g_ibuf_532);
      SetIndexStyle(0, DRAW_LINE);
      SetIndexBuffer(1, g_ibuf_536);
      SetIndexStyle(1, DRAW_LINE);
      SetIndexBuffer(2, g_ibuf_540);
      SetIndexStyle(2, DRAW_LINE, STYLE_DASH);
      SetIndexBuffer(3, g_ibuf_544);
      ls_0 = Symbol();
      if (StringFind(ls_0, "EURUSD") != -1) {
         gd_476 = 100;
         gd_484 = 0;
         gd_492 = 100;
         gd_500 = 0;
         gi_508 = 5;
         gi_512 = 5;
      }
      if (StringFind(ls_0, "USDCHF") != -1) {
         gd_476 = 100;
         gd_484 = 0;
         gd_492 = 100;
         gd_500 = 0;
         gi_508 = 5;
         gi_512 = 5;
      }
      if (StringFind(ls_0, "GBPUSD") != -1) {
         gd_476 = 100;
         gd_484 = 0;
         gd_492 = 100;
         gd_500 = 0;
         gi_508 = 5;
         gi_512 = 5;
      }
      if (StringFind(ls_0, "USDJPY") != -1) {
         gd_476 = 100;
         gd_484 = 0;
         gd_492 = 100;
         gd_500 = 0;
         gi_508 = 6;
         gi_512 = 6;
      }
      return (-1);
   }
   if (Copyright == "9jawe09j09j()J)(JJ") {
      IndicatorBuffers(6);
      SetIndexBuffer(0, g_ibuf_588);
      SetIndexStyle(0, DRAW_LINE);
      SetIndexLabel(0, "FXI Ratchet");
      SetIndexBuffer(1, g_ibuf_556);
      SetIndexStyle(1, DRAW_NONE);
      SetIndexLabel(1, "Debug 1");
      SetIndexBuffer(2, g_ibuf_560);
      SetIndexStyle(2, DRAW_NONE);
      SetIndexLabel(2, "Debug 2");
      SetIndexBuffer(3, g_ibuf_564);
      SetIndexStyle(3, DRAW_NONE);
      SetIndexLabel(3, "Debug 3");
      SetIndexBuffer(4, g_ibuf_568);
      SetIndexStyle(4, DRAW_NONE);
      SetIndexLabel(4, "Debug 4");
      SetIndexBuffer(5, g_ibuf_572);
      SetIndexStyle(5, DRAW_NONE);
      SetIndexLabel(5, "Debug 5");
      if (First == "1") {
         gi_548 = FALSE;
         gi_552 = TRUE;
      } else {
         gi_548 = FALSE;
         gi_552 = FALSE;
      }
      return (-1);
   }
   if (Copyright == "o999jjdjfjjfjfjfjfjfjf") {
      SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 1, Crimson);
      SetIndexBuffer(0, g_ibuf_588);
      SetIndexLabel(0, "HA_0");
      SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 1, RoyalBlue);
      SetIndexBuffer(1, g_ibuf_592);
      SetIndexLabel(1, "HA_1");
      SetIndexStyle(2, DRAW_HISTOGRAM, STYLE_SOLID, 3, Crimson);
      SetIndexBuffer(2, g_ibuf_596);
      SetIndexLabel(2, "HA_Open");
      SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 3, RoyalBlue);
      SetIndexBuffer(3, g_ibuf_600);
      SetIndexLabel(3, "HA_Close");
      SetIndexDrawBegin(0, 10);
      SetIndexDrawBegin(1, 10);
      SetIndexDrawBegin(2, 10);
      SetIndexDrawBegin(3, 10);
      SetIndexBuffer(0, g_ibuf_588);
      SetIndexBuffer(1, g_ibuf_592);
      SetIndexBuffer(2, g_ibuf_596);
      SetIndexBuffer(3, g_ibuf_600);
      return (-1);
   }
   if (Copyright == "09uj089ju#$)JHFihuihdf") {
      if (First == "1") gi_128 = 5;
      else gi_128 = 40;
      SetIndexBuffer(0, g_ibuf_588);
      SetIndexStyle(0, DRAW_LINE);
      SetIndexBuffer(1, g_ibuf_592);
      SetIndexStyle(1, DRAW_LINE);
      SetIndexBuffer(2, g_ibuf_596);
      SetIndexStyle(2, DRAW_LINE);
      SetIndexBuffer(3, g_ibuf_616);
      SetIndexStyle(3, DRAW_HISTOGRAM, STYLE_SOLID, 2);
      SetIndexBuffer(4, g_ibuf_620);
      SetIndexStyle(4, DRAW_HISTOGRAM, STYLE_SOLID, 2);
      SetIndexDrawBegin(0, gi_128);
      SetIndexDrawBegin(1, gi_128);
      SetIndexDrawBegin(2, gi_128);
      SetIndexDrawBegin(3, gi_128);
      SetIndexDrawBegin(4, gi_128);
      return (-1);
   }
   if (Copyright == "LoadTrendFinder") {
      IndicatorShortName("Trend Finder Ratchet v2 | ForexImpact.com");
      IndicatorBuffers(4);
      SetIndexBuffer(0, g_ibuf_224);
      SetIndexBuffer(1, g_ibuf_228);
      SetIndexBuffer(2, g_ibuf_432);
      SetIndexBuffer(3, g_ibuf_436);
      SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 2);
      SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 2);
      SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 0);
      SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 0);
      SetIndexArrow(0, 233);
      SetIndexArrow(1, 234);
      SetIndexArrow(2, 233);
      SetIndexArrow(3, 234);
      SetIndexEmptyValue(0, 0.0);
      SetIndexEmptyValue(1, 0.0);
      SetIndexEmptyValue(2, 0.0);
      SetIndexEmptyValue(3, 0.0);
      SetIndexLabel(0, "Green Arrow");
      SetIndexLabel(1, "Red Arrow");
      SetIndexLabel(2, "Exit Long Arrow");
      SetIndexLabel(3, "Exit Short Arrow");
      SetIndexDrawBegin(0, 10);
      SetIndexDrawBegin(1, 10);
      SetIndexDrawBegin(2, 10);
      SetIndexDrawBegin(3, 10);
      if (Period() == PERIOD_M1) gs_unused_468 = "1 Minute";
      if (Period() == PERIOD_M5) gs_unused_468 = "5 Minute";
      if (Period() == PERIOD_M15) gs_unused_468 = "15 Minute";
      if (Period() == PERIOD_M30) gs_unused_468 = "30 Minute";
      if (Period() == PERIOD_H1) gs_unused_468 = "60 Minute";
      if (Period() == PERIOD_H4) gs_unused_468 = "4 Hour";
      if (Period() == PERIOD_D1) gs_unused_468 = "Daily";
      if (Period() == PERIOD_W1) gs_unused_468 = "Weekly";
      if (Period() == PERIOD_MN1) gs_unused_468 = "Monthly";
      return (-1);
   }
   return (0);
}

int trendFinder_start() {
   if (g_time_464 != Time[0]) {
      if (g_ibuf_224[0] != 0.0 && g_ibuf_224[0] != EMPTY_VALUE && g_ibuf_224[1] == 0.0 || g_ibuf_224[1] == EMPTY_VALUE) g_time_464 = Time[0];
      if (g_ibuf_228[0] != 0.0 && g_ibuf_228[0] != EMPTY_VALUE && g_ibuf_228[1] == 0.0 || g_ibuf_228[1] == EMPTY_VALUE) g_time_464 = Time[0];
   }
   if (Copyright == "verCheckInfo") {
      gda_108[0] = gd_112;
      return (0);
   }
   if (Copyright == "9jawe09j09j()J)(JJ") {
      Ratchet();
      return (0);
   }
   if (Copyright == "koaijdsoDUDFIUONUIN") {
      SquishSquash();
      return (0);
   }
   if (Copyright == "o999jjdjfjjfjfjfjfjfjf") {
      HeikenAshi();
      return (0);
   }
   if (Copyright == "09uj089ju#$)JHFihuihdf") {
      PAC();
      return (0);
   }
   int l_ind_counted_0 = IndicatorCounted();
   int li_4 = Bars - l_ind_counted_0;
   if (li_4 > 0) li_4--;
   if (li_4 < 0) return (-1);
   for (int l_shift_8 = li_4; l_shift_8 >= 0; l_shift_8--) {
      g_icustom_288 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "9jawe09j09j()J)(JJ", "1", 0, l_shift_8);
      g_icustom_296 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "9jawe09j09j()J)(JJ", "2", 0, l_shift_8);
      g_icustom_304 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "9jawe09j09j()J)(JJ", "1", 0, l_shift_8 + 1);
      g_icustom_312 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "9jawe09j09j()J)(JJ", "2", 0, l_shift_8 + 1);
      g_icustom_336 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "koaijdsoDUDFIUONUIN", "", 0, l_shift_8);
      g_icustom_344 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "koaijdsoDUDFIUONUIN", "", 1, l_shift_8);
      g_icustom_352 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "koaijdsoDUDFIUONUIN", "", 0, l_shift_8 + 1);
      g_icustom_360 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "koaijdsoDUDFIUONUIN", "", 1, l_shift_8 + 1);
      g_icustom_384 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "o999jjdjfjjfjfjfjfjfjf", "", 2, l_shift_8 + 1);
      g_icustom_392 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "o999jjdjfjjfjfjfjfjfjf", "", 3, l_shift_8 + 1);
      g_icustom_408 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "o999jjdjfjjfjfjfjfjfjf", "", 2, l_shift_8);
      g_icustom_400 = iCustom(Symbol(), 0, "FXI+DelphiScalper", "o999jjdjfjjfjfjfjfjfjf", "", 3, l_shift_8);
      g_istochastic_424 = iStochastic(Symbol(), 0, g_period_184, g_period_188, g_slowing_192, MODE_SMA, 1, MODE_MAIN, l_shift_8);
      gi_unused_320 = 1;
      g_icustom_456 = g_icustom_400;
      if (gi_252 == -1 && g_ibuf_224[l_shift_8] != 0.0) g_ibuf_432[l_shift_8] = g_ibuf_224[l_shift_8];
      if (gi_252 == -1 && g_ibuf_228[l_shift_8] != 0.0) g_ibuf_436[l_shift_8] = g_ibuf_228[l_shift_8];
      if (gi_252 != -1 && g_ibuf_224[l_shift_8] != 0.0 || g_ibuf_228[l_shift_8] != 0.0 && g_ibuf_432[l_shift_8] != 0.0 || g_ibuf_436[l_shift_8] != 0.0) {
         g_ibuf_432[l_shift_8] = 0.0;
         g_ibuf_436[l_shift_8] = 0.0;
      }
      if (Close[l_shift_8] < iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "1", 2, l_shift_8)) gi_248 = 2;
      else gi_248 = 1;
      if (gi_252 == 1 && g_ibuf_224[l_shift_8 + 1] != 0.0) {
         if (g_icustom_400 < g_icustom_336 && (gi_120 && g_icustom_408 > g_icustom_400) || !gi_120) gi_252 = -1;
         if (Close[l_shift_8] < g_icustom_288) gi_252 = -1;
         if (Open[l_shift_8] < iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "1", 2, l_shift_8)) gi_252 = -1;
         if (gi_252 != 1) {
            gt_unused_440 = Time[l_shift_8];
            continue;
         }
         if (g_ibuf_224[l_shift_8] == 0.0 && gi_252 != -1) g_ibuf_224[l_shift_8] = iMA(Symbol(), 0, 5, 0, MODE_SMA, PRICE_LOW, l_shift_8) - 10.0 * Point;
      }
      if (gi_252 == 2 && g_ibuf_228[l_shift_8 + 1] != 0.0) {
         if (Close[l_shift_8] > g_icustom_288) gi_252 = -1;
         if (g_icustom_400 > g_icustom_344 && (gi_120 && g_icustom_408 < g_icustom_400) || !gi_120) gi_252 = -1;
         if (Open[l_shift_8] > iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "1", 2, l_shift_8)) gi_252 = -1;
         if (gi_252 != 2) {
            gt_unused_440 = Time[l_shift_8];
            continue;
         }
         if (g_ibuf_228[l_shift_8] == 0.0 && gi_252 != -1) g_ibuf_228[l_shift_8] = iMA(Symbol(), 0, 5, 0, MODE_SMA, PRICE_HIGH, l_shift_8) + 10.0 * Point;
      }
      if (gi_252 == -1 && gi_452 <= gi_124) {
         gi_252 = gi_248;
         if (gi_252 == 1 && Close[l_shift_8] < g_icustom_288) gi_252 = -1;
         if (gi_252 == 2 && Close[l_shift_8] > g_icustom_288) gi_252 = -1;
         if ((gi_252 == 1 && g_istochastic_424 < gi_196) || (gi_252 == 2 && g_istochastic_424 > gi_200)) gi_252 = -1;
         if (iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "0", 2, l_shift_8) > g_icustom_344 && iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "0", 2, l_shift_8) < g_icustom_336) {
            if (g_icustom_400 > iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "0", 2, l_shift_8) && gi_252 == 2) gi_252 = -1;
            if (g_icustom_400 < iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "0", 2, l_shift_8) && gi_252 == 1) gi_252 = -1;
         } else {
            if ((gi_252 == 1 && g_icustom_336 < iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "0", 2, l_shift_8)) || (gi_252 == 2 && g_icustom_344 > iCustom(NULL, 0, "FXI+DelphiScalper", "09uj089ju#$)JHFihuihdf", "0", 2, l_shift_8)) &&
               gi_252 != -1) gi_252 = -1;
         }
         if ((gi_252 == 1 && iCCI(NULL, 0, 14, PRICE_CLOSE, l_shift_8) < 100.0) || (gi_252 == 2 && iCCI(NULL, 0, 14, PRICE_CLOSE, l_shift_8) > -100.0)) gi_252 = -1;
         if (gi_252 == 1) {
            if (g_icustom_456 <= g_icustom_336) gi_252 = -1;
            else {
               if (g_ibuf_224[l_shift_8] == 0.0) {
                  g_ibuf_224[l_shift_8] = iMA(Symbol(), 0, 5, 0, MODE_SMA, PRICE_LOW, l_shift_8) - 10.0 * Point;
                  gt_unused_444 = Time[l_shift_8];
               }
            }
         }
         if (gi_252 == 2) {
            if (g_icustom_456 >= g_icustom_344) gi_252 = -1;
            else {
               if (g_ibuf_228[l_shift_8] == 0.0) {
                  g_ibuf_228[l_shift_8] = iMA(Symbol(), 0, 5, 0, MODE_SMA, PRICE_HIGH, l_shift_8) + 10.0 * Point;
                  gt_unused_444 = Time[l_shift_8];
               }
            }
         }
      }
   }
   return (0);
}

void slideArray(int ai_0, double ad_4, int ai_12) {
   for (int li_16 = ai_12 - 1; li_16 >= 0; li_16--) {
      if (ai_0 == 1) gda_524[li_16 + 1] = gda_524[li_16];
      else gda_528[li_16 + 1] = gda_528[li_16];
   }
   if (ai_0 == 1) gda_524[0] = ad_4;
   if (ai_0 == 2) gda_528[0] = ad_4;
}

int SquishSquash() {
   int l_index_68;
   int l_ind_counted_0 = IndicatorCounted();
   double ld_52 = 0;
   double ld_60 = 0;
   if (ArrayResize(gda_524, gi_508 + 2) == -1) {
      Print("Cannot resize array!");
      return (0);
   }
   if (ArrayResize(gda_528, gi_512 + 2) == -1) {
      Print("Cannot resize array!");
      return (0);
   }
   if (l_ind_counted_0 < 0) return (-1);
   int li_76 = Bars - l_ind_counted_0;
   momentum(li_76);
   for (int li_80 = li_76; li_80 >= 0; li_80--) {
      for (int li_72 = li_80; li_72 < li_80 + gd_476; li_72++) ld_52 += gd_484 * ((High[li_72] - Open[li_72]) / 2.0);
      ld_60 = ld_52 / gd_476;
      ld_52 = 0;
      slideArray(1, ld_60, gi_508);
      for (li_72 = li_80; li_72 < li_80 + gd_492; li_72++) ld_52 += gd_500 * ((Open[li_72] - Low[li_72]) / 2.0);
      ld_60 = ld_52 / gd_492;
      ld_52 = 0;
      slideArray(2, ld_60, gi_512);
      if (gda_528[gi_512] == EMPTY_VALUE || gda_524[gi_508] == EMPTY_VALUE) continue;
      l_index_68 = 0;
      for (li_72 = li_80; li_72 < li_80 + gi_508; li_72++) {
         ld_52 += High[li_72] + gda_524[l_index_68];
         l_index_68++;
      }
      if ((High[li_80 + 1] + (Low[li_80 + 1])) / 2.0 < (High[li_80] + Low[li_80]) / 2.0 && g_pips_516 * Point < g_ibuf_544[li_80]) ld_60 = ld_52 / gi_508 + g_ibuf_544[li_80];
      else ld_60 = ld_52 / gi_508;
      ld_52 = 0;
      g_ibuf_532[li_80] = ld_60;
      l_index_68 = 0;
      for (li_72 = li_80; li_72 < li_80 + gi_512; li_72++) {
         ld_52 += Low[li_72] - gda_528[l_index_68];
         l_index_68++;
      }
      if ((High[li_80 + 1] + (Low[li_80 + 1])) / 2.0 > (High[li_80] + Low[li_80]) / 2.0 && g_pips_516 * Point < g_ibuf_544[li_80]) ld_60 = ld_52 / gi_512 - g_ibuf_544[li_80];
      else ld_60 = ld_52 / gi_512;
      ld_52 = 0;
      g_ibuf_536[li_80] = ld_60;
      g_ibuf_540[li_80] = (g_ibuf_532[li_80] + g_ibuf_536[li_80]) / 2.0;
   }
   return (0);
}

void momentum(int ai_0) {
   for (int l_index_4 = 0; l_index_4 <= ai_0; l_index_4++) g_ibuf_544[l_index_4] = MathAbs((High[l_index_4 + 1] + (Low[l_index_4 + 1])) / 2.0 - (High[l_index_4] + Low[l_index_4]) / 2.0) / 2.0;
}

int Ratchet() {
   int l_ind_counted_0 = IndicatorCounted();
   int li_4 = Bars - l_ind_counted_0 - 1;
   if (li_4 > 0) li_4--;
   if (li_4 < 0) return (-1);
   for (int li_8 = li_4; li_8 >= 0; li_8--) {
      if (gi_548) gd_580 = Close[li_8];
      else gd_580 = Open[li_8];
      if (gi_252 == -1) {
         if (Open[li_8] > Close[li_8]) {
            gi_252 = 2;
            g_ibuf_556[li_8] = gi_252;
            g_time_576 = Time[li_8];
            g_ibuf_588[li_8] = High[li_8 + 1];
         } else {
            gi_252 = 1;
            g_ibuf_556[li_8] = gi_252;
            g_time_576 = Time[li_8];
            g_ibuf_588[li_8] = Low[li_8 + 1];
         }
      }
      if (gi_252 == 1 && Time[li_8] > g_time_576) {
         g_ibuf_556[li_8] = g_ibuf_556[li_8 + 1];
         if (gi_552) {
            if (Open[li_8 + 1] < Close[li_8 + 1]) g_ibuf_588[li_8] = g_ibuf_588[li_8 + 1] + (Close[li_8 + 1] - (Open[li_8 + 1]));
            else g_ibuf_588[li_8] = g_ibuf_588[li_8 + 1];
         } else g_ibuf_588[li_8] = g_ibuf_588[li_8 + 1] + MathAbs(Close[li_8 + 1] - (Open[li_8 + 1]));
         if (gd_580 < g_ibuf_588[li_8]) {
            g_time_576 = Time[li_8];
            g_ibuf_588[li_8] = High[li_8 + 1];
            gi_252 = 2;
            g_ibuf_556[li_8] = gi_252;
         }
      }
      if (gi_252 == 2 && Time[li_8] > g_time_576) {
         g_ibuf_556[li_8] = g_ibuf_556[li_8 + 1];
         if (gi_552) {
            if (Open[li_8 + 1] > Close[li_8 + 1]) g_ibuf_588[li_8] = g_ibuf_588[li_8 + 1] - (Open[li_8 + 1] - (Close[li_8 + 1]));
            else g_ibuf_588[li_8] = g_ibuf_588[li_8 + 1];
         } else g_ibuf_588[li_8] = g_ibuf_588[li_8 + 1] - MathAbs(Open[li_8 + 1] - (Close[li_8 + 1]));
         if (gd_580 > g_ibuf_588[li_8]) {
            gi_252 = 1;
            g_ibuf_556[li_8] = gi_252;
            g_time_576 = Time[li_8];
            g_ibuf_588[li_8] = Low[li_8 + 1];
         }
      }
   }
   return (0);
}

int HeikenAshi() {
   double ld_0;
   double ld_8;
   double ld_16;
   double ld_24;
   if (Bars <= 10) return (0);
   gi_604 = IndicatorCounted();
   if (gi_604 < 0) return (-1);
   if (gi_604 > 0) gi_604--;
   for (int li_32 = Bars - gi_604 - 1; li_32 >= 0; li_32--) {
      ld_24 = NormalizeDouble((Open[li_32] + High[li_32] + Low[li_32] + Close[li_32]) / 4.0, Digits);
      ld_0 = NormalizeDouble((g_ibuf_596[li_32 + 1] + (g_ibuf_600[li_32 + 1])) / 2.0, Digits);
      ld_8 = MathMax(High[li_32], MathMax(ld_0, ld_24));
      ld_16 = MathMin(Low[li_32], MathMin(ld_0, ld_24));
      if (ld_0 < ld_24) {
         g_ibuf_588[li_32] = ld_16;
         g_ibuf_592[li_32] = ld_8;
      } else {
         g_ibuf_588[li_32] = ld_8;
         g_ibuf_592[li_32] = ld_16;
      }
      g_ibuf_596[li_32] = ld_0;
      g_ibuf_600[li_32] = ld_24;
   }
   return (0);
}

int PAC() {
   double ld_8;
   int l_ind_counted_0 = IndicatorCounted();
   int li_4 = Bars - l_ind_counted_0;
   if (li_4 > 0) li_4--;
   if (li_4 < 0) return (-1);
   for (int li_16 = li_4; li_16 >= 0; li_16--) {
      g_ibuf_588[li_16] = High[iHighest(NULL, 0, MODE_HIGH, gi_128, li_16 + 1)];
      g_ibuf_592[li_16] = Low[iLowest(NULL, 0, MODE_LOW, gi_128, li_16 + 1)];
      ld_8 = MathAbs(g_ibuf_588[li_16] - g_ibuf_592[li_16]);
      g_ibuf_596[li_16] = ld_8 / 2.0 + g_ibuf_592[li_16];
      if (Open[li_16] > g_ibuf_596[li_16]) {
         g_ibuf_616[li_16] = 1.0;
         g_ibuf_620[li_16] = 0.0;
      } else {
         g_ibuf_616[li_16] = 0.0;
         g_ibuf_620[li_16] = 1.0;
      }
   }
   return (0);
}

int loginStart() {
   int l_str2int_0;
   bool li_4;
   int li_8;
   g_file_632 = FileOpen("fxi_d.bin", FILE_CSV|FILE_READ);
   if (g_file_632 < 1) li_4 = FALSE;
   else {
      l_str2int_0 = StrToInteger(FileReadString(g_file_632));
      FileClose(g_file_632);
      li_4 = TRUE;
   }
   if (TimeLocal() - l_str2int_0 >= 259200 || li_4 == FALSE) {
      li_8 = doLogin();
      switch (li_8) {
      case 0:
         Alert("Delphi Scalping -- Logged In");
         g_file_632 = FileOpen("fxi_d.bin", FILE_WRITE, 8);
         if (g_file_632 < 1) {
            Print("Cannot open password cache!");
            return (0);
         }
         FileWrite(g_file_632, TimeLocal());
         FileClose(g_file_632);
         break;
      case 1:
         Alert("Invalid key provided!! Please re-install the software with the correct key.");
         gi_636 = TRUE;
         break;
      case 4:
         Alert("Your account has been disabled! Please contact support@fximpact.com");
         gi_636 = TRUE;
         break;
      case 5:
         Alert("Server error!! Please make sure you are connected to the Internet and try again.");
         gi_636 = TRUE;
         break;
      case 6:
         Alert("No key found in your registry (bad install)! Please re-install the product.");
         gi_636 = TRUE;
      }
   }
   return (0);
}

int doLogin() {
   string ls_unused_0;
   string ls_unused_8;
   string ls_unused_16;
   string ls_24 = returnReg("Software\\FXI\\Delphi", "key");
   if (ls_24 == "") return (6);
   string ls_32 = "key=" + ls_24;
   string ls_40 = gGrab("http://www.foreximpact.com/delphi/d_login.php", ls_32);
   if (StringSubstr(ls_40, 0, 1) == "0") {
      gs_unused_640 = ls_40;
      return (0);
   }
   if (StringSubstr(ls_40, 0, 1) == "1") return (1);
   if (StringSubstr(ls_40, 0, 1) == "4") return (4);
   return (5);
}

int init() {
   //loginStart();
   //if (gi_636) return (0);
   if (doTFInit() < 0) return (0);
   return (0);
}

int deinit() {
   ObjectsDeleteAll(0, OBJ_ARROW);
   return (0);
}

int start() {
  // if (gi_636) return (0);
   if (Copyright == "LoadTrendFinder" || Copyright == "koaijdsoDUDFIUONUIN" || Copyright == "9jawe09j09j()J)(JJ" || Copyright == "o999jjdjfjjfjfjfjfjfjf" || Copyright == "09uj089ju#$)JHFihuihdf") {
      trendFinder_start();
      return (0);
   }
   int l_ind_counted_0 = IndicatorCounted();
   int li_4 = Bars - l_ind_counted_0;
   if (li_4 > 0) li_4--;
   if (li_4 < 0) return (-1);
   double l_icustom_8 = 0;
   double l_icustom_16 = 0;
   double l_icustom_24 = 0;
   double l_icustom_32 = 0;
   for (int li_40 = li_4; li_40 >= 0; li_40--) {
      l_icustom_8 = iCustom(Symbol(), 0, gs_624, "LoadTrendFinder", 0, li_40);
      l_icustom_16 = iCustom(Symbol(), 0, gs_624, "LoadTrendFinder", 1, li_40);
      l_icustom_24 = iCustom(Symbol(), 0, gs_624, "LoadTrendFinder", 0, li_40 + 1);
      l_icustom_32 = iCustom(Symbol(), 0, gs_624, "LoadTrendFinder", 1, li_40 + 1);
      if (l_icustom_24 == 0.0 && l_icustom_8 != 0.0) {
         if (ObjectFind("FXI_StrengthScalpL_" + Time[li_40]) == -1) {
            ObjectCreate("FXI_StrengthScalpL_" + Time[li_40], OBJ_ARROW, 0, Time[li_40], Low[li_40] - 50.0 * Point);
            ObjectSet("FXI_StrengthScalpL_" + Time[li_40], OBJPROP_ARROWCODE, 233);
            ObjectSet("FXI_StrengthScalpL_" + Time[li_40], OBJPROP_COLOR, UpArrow);
            ObjectSet("FXI_StrengthScalpL_" + Time[li_40], OBJPROP_WIDTH, 2);
         }
      }
      if (l_icustom_32 == 0.0 && l_icustom_16 != 0.0) {
         if (ObjectFind("FXI_StrengthScalpS_" + Time[li_40]) == -1) {
            ObjectCreate("FXI_StrengthScalpS_" + Time[li_40], OBJ_ARROW, 0, Time[li_40], High[li_40] + 50.0 * Point);
            ObjectSet("FXI_StrengthScalpS_" + Time[li_40], OBJPROP_ARROWCODE, 234);
            ObjectSet("FXI_StrengthScalpS_" + Time[li_40], OBJPROP_COLOR, DownArrow);
            ObjectSet("FXI_StrengthScalpS_" + Time[li_40], OBJPROP_WIDTH, 2);
         }
      }
   }
   return (0);
}