Navigation:Home > Content >

PipStrider_edu_v0.1.mq4

Time: 2010-01-25 | Download file:PipStrider_edu_v0.1.mq4

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

//#import "NxGnAllDay.dll"
//   int simpleclient(int a0, int a1);
//#import

extern string    Set_NF             = "||-------------------News filter set-------------------||";
extern bool      AvoidNews          = true;
extern int       MinimumImpact      = 1;
extern int       MinsBeforeNews     = 30;
extern int       MinsAfterNews      = 30;
extern string    Set_TF             = "||-------------------Time filter set-------------------||";
extern bool      UseTimeFilter      = false;    //If use or not time filter
extern int       TimeStartTrade     = 0;        //Time to start trade expert
extern int       TimeEndTrade       = 0;        //Time to stop trade expert
bool gi_76 = TRUE;
int gi_80 = D'19.04.2001 00:25:21';
string gs_84 = "NxGnAllDay v_1.30 ";
extern string version2 = "NxGnAllDay v_1.30 ";
extern string OWN = "Copyright © 2010-2011, Forex-Goldmine, Inc.";
bool gi_unused_108 = TRUE;
extern string _Comment = "NxGnAllDay ";
extern bool DoTrades = TRUE;
extern bool MonitorAndClose = FALSE;
extern bool StealthMode = FALSE;
extern bool AutoStealthMode = FALSE;
extern bool AllowLotsBeyondMaxSize = FALSE;
bool gi_140 = TRUE;
int gi_144 = 2;
extern int TradeDirection = 3;
extern int TradeRange = 15;
bool gi_156 = TRUE;
bool gi_160 = FALSE;
double gd_164 = 5.0;
extern int WaitPips = 0;
bool gi_176 = TRUE;
extern int StopLoss = 0;
extern string a1 = "----------------------------------------------";
extern string a2 = " Martingale Disrupter (tm) Technology";
extern bool UseMartingaleDisrupter = FALSE;
extern bool AdjustTakeProfit = FALSE;
extern double DisrupterClose = 0.75;
extern double DisrupterClose2 = 0.75;
double gd_224 = -10.0;
bool gi_232 = TRUE;
bool gi_236 = TRUE;
bool gi_240 = FALSE;
extern int OnlyAfterLevel = 6;
extern int OnlyAfterLevel2 = 6;
int gi_252 = 0;
extern int MaxBuyMartingaleLevel = 7;
extern int MaxSellMartingaleLevel = 7;
extern bool CloseBuyBeyondMax = FALSE;
extern bool CloseSellBeyondMax = FALSE;
extern double MaxDrawDownPct = 100.0;
extern bool LimitToThisPair = FALSE;
extern bool UseGridExpander = TRUE;
extern int ExpandPips = 0;
extern int ExpandPips2 = 0;
int gi_296 = 100;
int gi_unused_300 = 0;
int gi_unused_304 = 0;
extern string a3 = "----------------------------------------------";
extern double TradeLots = 0.0;
extern double BalanceFactor = 6000.0;
extern double ControlBalance = 0.0;
extern double LockInProfits = 0.0;
extern bool StopWhenProfitReached = FALSE;
extern string a4 = "Set to -1 to set 0 or a positive number to set actual value";
extern double ResetFundsWithdrawn = 0.0;
extern double MaxLots = 1000.0;
extern int MagicNumber = 734775;
extern bool Send_Email = FALSE;
extern int Send_Frequency = 0;
extern int Send_Minute = 0;
extern bool SUNDAY = TRUE;
extern bool MONDAY = TRUE;
extern bool TUESDAY = TRUE;
extern bool WEDNESDAY = TRUE;
extern bool THURSDAY = TRUE;
extern bool FRIDAY = TRUE;
extern bool ResetMaximums = FALSE;
extern int LookBackDays = 5;
double gd_424 = 2.0;
bool gi_432 = TRUE;
int g_period_436 = 7;
extern string note1 = "---- Caution! For Emergency Closing of Trades ---";
extern bool CloseAllBuyTrades = FALSE;
extern bool CloseAllSellTrades = FALSE;
int gi_unused_456 = 40;
int gi_460 = 40;
int gi_464 = 40;
int gi_468 = 30;
int gi_472 = 0;
double gd_unused_476 = 20.0;
double gd_484 = 0.01;
bool gi_492 = FALSE;
bool gi_496 = FALSE;
string gs_unused_500 = " ";
double gd_508 = 0.0;
double gd_516 = 0.0;
double g_ord_open_price_524 = 0.0;
double g_ord_open_price_532 = 0.0;
double gd_540 = 0.0;
double gd_548 = 0.0;
double gd_unused_556 = 0.0;
int gi_564 = 0;
int g_error_568 = 0/* NO_ERROR */;
double g_ord_open_price_572 = 0.0;
double gd_unused_580 = 0.0;
int gi_588 = 0;
int gi_592 = 0;
string g_comment_596 = " ";
int gi_604 = 3;
int g_color_608 = CLR_NONE;
int g_color_612 = CLR_NONE;
bool gi_616 = FALSE;
double gd_unused_620 = 0.0;
double gd_unused_628 = 0.0;
string gs_unused_636 = " ";
int gi_unused_644 = 0;
int gi_unused_648 = 0;
int gi_unused_652 = 0;
double gd_unused_656 = 0.0;
int gi_unused_664 = 0;
int gi_unused_668 = 0;
int gi_unused_672 = 0;
double gd_unused_676 = 0.0;
int gi_684 = 0;
int gi_688 = 0;
int gi_692 = 0;
int gi_unused_696 = 0;
int gi_unused_700 = 0;
int gi_unused_704 = 0;
int gi_unused_708 = 0;
int gi_unused_712 = 0;
double gd_unused_716 = 98765.43;
double gd_unused_724 = 98765.43;
int gi_732 = 2;
int gi_736 = 10;
double gd_740 = 0.0;
double gd_748 = 0.0;
bool g_bool_756 = TRUE;
double gd_760 = 0.0;
double gd_768 = 0.0;
int g_count_776 = 0;
int g_count_780 = 0;
int g_count_784 = 0;
int gi_788 = 0;
int g_global_var_792 = 0;
int g_global_var_796 = 0;
int gi_800 = 0;
int g_day_804 = 0;
string g_dbl2str_808 = "";
double g_ord_open_price_816 = 0.0;
double g_ord_open_price_824 = 0.0;
double g_ord_lots_832 = 0.0;
double g_ord_lots_840 = 0.0;
double gd_848 = 0.0;
double gd_856 = 0.0;
bool gi_864 = FALSE;
double gd_868 = 0.0;
double gd_876 = 0.0;
double gd_884 = 0.0;
double gda_892[3];
double gda_896[3];
double gda_900[3];
double gda_904[3];
double gd_908 = 0.0;
double gd_unused_916 = 0.0;
double gd_924 = 0.0;
double gd_932 = 0.0;
double gd_unused_940 = 0.0;
double gd_948 = 0.0;
int gi_956 = 0;
double gd_960 = 0.0;
double gd_968 = 0.0;
bool gi_976 = FALSE;
int gi_980 = 0;
int gi_984 = 30;
int gi_988 = 0;
int gi_992 = 0;
int gi_996 = 0;
int gi_1000 = 0;
double gd_1004 = 0.0;
int gi_1012 = 0;
double gd_1016 = 0.0;
double gd_1024 = 0.0;
int gi_1032 = 0;
int gi_1036 = 0;
double gd_1040 = 0.0;
double gd_1048 = 0.0;
double gd_1056 = 0.0;
string gs_1064 = " ";
int g_count_1072 = 0;
int g_count_1076 = 0;
int g_count_1080 = 0;
int g_count_1084 = 0;
int g_count_1088 = 0;
int g_count_1092 = 0;
int gi_1096 = 0;
int gi_1100 = 0;
double gd_1104 = 0.0;
double gd_1112 = 0.0;
int gi_1120 = 0;
int gi_unused_1124 = 0;
int gi_1128 = 0;
int g_acc_number_1132 = 0;
int gi_1136 = 7;
int gi_unused_1140 = 0;
int gi_unused_1144 = 0;

int init() {
   if (Send_Frequency != 0 && Send_Frequency != 60 && Send_Frequency != 240 && Send_Frequency != 480 && Send_Frequency != 720 && Send_Frequency != 1440) {
      Comment("Send_Frequency setting can only be 0, 60, 240, 480, 720 or 1440");
      return (-1);
   }
   if (Send_Minute < 0 || Send_Minute > 59) {
      Comment("Send_Minute must be between 0 and 59");
      return (-1);
   }
   gi_1128 = 1;
   //gi_1128 = GetAuth();
   //if (gi_1128 != 1) {
     // Comment("This EA is not licensed for this account");
     // return (-1);
   //}
   SetDirection();
   gi_1100 = FALSE;
   gi_684 = TradeRange;
   gi_688 = TradeRange;
   gi_692 = TradeRange;
   gd_876 = 0.0;
   gd_884 = 0.0;
   gi_996 = 30;
   gi_980 = FALSE;
   gi_252 = 0;
   gi_296 = 100;
   gd_224 = -10.0;
   gi_976 = StealthMode;
   gi_1036 = 10000;
   gi_1032 = 0;
   gd_1040 = 0.0;
   gd_1048 = 0.0;
   g_count_1072 = 0;
   g_count_1076 = 0;
   g_count_1080 = 0;
   g_count_1084 = 0;
   g_count_1088 = 0;
   g_count_1092 = 0;
   gi_1096 = FALSE;
   double l_lotsize_0 = MarketInfo(Symbol(), MODE_LOTSIZE);
   DisrupterClose /= 100000 / l_lotsize_0;
   DisrupterClose2 /= 100000 / l_lotsize_0;
   gd_224 /= 100000 / l_lotsize_0;
   ArrayInitialize(gda_892, 0.0);
   ArrayInitialize(gda_896, 0.0);
   ArrayInitialize(gda_900, 0.0);
   ArrayInitialize(gda_904, 0.0);
   if (StringSubstr(a1, 0, 1) == "3") {
      gi_252 = 6;
      gi_296 = 100;
      gd_224 = -10.0;
   }
   g_dbl2str_808 = DoubleToStr(MagicNumber, 0);
   g_dbl2str_808 = StringSubstr(g_dbl2str_808, 0, 2);
   if (!GlobalVariableCheck("GVMaxBuyLevel" + g_dbl2str_808 + Symbol())) GlobalVariableSet("GVMaxBuyLevel" + g_dbl2str_808 + Symbol(), 0);
   if (!GlobalVariableCheck("GVMaxSellLevel" + g_dbl2str_808 + Symbol())) GlobalVariableSet("GVMaxSellLevel" + g_dbl2str_808 + Symbol(), 0);
   if (!GlobalVariableCheck("GVFundsWithdrawn" + g_dbl2str_808 + Symbol())) GlobalVariableSet("GVFundsWithdrawn" + g_dbl2str_808 + Symbol(), 0.0);
   if (!GlobalVariableCheck("GVStealthMode" + g_dbl2str_808 + Symbol())) GlobalVariableSet("GVStealthMode" + g_dbl2str_808 + Symbol(), StealthMode);
   GetVariables();
   gd_848 = AccountBalance() - gd_856;
   if (gd_848 < ControlBalance) gd_848 += gd_856;
   if (ResetFundsWithdrawn > 0.0) {
      gd_856 = ResetFundsWithdrawn;
      GlobalVariableSet("GVFundsWithdrawn" + g_dbl2str_808 + Symbol(), ResetFundsWithdrawn);
      ResetFundsWithdrawn = 0.0;
      WriteVariables();
   }
   if (ResetFundsWithdrawn < 0.0) {
      gd_856 = 0.0;
      GlobalVariableSet("GVFundsWithdrawn" + g_dbl2str_808 + Symbol(), 0.0);
      ResetFundsWithdrawn = 0.0;
      WriteVariables();
   }
   gd_848 = AccountBalance() - gd_856;
   if (gd_848 < ControlBalance) gd_848 += gd_856;
   g_bool_756 = DoTrades;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 1.0) gi_732 = 1;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.1) gi_732 = 2;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.01) gi_732 = 3;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.001) gi_732 = 4;
   if (MarketInfo(Symbol(), MODE_MINLOT) < 0.0001) gi_732 = 5;
   gi_984 = 30;
   CalculateTradeRange();
   if (Digits == 5 || Digits == 3) {
      StopLoss = 10 * StopLoss;
      ExpandPips = 10 * ExpandPips;
      ExpandPips2 = 10 * ExpandPips2;
      gi_296 = 10 * gi_296;
      gi_984 = 300;
      WaitPips = 10 * WaitPips;
      gd_164 = 10.0 * gd_164;
   }
   gi_1012 = gi_684;
   gi_unused_456 = gi_684;
   gi_460 = gi_684;
   gi_464 = gi_684;
   gi_468 = gi_684;
   CheckStealthMode();
   CalculateLots();
   gd_unused_716 = 98765.43;
   gd_unused_724 = 98765.43;
   EvaluateTrades();
   SetDirection();
   if (ResetMaximums) {
      g_global_var_796 = 0;
      g_global_var_792 = 0;
      WriteVariables();
   }
   if (gi_472 >= 0) {
      gd_484 = gd_516 * gi_144;
      gd_484 = NormalizeDouble(gd_484, gi_732);
      gi_460 = gi_688;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_780 >= OnlyAfterLevel) gi_460 = gi_688 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_780 >= OnlyAfterLevel2) gi_460 = gi_688 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_780 >= gi_252) gi_460 = gi_688 + gi_296;
      gd_760 = gd_484;
      gd_740 = g_ord_open_price_532 - gi_460 * Point;
   }
   if (gi_472 <= 0) {
      gd_484 = gd_508 * gi_144;
      gd_484 = NormalizeDouble(gd_484, gi_732);
      gi_464 = gi_692;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_784 >= OnlyAfterLevel) gi_464 = gi_692 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_784 >= OnlyAfterLevel2) gi_464 = gi_692 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_784 >= gi_252) gi_464 = gi_692 + gi_296;
      gd_768 = gd_484;
      gd_748 = g_ord_open_price_524 + gi_464 * Point;
   }
   if (gd_508 == 0.0) g_count_784 = 0;
   if (gd_516 == 0.0) g_count_780 = 0;
   if (g_count_784 > g_global_var_796) g_global_var_796 = g_count_784;
   if (g_count_780 > g_global_var_792) g_global_var_792 = g_count_780;
   CalculateHighAndLow();
   WriteVariables();
   if (gi_496 || StringSubstr(a1, 0, 1) == "m") SendTheMail();
   if (!IsTesting()) DisplayComments();
   return (0);
}

int deinit() {
   gd_848 = AccountBalance() - gd_856;
   if (gd_848 < ControlBalance / 10.0 || gd_848 < 0.0) gd_848 = AccountBalance();
   Print("Min TradeRange Was " + gi_1036);
   Print("Max TradeRange Was " + gi_1032);
   Print("Max DrawDown Percent Reached Was " + DoubleToStr(100.0 * gd_1024, 2));
   Print("Max Buy Martingale Level Reached Was " + g_global_var_792);
   Print("Max Sell Martingale Level Reached Was " + g_global_var_796);
   if (g_count_1072 > 0) Print("Level 4 Counter = " + g_count_1072);
   if (g_count_1076 > 0) Print("Level 5 Counter = " + g_count_1076);
   if (g_count_1080 > 0) Print("Level 6 Counter = " + g_count_1080);
   if (g_count_1084 > 0) Print("Level 7 Counter = " + g_count_1084);
   if (g_count_1088 > 0) Print("Level 8 Counter = " + g_count_1088);
   if (g_count_1092 > 0) Print("Level 9 Counter = " + g_count_1092);
   Print("Working Balance Was " + DoubleToStr(gd_848, 2));
   Print("Funds Withdrawn Was " + DoubleToStr(gd_856, 2));
   DeleteAllObjects();
   return (0);
}

int start()
{
  int total=OrdersTotal();
//+-----------------------------------------------------------------------------------------------------+
//TIME FILTER PART//
  if(UseTimeFilter==true)
  {
  if((TimeStartTrade< TimeEndTrade)&&((TimeHour(TimeCurrent())TimeEndTrade))) return(0);
  else
  if((TimeStartTrade>TimeEndTrade)&&((TimeHour(TimeCurrent())=TimeEndTrade))) return(0);
  }
//+-----------------------------------------------------------------------------------------------------+
//NEWS FILTER PART//
  bool ContinueTrading=true;
  if(AvoidNews)
  {
  static int PrevMinute=-1;  
  int MinSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,0);
  int MinToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,1,1);
  int ImpactSinceNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,0);
  int ImpactToNews=iCustom(NULL,0,"FFCal",true,true,false,true,true,2,1);
  if(Minute()!=PrevMinute)
  {
  PrevMinute=Minute();
  if((MinToNews<=MinsBeforeNews&&ImpactToNews>=MinimumImpact)||(MinSinceNews<=MinsAfterNews&&ImpactSinceNews>=MinimumImpact))ContinueTrading=false;
  }
  }
//+-----------------------------------------------------------------------------------------------------+
//AUTO SET MonitorAndClose//
  int SumTrades=0;
  for(int i=total-1; i>=0; i--)
  {
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
  {
  if(OrderMagicNumber()==MagicNumber) SumTrades++;
  }
  }
  if(SumTrades>0) MonitorAndClose=true;
  if(SumTrades==0) MonitorAndClose=false;
//+-----------------------------------------------------------------------------------------------------+
//|---------close trades
  if(ContinueTrading==false)
  {
  for(int q=total-1; q>=0; q--)
  {
  OrderSelect(q,SELECT_BY_POS);
  int type=OrderType();
  bool result=false;
  switch(type)
  {
  //Close opened long positions
  case OP_BUY: result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Red);
  break;
  //Close opened short positions
  case OP_SELL: result=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Red);
  break;
  }
  if(result==false)
  {
  Alert("Order ",OrderTicket()," failed to close. Error:",GetLastError());
  Sleep(3000);
  }  
  }
  return(0);
  }
//+-----------------------------------------------------------------------------------------------------+
   double ld_0;
   int li_8;
   bool li_12;
   if (Send_Frequency != 0 && Send_Frequency != 60 && Send_Frequency != 240 && Send_Frequency != 480 && Send_Frequency != 720 && Send_Frequency != 1440) {
      Comment("Send_Frequency setting can only be 0, 60, 240, 480, 720 or 1440");
      return (-1);
   }
   if (Send_Minute < 0 || Send_Minute > 59) {
      Comment("Send_Minute must be between 0 and 59");
      return (-1);
   }
   if (gi_1128 != 1) {
      Comment("This EA is not licensed for this account");
      return (-1);
   }
   GetVariables();
   CheckProfitGrab();
   if (StopWhenProfitReached && ControlBalance > 0.0 && LockInProfits > 0.0 && gd_856 > 0.0) {
      if (AccountEquity() >= ControlBalance + LockInProfits) {
         Print("Close of all trades due to profit target reached");
         ClosePairType(OP_BUY);
         ClosePairType(OP_SELL);
         return (0);
      }
   }
   g_bool_756 = FALSE;
   if (DoTrades == TRUE && (DayOfWeek() == 1 && MONDAY) || (DayOfWeek() == 2 && TUESDAY) || (DayOfWeek() == 3 && WEDNESDAY) || (DayOfWeek() == 4 && THURSDAY) || (DayOfWeek() == 5 &&
      FRIDAY) || (DayOfWeek() == 0 && SUNDAY)) g_bool_756 = TRUE;
   CheckStealthMode();
   CalculateLots();
   if (!UseMartingaleDisrupter) TestDrawdownPct();
   if (UseMartingaleDisrupter) RunMartingaleDisrupter();
   if (CloseAllBuyTrades) ClosePairType(OP_BUY);
   if (CloseAllSellTrades) ClosePairType(OP_SELL);
   if (!gi_432) CalculateTradeRange();
   if (gi_432) {
      ld_0 = gi_684;
      CalculateTradeRange();
      if (gi_156 && gi_684 < ld_0) gi_684 = ld_0;
   }
   EvaluateTrades();
   if (g_count_784 > g_global_var_796) g_global_var_796 = g_count_784;
   if (g_count_780 > g_global_var_792) g_global_var_792 = g_count_780;
   CalculateHighAndLow();
   SetDirection();
   if (gi_472 >= 0) {
      gd_484 = gd_516 * gi_144;
      gd_484 = NormalizeDouble(gd_484, gi_732);
      gi_460 = gi_688;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_780 >= OnlyAfterLevel) gi_460 = gi_688 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_780 >= OnlyAfterLevel2) gi_460 = gi_688 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_780 >= gi_252) gi_460 = gi_688 + gi_296;
      gd_760 = gd_484;
      gd_740 = g_ord_open_price_532 - gi_460 * Point;
   }
   if (gi_472 <= 0) {
      gd_484 = gd_508 * gi_144;
      gd_484 = NormalizeDouble(gd_484, gi_732);
      gi_464 = gi_692;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_784 >= OnlyAfterLevel) gi_464 = gi_692 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_784 >= OnlyAfterLevel2) gi_464 = gi_692 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_784 >= gi_252) gi_464 = gi_692 + gi_296;
      gd_768 = gd_484;
      gd_748 = g_ord_open_price_524 + gi_464 * Point;
   }
   if (gd_516 == 0.0 && gi_472 >= 0 && WaitPips > 0 && gd_1104 == 0.0) gd_1104 = Ask - WaitPips * Point;
   if (g_bool_756 == TRUE && MonitorAndClose == FALSE && gi_472 >= 0 && gd_516 == 0.0 && WaitPips == 0 || Ask <= gd_1104) {
      CalculateTradeRange();
      gi_1012 = gi_688;
      if (!IsTesting()) {
         gi_1128 = 1;
         //gi_1128 = GetAuth();
         if (gi_1128 != 1) {
            if (Send_Email && gi_1100 == FALSE) SendTheSecurityMail();
            gi_1100 = TRUE;
            Comment("This EA is not licensed for this account");
            return (-1);
         }
      }
      if (_IsTradeAllowed() == 1) open_buy_market(gd_548, MagicNumber);
      gi_1100 = FALSE;
      gd_1104 = 0.0;
      ArrayInitialize(gda_892, 0.0);
      ArrayInitialize(gda_896, 0.0);
      ArrayInitialize(gda_900, 0.0);
      ArrayInitialize(gda_904, 0.0);
      gi_988 = FALSE;
      gi_1096 = FALSE;
      gi_996 = 30;
   }
   if (gd_508 == 0.0 && gi_472 <= 0 && WaitPips > 0 && gd_1112 == 0.0) gd_1112 = Bid + WaitPips * Point;
   if (g_bool_756 == TRUE && MonitorAndClose == FALSE && gi_472 <= 0 && gd_508 == 0.0 && WaitPips == 0 || Bid >= gd_1112) {
      CalculateTradeRange();
      gi_1012 = gi_692;
      if (!IsTesting()) {
         gi_1128 = 1;
         //gi_1128 = GetAuth();
         if (gi_1128 != 1) {
            if (Send_Email && gi_1100 == FALSE) SendTheSecurityMail();
            gi_1100 = TRUE;
            Comment("This EA is not licensed for this account");
            return (-1);
         }
      }
      if (_IsTradeAllowed() == 1) open_sell_market(gd_548, MagicNumber);
      gd_1112 = 0;
      gi_1100 = FALSE;
      ArrayInitialize(gda_892, 0.0);
      ArrayInitialize(gda_896, 0.0);
      ArrayInitialize(gda_900, 0.0);
      ArrayInitialize(gda_904, 0.0);
      gi_992 = FALSE;
      gi_1096 = FALSE;
      gi_996 = 30;
   }
   if (g_bool_756 == TRUE || MonitorAndClose == TRUE && gi_472 >= 0 && gd_516 > 0.0) {
      if ((!gi_160 && Ask <= gd_740) || (gi_160 && Ask <= gd_740 && Ask >= gd_740 - gd_164 * Point)) {
         g_count_780 = GetMartingaleLevel2(2);
         g_count_780++;
         GetMartingaleLevel(gd_760);
         if (g_count_776 > g_count_780) g_count_780 = g_count_776;
         if (MaxBuyMartingaleLevel == 0 || (g_count_780 <= MaxBuyMartingaleLevel && MaxBuyMartingaleLevel > 0)) {
            if (_IsTradeAllowed() == 1) open_buy_market(gd_760, MagicNumber);
            ArrayInitialize(gda_892, 0.0);
            ArrayInitialize(gda_896, 0.0);
            ArrayInitialize(gda_900, 0.0);
            ArrayInitialize(gda_904, 0.0);
            if (g_count_780 == 4) g_count_1072++;
            if (g_count_780 == 5) g_count_1076++;
            if (g_count_780 == 6) g_count_1080++;
            if (g_count_780 == 7) g_count_1084++;
            if (g_count_780 == 8) g_count_1088++;
            if (g_count_780 == 9) g_count_1092++;
            gi_988 = FALSE;
            gi_1096 = FALSE;
            gi_996 = 30;
         }
         if (UseMartingaleDisrupter && MaxBuyMartingaleLevel > 0 && g_count_780 > MaxBuyMartingaleLevel && CloseBuyBeyondMax) {
            Print("Close of all buy trades due to max martingale level surpassed.");
            ClosePairType(OP_BUY);
         }
      }
   }
   if (g_bool_756 == TRUE || MonitorAndClose == TRUE && gi_472 <= 0 && gd_508 > 0.0) {
      if ((!gi_160 && Bid >= gd_748) || (gi_160 && Bid >= gd_748 && Bid <= gd_748 + gd_164 * Point)) {
         g_count_784 = GetMartingaleLevel2(1);
         g_count_784++;
         GetMartingaleLevel(gd_768);
         if (g_count_776 > g_count_784) g_count_784 = g_count_776;
         if (MaxSellMartingaleLevel == 0 || (g_count_784 <= MaxSellMartingaleLevel && MaxSellMartingaleLevel > 0)) {
            if (_IsTradeAllowed() == 1) open_sell_market(gd_768, MagicNumber);
            ArrayInitialize(gda_892, 0.0);
            ArrayInitialize(gda_896, 0.0);
            ArrayInitialize(gda_900, 0.0);
            ArrayInitialize(gda_904, 0.0);
            if (g_count_784 == 4) g_count_1072++;
            if (g_count_784 == 5) g_count_1076++;
            if (g_count_784 == 6) g_count_1080++;
            if (g_count_784 == 7) g_count_1084++;
            if (g_count_784 == 8) g_count_1088++;
            if (g_count_784 == 9) g_count_1092++;
            gi_992 = FALSE;
            gi_1096 = FALSE;
            gi_996 = 30;
         }
         if (UseMartingaleDisrupter && MaxSellMartingaleLevel > 0 && g_count_784 > MaxSellMartingaleLevel && CloseSellBeyondMax) {
            Print("Close of all sell trades due to max martingale level surpassed.");
            ClosePairType(OP_SELL);
         }
      }
   }
   gi_996 += 1;
   if (gd_876 == 0.0 || gd_884 == 0.0) gi_996 = 30;
   if (gi_996 >= 2) {
      TestTakeProfit();
      gi_996 = 0;
   }
   CalculateClosePrice();
   WriteVariables();
   if (Send_Email) {
      li_8 = Send_Minute + 15;
      if (li_8 > 59) li_8 -= 60;
      if (Minute() > li_8) gi_788 = FALSE;
      if (gi_788 == FALSE) {
         li_12 = FALSE;
         if (Send_Frequency == 60 && Minute() >= Send_Minute && Minute() < li_8) li_12 = TRUE;
         if (Send_Frequency == 240 && Minute() >= Send_Minute && Minute() < li_8 && Hour() == 0 || Hour() == 4 || Hour() == 8 || Hour() == 12 || Hour() == 16 || Hour() == 20) li_12 = TRUE;
         if (Send_Frequency == 480 && Minute() >= Send_Minute && Minute() < li_8 && Hour() == 0 || Hour() == 8 || Hour() == 16) li_12 = TRUE;
         if (Send_Frequency == 720 && Minute() >= Send_Minute && Minute() < li_8 && Hour() == 0 || Hour() == 12) li_12 = TRUE;
         if (Send_Frequency == 1440 && Minute() >= Send_Minute && Minute() < li_8 && Hour() == 0) li_12 = TRUE;
         if (gi_788 == TRUE) li_12 = FALSE;
         if (li_12) {
            SendTheMail();
            gi_788 = TRUE;
         }
      }
   }
   if (IsTesting()) {
      if (Day() != g_day_804) gi_800 = FALSE;
      if (gi_800 == FALSE) {
         CalculateDrawDownPct();
         Print("Min TradeRange Used = " + gi_1036);
         Print("Max TradeRange Used = " + gi_1032);
         Print("Max DrawDown Percent Reached is " + DoubleToStr(100.0 * gd_1024, 2));
         Print("Max Buy Martingale Level Reached is " + g_global_var_792);
         Print("Max Sell Martingale Level Reached is " + g_global_var_796);
         Print(gs_1064 + DoubleToStr(100.0 * gd_1056, 2));
         Print("Current Buy TradeRange = " + gi_688);
         Print("Current Sell TradeRange = " + gi_692);
         Print("Current Buy Martingale Level is " + g_count_780);
         Print("Current Sell Martingale Level is " + g_count_784);
         if (g_count_1072 > 0) Print("Level 4 Counter = " + g_count_1072);
         if (g_count_1076 > 0) Print("Level 5 Counter = " + g_count_1076);
         if (g_count_1080 > 0) Print("Level 6 Counter = " + g_count_1080);
         if (g_count_1084 > 0) Print("Level 7 Counter = " + g_count_1084);
         if (g_count_1088 > 0) Print("Level 8 Counter = " + g_count_1088);
         if (g_count_1092 > 0) Print("Level 9 Counter = " + g_count_1092);
         Print("Working Balance is " + DoubleToStr(gd_848, 2));
         Print("Funds Withdrawn is " + DoubleToStr(gd_856, 2));
         gi_800 = TRUE;
         g_day_804 = Day();
      }
   }
   if (!IsTesting()) DisplayComments();
   return (0);
}

/*double AddLots2(string a_symbol_0, int ai_8) {
   double ld_ret_12 = 0.0;
   gi_564 = OrdersTotal();
   for (int l_pos_20 = gi_564 - 1; l_pos_20 >= 0; l_pos_20--) {
      if (!OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES)) {
         g_error_568 = GetLastError();
         Print("OrderSelect( ", l_pos_20, ", SELECT_BY_POS ) - Error #", g_error_568);
      } else {
         if (OrderSymbol() == a_symbol_0) {
            if (OrderMagicNumber() == MagicNumber) {
               if (ai_8 == 1 && OrderType() == OP_BUY) continue;
               if (ai_8 == 2 && OrderType() == OP_SELL) continue;
               if (OrderCloseTime() == 0) ld_ret_12 += OrderLots();
            }
         }
      }
   }
   return (ld_ret_12);
}*/

double EAProfitAll(int ai_0) {
   double ld_ret_4 = 0.0;
   bool li_12 = FALSE;
   gi_564 = OrdersTotal();
   for (int l_pos_16 = 0; l_pos_16 <= gi_564 - 1; l_pos_16++) {
      if (!OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
         g_error_568 = GetLastError();
         Print("OrderSelect( ", l_pos_16, ", SELECT_BY_POS ) - Error #", g_error_568);
      } else {
         if (OrderSymbol() == Symbol()) {
            if (OrderMagicNumber() == MagicNumber) {
               if (ai_0 == 1 && OrderType() == OP_BUY) continue;
               if (ai_0 == 2 && OrderType() == OP_SELL) continue;
               if (OrderCloseTime() == 0) {
                  li_12 = FALSE;
                  if (gi_232 && ai_0 == 2) li_12 = TRUE;
                  if (gi_236 && ai_0 == 1) li_12 = TRUE;
                  if (gi_240 && ai_0 == 2 && g_count_780 >= OnlyAfterLevel2 && OrderSwap() < 0.0) li_12 = FALSE;
                  if (gi_240 && ai_0 == 1 && g_count_784 >= OnlyAfterLevel2 && OrderSwap() < 0.0) li_12 = FALSE;
                  ld_ret_4 += OrderProfit();
                  if (li_12) ld_ret_4 += OrderSwap();
               }
            }
         }
      }
   }
   return (ld_ret_4);
}

void CalculateHighAndLow() {
   double l_ihigh_0 = iHigh(Symbol(), PERIOD_D1, iHighest(Symbol(), PERIOD_D1, MODE_HIGH, LookBackDays, 0));
   double l_ilow_8 = iLow(Symbol(), PERIOD_D1, iLowest(Symbol(), PERIOD_D1, MODE_LOW, LookBackDays, 0));
   gd_540 = (l_ihigh_0 + l_ilow_8) / 2.0;
   gd_540 = NormalizeDouble(gd_540, Digits);
}

void DeleteAllObjects() {
   string l_name_4;
   int l_objs_total_0 = ObjectsTotal();
   for (int li_12 = 0; li_12 < l_objs_total_0; li_12++) {
      l_name_4 = ObjectName(li_12);
      if (l_name_4 != "") ObjectDelete(l_name_4);
   }
   ObjectDelete("FLP_txt");
   ObjectDelete("P_txt");
}

void ClosePairType(int a_cmd_0) {
   int l_cmd_16;
   int l_ticket_20;
   double l_ord_lots_24;
   string l_symbol_32;
   int l_ord_total_4 = OrdersTotal();
   for (int l_count_8 = 0; l_count_8 < 5; l_count_8++) {
      for (int l_pos_12 = 0; l_pos_12 < l_ord_total_4; l_pos_12++) {
         while (!IsTradeAllowed()) {
         }
         OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
         l_cmd_16 = OrderType();
         l_ticket_20 = OrderTicket();
         l_ord_lots_24 = OrderLots();
         l_symbol_32 = OrderSymbol();
         if (l_symbol_32 == Symbol() && l_cmd_16 == OP_BUY && l_cmd_16 == a_cmd_0 && OrderMagicNumber() == MagicNumber) OrderClose(l_ticket_20, l_ord_lots_24, MarketInfo(l_symbol_32, MODE_BID), 3, CLR_NONE);
         if (l_symbol_32 == Symbol() && l_cmd_16 == OP_SELL && l_cmd_16 == a_cmd_0 && OrderMagicNumber() == MagicNumber) OrderClose(l_ticket_20, l_ord_lots_24, MarketInfo(l_symbol_32, MODE_ASK), 3, CLR_NONE);
      }
   }
}

double search_for(int ai_0) {
   double ld_ret_4 = 0.0;
   double l_ord_open_price_12 = 0.0;
   gi_564 = OrdersTotal();
   double ld_unused_20 = 0.0;
   double ld_unused_28 = 0.0;
   double ld_36 = MathFloor(gi_688 / 2) * Point;
   if (ai_0 == 1) ld_36 = MathFloor(gi_692 / 2) * Point;
   bool li_44 = FALSE;
   bool li_48 = FALSE;
   if (ai_0 == 1) g_ord_open_price_824 = 0.0;
   if (ai_0 == 2) g_ord_open_price_816 = 0.0;
   if (ai_0 == 1) g_ord_lots_840 = 0.0;
   if (ai_0 == 2) g_ord_lots_832 = 0.0;
   int li_unused_52 = 0;
   for (int l_pos_56 = gi_564 - 1; l_pos_56 >= 0; l_pos_56--) {
      if (!OrderSelect(l_pos_56, SELECT_BY_POS, MODE_TRADES)) {
         g_error_568 = GetLastError();
         Print("OrderSelect( ", l_pos_56, ", SELECT_BY_POS ) - Error #", g_error_568);
      } else {
         if (OrderSymbol() == Symbol()) {
            if (OrderMagicNumber() == MagicNumber) {
               if (OrderCloseTime() == 0) {
                  if (ai_0 == 1 && OrderType() == OP_BUY) continue;
                  if (ai_0 == 2 && OrderType() == OP_SELL) continue;
                  if (ai_0 == 2 && l_ord_open_price_12 != 0.0 && OrderOpenPrice() > l_ord_open_price_12 + ld_36 || !AllowLotsBeyondMaxSize) {
                     if (li_48 == FALSE) g_ord_open_price_816 = OrderOpenPrice();
                     g_ord_open_price_816 = NormalizeDouble(g_ord_open_price_816, Digits);
                     g_ord_lots_832 = OrderLots();
                     li_48 = TRUE;
                  } else {
                     if (ai_0 == 1 && l_ord_open_price_12 != 0.0 && OrderOpenPrice() < l_ord_open_price_12 - ld_36 || !AllowLotsBeyondMaxSize) {
                        if (li_44 == FALSE) g_ord_open_price_824 = OrderOpenPrice();
                        g_ord_open_price_824 = NormalizeDouble(g_ord_open_price_824, Digits);
                        g_ord_lots_840 = OrderLots();
                        li_44 = TRUE;
                     } else {
                        if (MathAbs(l_ord_open_price_12 - OrderOpenPrice()) > ld_36 || !AllowLotsBeyondMaxSize) ld_ret_4 = OrderLots();
                        if (MathAbs(l_ord_open_price_12 - OrderOpenPrice()) < ld_36 && AllowLotsBeyondMaxSize) ld_ret_4 += OrderLots();
                        g_ord_open_price_572 = OrderOpenPrice();
                        l_ord_open_price_12 = OrderOpenPrice();
                     }
                  }
               }
            }
         }
      }
   }
   return (ld_ret_4);
}

void AddTakeProfit(int ai_0, double ad_4) {
   double ld_unused_12 = 0.0;
   gi_564 = OrdersTotal();
   double ld_20 = 0.0;
   double ld_28 = 0.0;
   for (int l_pos_36 = gi_564 - 1; l_pos_36 >= 0; l_pos_36--) {
      if (!OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) {
         g_error_568 = GetLastError();
         Print("OrderSelect( ", l_pos_36, ", SELECT_BY_POS ) - Error #", g_error_568);
      } else {
         if (OrderSymbol() == Symbol()) {
            if (OrderMagicNumber() == MagicNumber) {
               if (OrderCloseTime() == 0) {
                  if (ai_0 == 1 && OrderType() == OP_BUY) continue;
                  if (ai_0 == 2 && OrderType() == OP_SELL) continue;
                  if (ai_0 == 2 && ad_4 != 0.0) ld_20 = NormalizeDouble(ad_4, Digits);
                  if (ai_0 == 1 && ad_4 != 0.0) ld_20 = NormalizeDouble(ad_4, Digits);
                  if (ai_0 == 2 && StopLoss != 0) ld_28 = NormalizeDouble(g_ord_open_price_532 - StopLoss * Point, Digits);
                  if (ai_0 == 1 && StopLoss != 0) ld_28 = NormalizeDouble(g_ord_open_price_524 + StopLoss * Point, Digits);
                  if (gi_976 == FALSE) {
                     if (OrderTakeProfit() != ld_20 && ld_20 != 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), NormalizeDouble(ld_20, Digits), 0, CLR_NONE);
                     if (StopLoss != 0 && OrderStopLoss() != ld_28 && ld_28 != 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(ld_28, Digits), OrderTakeProfit(), 0, CLR_NONE);
                  }
                  if (gi_976 == TRUE) {
                     if (OrderTakeProfit() != 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), 0.0, 0, CLR_NONE);
                     if (OrderStopLoss() != 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), 0.0, OrderTakeProfit(), 0, CLR_NONE);
                     if (ld_28 != 0.0 && StopLoss != 0 && ai_0 == 2 && Bid <= ld_28) OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_BID), 3, CLR_NONE);
                     if (ld_28 != 0.0 && StopLoss != 0 && ai_0 == 1 && Ask >= ld_28) OrderClose(OrderTicket(), OrderLots(), MarketInfo(Symbol(), MODE_ASK), 3, CLR_NONE);
                  }
               }
            }
         }
      }
   }
}

int _IsTradeAllowed() {
   int li_4;
   int li_0 = 30;
   if (!IsTradeAllowed()) {
      li_4 = GetTickCount();
      Print("Trade context is busy! Wait until it is free...");
      while (true) {
         if (IsStopped()) {
            Print("The expert was terminated by the user!");
            return (-1);
         }
         if (GetTickCount() - li_4 > 1000 * li_0) {
            Print("The waiting limit exceeded (" + li_0 + " ???.)!");
            return (-2);
         }
         if (IsTradeAllowed()) {
            Print("Trade context has become free!");
            RefreshRates();
            return (1);
         }
         Sleep(100);
      }
   }
   return (1);
}

int open_buy_market(double a_lots_0, int a_magic_8) {
   int l_slippage_44;
   int l_count_48;
   int l_ticket_52;
   double l_price_56;
   double l_maxlot_12 = MarketInfo(Symbol(), MODE_MAXLOT);
   double l_minlot_20 = MarketInfo(Symbol(), MODE_MINLOT);
   double ld_28 = a_lots_0;
   double l_price_36 = 0.0;
   if (!AllowLotsBeyondMaxSize && ld_28 > l_maxlot_12) ld_28 = l_maxlot_12;
   l_price_36 = 0.0;
   l_price_36 = NormalizeDouble(l_price_36, Digits);
   while (ld_28 > 0.0) {
      a_lots_0 = ld_28;
      if (a_lots_0 > l_maxlot_12) a_lots_0 = l_maxlot_12;
      if (a_lots_0 < l_minlot_20) a_lots_0 = l_minlot_20;
      a_lots_0 = NormalizeDouble(a_lots_0, gi_732);
      ld_28 -= a_lots_0;
      l_slippage_44 = gi_736;
      l_count_48 = 0;
      l_ticket_52 = -1;
      l_price_56 = 0.0;
      if (gi_140 == TRUE && gi_588 != 0) {
         l_price_56 = Ask + gi_588 * Point;
         l_price_56 = NormalizeDouble(l_price_56, Digits);
      }
      if (gi_140 == FALSE && gi_592 != 0 && gi_588 != 0) {
         l_price_56 = Ask + (gi_588 + gi_592) * Point;
         l_price_56 = NormalizeDouble(l_price_56, Digits);
      }
      l_price_56 = 0.0;
      l_price_56 = NormalizeDouble(l_price_56, Digits);
      g_comment_596 = _Comment + " " + DoubleToStr(a_magic_8, 0);
      while (l_ticket_52 == -1 && l_count_48 <= gi_604) {
         l_ticket_52 = OrderSend(Symbol(), OP_BUY, a_lots_0, Ask, l_slippage_44, l_price_36, l_price_56, g_comment_596, a_magic_8, 0, g_color_608);
         l_count_48++;
         if (l_ticket_52 >= 0) break;
         if (l_count_48 > gi_604) break;
         Sleep(1000);
      }
      if (l_ticket_52 != 0) {
         g_error_568 = GetLastError();
         if (gi_616 == TRUE) Alert("Error OrderSend # ", g_error_568);
      }
      if (ld_28 > 0.0) continue;
   }
   return (0);
}

int open_sell_market(double a_lots_0, int a_magic_8) {
   int l_slippage_44;
   int l_count_48;
   int l_ticket_52;
   double l_price_56;
   double l_maxlot_12 = MarketInfo(Symbol(), MODE_MAXLOT);
   double l_minlot_20 = MarketInfo(Symbol(), MODE_MINLOT);
   double ld_28 = a_lots_0;
   double l_price_36 = 0.0;
   if (!AllowLotsBeyondMaxSize && ld_28 > l_maxlot_12) ld_28 = l_maxlot_12;
   l_price_36 = 0.0;
   l_price_36 = NormalizeDouble(l_price_36, Digits);
   while (ld_28 > 0.0) {
      a_lots_0 = ld_28;
      if (a_lots_0 > l_maxlot_12) a_lots_0 = l_maxlot_12;
      if (a_lots_0 < l_minlot_20) a_lots_0 = l_minlot_20;
      a_lots_0 = NormalizeDouble(a_lots_0, gi_732);
      ld_28 -= a_lots_0;
      l_slippage_44 = gi_736;
      l_count_48 = 0;
      l_ticket_52 = -1;
      l_price_56 = 0.0;
      if (gi_140 == TRUE && gi_588 != 0) {
         l_price_56 = Bid - gi_588 * Point;
         l_price_56 = NormalizeDouble(l_price_56, Digits);
      }
      if (gi_140 == FALSE && gi_592 != 0 && gi_588 != 0) {
         l_price_56 = Bid - (gi_588 + gi_592) * Point;
         l_price_56 = NormalizeDouble(l_price_56, Digits);
      }
      l_price_56 = 0.0;
      l_price_56 = NormalizeDouble(l_price_56, Digits);
      g_comment_596 = _Comment + " " + DoubleToStr(a_magic_8, 0);
      while (l_ticket_52 == -1 && l_count_48 <= gi_604) {
         l_ticket_52 = OrderSend(Symbol(), OP_SELL, a_lots_0, Bid, l_slippage_44, l_price_36, l_price_56, g_comment_596, a_magic_8, 0, g_color_612);
         l_count_48++;
         if (l_ticket_52 >= 0) break;
         if (l_count_48 > gi_604) break;
         Sleep(1000);
      }
      if (l_ticket_52 != 0) {
         g_error_568 = GetLastError();
         if (gi_616 == TRUE) Alert("Error OrderSend # ", g_error_568);
      }
      if (ld_28 > 0.0) continue;
   }
   return (0);
}

void DisplayComments() {
   string ls_0 = "TRUE";
   if (DoTrades == FALSE) ls_0 = "FALSE";
   string ls_8 = "False";
   if (gi_1128 == 1) ls_8 = "True";
   string ls_16 = "False";
   if (MonitorAndClose) ls_16 = "True";
   int li_24 = g_count_780;
   int li_28 = g_count_784;
   if (gd_508 == 0.0) g_count_784 = 0;
   if (gd_516 == 0.0) g_count_780 = 0;
   string ls_32 = "False";
   if (UseGridExpander) ls_32 = "True";
   string ls_40 = "True ";
   if (!CloseBuyBeyondMax) ls_40 = "False";
   string ls_48 = "True ";
   if (!CloseSellBeyondMax) ls_48 = "False";
   CalculateDrawDownPct();
   string ls_56 = "Buy and Sell";
   if (TradeDirection == -1) ls_56 = "Sell Only";
   if (TradeDirection == 1) ls_56 = "Buy Only";
   if (TradeDirection == 2) ls_56 = "Alternate Between Buy and Sell";
   if (TradeDirection == 3) ls_56 = "Buy or Sell Determined by CounterTrend Calculation";
   if (TradeDirection == 4) ls_56 = "Buy or Sell Determined by Trend Calculation";
   if (OnlyAfterLevel2 != 0 && gi_252 != 0) {
      Comment("\n" 
         + gs_84, 
         "\n" 
         + "\nCurrent Server Time = " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
         + "\nAccount Leverage =", AccountLeverage() 
         + "\nSpread = " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD), 0) 
         + "\nBalanceFactor = " + DoubleToStr(BalanceFactor, 2) 
         + "\nWorking Balance = " + DoubleToStr(gd_848, 2) 
         + "\nFunds Withdrawn = " + DoubleToStr(gd_856, 2) 
         + "\n" 
         + gs_1064 + DoubleToStr(100.0 * gd_1056, 2) 
         + "\n\nTradeLots = " + DoubleToStr(TradeLots, gi_732) 
         + "\nBase Lots = " + DoubleToStr(gd_548, gi_732) 
         + "\nMagic Number = " + MagicNumber 
         + "\nTrade Direction = " + ls_56 
         + "\nTradeRange = " + TradeRange 
         + "\nAverage True Range = " + DoubleToStr(gd_1004, 0) 
         + "\nMaximum Allowed Buy Level = " + MaxBuyMartingaleLevel 
         + "\nMaximum Allowed Sell Level = " + MaxSellMartingaleLevel 
         + "\nCloseBuyBeyondMax = " + ls_40 
         + "\nCloseSellBeyondMax = " + ls_48 
         + "\nUseGridExpander = " + ls_32 
         + "\nMartingale Disrupter (tm) Level = " + OnlyAfterLevel 
         + "\nExpandPips = " + ExpandPips 
         + "\nDisrupterClose = " + DoubleToStr(DisrupterClose, 2) 
         + "\nMartingale Disrupter (tm) Level2 = " + OnlyAfterLevel2 
         + "\nExpandPips2 = " + ExpandPips2 
         + "\nDisrupterClose2 = " + DoubleToStr(DisrupterClose2, 2) 
         + "\nMartingale Disrupter (tm) Level3 = " + gi_252 
         + "\nExpandPips3 = " + gi_296 
         + "\nDisrupterClose3 = " + DoubleToStr(gd_224, 2) 
         + "\n\nNext Buy Price = " + DoubleToStr(gd_740, Digits) 
         + "\nBuy Side TakeProfit = " + DoubleToStr(gd_876, Digits) 
         + "\nCalculated Buy Disrupter Price = " + DoubleToStr(gd_924, Digits) 
         + "\nNext Buy Lots = " + DoubleToStr(gd_760, gi_732) 
         + "\n\nNext Sell Price = " + DoubleToStr(gd_748, Digits) 
         + "\nSell Side TakeProfit = " + DoubleToStr(gd_884, Digits) 
         + "\nCalculated Sell Disrupter Price = " + DoubleToStr(gd_948, Digits) 
         + "\nNext Sell Lots = " + DoubleToStr(gd_768, gi_732) 
         + "\n\nCurrent Buy Level = " + li_24 
         + "\nCurrent Buy Side Profit = " + DoubleToStr(EAProfitAll(2), 2) 
         + "\n\nCurrent Sell Level = " + li_28 
         + "\nCurrent Sell Side Profit = " + DoubleToStr(EAProfitAll(1), 2) 
         + "\n\nMaximum Sell Level Reached = " + g_global_var_796 
         + "\nMaximum Buy Level Reached = " + g_global_var_792 
         + "\n\nAccount Authorized = " + ls_8 
         + "\n\nMonitor And Close = " + ls_16 
      + "\nDoTrades = " + ls_0);
   }
   if (OnlyAfterLevel2 != 0 && gi_252 == 0) {
      Comment("\n" 
         + gs_84, 
         "\n" 
         + "\nCurrent Server Time = " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
         + "\nAccount Leverage =", AccountLeverage() 
         + "\nSpread = " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD), 0) 
         + "\nBalanceFactor = " + DoubleToStr(BalanceFactor, 2) 
         + "\nWorking Balance = " + DoubleToStr(gd_848, 2) 
         + "\nFunds Withdrawn = " + DoubleToStr(gd_856, 2) 
         + "\n" 
         + gs_1064 + DoubleToStr(100.0 * gd_1056, 2) 
         + "\n\nTradeLots = " + DoubleToStr(TradeLots, gi_732) 
         + "\nBase Lots = " + DoubleToStr(gd_548, gi_732) 
         + "\nMagic Number = " + MagicNumber 
         + "\nTrade Direction = " + ls_56 
         + "\nTradeRange = " + TradeRange 
         + "\nAverage True Range = " + DoubleToStr(gd_1004, 0) 
         + "\nMaximum Allowed Buy Level = " + MaxBuyMartingaleLevel 
         + "\nMaximum Allowed Sell Level = " + MaxSellMartingaleLevel 
         + "\nCloseBuyBeyondMax = " + ls_40 
         + "\nCloseSellBeyondMax = " + ls_48 
         + "\nUseGridExpander = " + ls_32 
         + "\nMartingale Disrupter (tm) Level = " + OnlyAfterLevel 
         + "\nExpandPips = " + ExpandPips 
         + "\nDisrupterClose = " + DoubleToStr(DisrupterClose, 2) 
         + "\nMartingale Disrupter (tm) Level2 = " + OnlyAfterLevel2 
         + "\nExpandPips2 = " + ExpandPips2 
         + "\nDisrupterClose2 = " + DoubleToStr(DisrupterClose2, 2) 
         + "\n\nNext Buy Price = " + DoubleToStr(gd_740, Digits) 
         + "\nBuy Side TakeProfit = " + DoubleToStr(gd_876, Digits) 
         + "\nCalculated Buy Disrupter Price = " + DoubleToStr(gd_924, Digits) 
         + "\nNext Buy Lots = " + DoubleToStr(gd_760, gi_732) 
         + "\n\nNext Sell Price = " + DoubleToStr(gd_748, Digits) 
         + "\nSell Side TakeProfit = " + DoubleToStr(gd_884, Digits) 
         + "\nCalculated Sell Disrupter Price = " + DoubleToStr(gd_948, Digits) 
         + "\nNext Sell Lots = " + DoubleToStr(gd_768, gi_732) 
         + "\n\nCurrent Buy Level = " + li_24 
         + "\nCurrent Buy Side Profit = " + DoubleToStr(EAProfitAll(2), 2) 
         + "\n\nCurrent Sell Level = " + li_28 
         + "\nCurrent Sell Side Profit = " + DoubleToStr(EAProfitAll(1), 2) 
         + "\n\nMaximum Sell Level Reached = " + g_global_var_796 
         + "\nMaximum Buy Level Reached = " + g_global_var_792 
         + "\n\nAccount Authorized = " + ls_8 
         + "\n\nMonitor And Close = " + ls_16 
      + "\nDoTrades = " + ls_0);
   }
   if (OnlyAfterLevel2 == 0 && gi_252 == 0) {
      Comment("\n" 
         + gs_84, 
         "\n" 
         + "\nCurrent Server Time = " + TimeToStr(TimeCurrent(), TIME_SECONDS) 
         + "\nAccount Leverage =", AccountLeverage() 
         + "\nSpread = " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD), 0) 
         + "\nBalanceFactor = " + DoubleToStr(BalanceFactor, 2) 
         + "\nWorking Balance = " + DoubleToStr(gd_848, 2) 
         + "\nFunds Withdrawn = " + DoubleToStr(gd_856, 2) 
         + "\n" 
         + gs_1064 + DoubleToStr(100.0 * gd_1056, 2) 
         + "\n\nTradeLots = " + DoubleToStr(TradeLots, gi_732) 
         + "\nBase Lots = " + DoubleToStr(gd_548, gi_732) 
         + "\nMagic Number = " + MagicNumber 
         + "\nTrade Direction = " + ls_56 
         + "\nTradeRange = " + TradeRange 
         + "\nAverage True Range = " + DoubleToStr(gd_1004, 0) 
         + "\nMaximum Allowed Buy Level = " + MaxBuyMartingaleLevel 
         + "\nMaximum Allowed Sell Level = " + MaxSellMartingaleLevel 
         + "\nCloseBuyBeyondMax = " + ls_40 
         + "\nCloseSellBeyondMax = " + ls_48 
         + "\nUseGridExpander = " + ls_32 
         + "\nMartingale Disrupter (tm) Level = " + OnlyAfterLevel 
         + "\nExpandPips = " + ExpandPips 
         + "\nDisrupterClose = " + DoubleToStr(DisrupterClose, 2) 
         + "\n\nNext Buy Price = " + DoubleToStr(gd_740, Digits) 
         + "\nBuy Side TakeProfit = " + DoubleToStr(gd_876, Digits) 
         + "\nCalculated Buy Disrupter Price = " + DoubleToStr(gd_924, Digits) 
         + "\nNext Buy Lots = " + DoubleToStr(gd_760, gi_732) 
         + "\n\nNext Sell Price = " + DoubleToStr(gd_748, Digits) 
         + "\nSell Side TakeProfit = " + DoubleToStr(gd_884, Digits) 
         + "\nCalculated Sell Disrupter Price = " + DoubleToStr(gd_948, Digits) 
         + "\nNext Sell Lots = " + DoubleToStr(gd_768, gi_732) 
         + "\n\nCurrent Buy Level = " + li_24 
         + "\nCurrent Buy Side Profit = " + DoubleToStr(EAProfitAll(2), 2) 
         + "\n\nCurrent Sell Level = " + li_28 
         + "\nCurrent Sell Side Profit = " + DoubleToStr(EAProfitAll(1), 2) 
         + "\n\nMaximum Sell Level Reached = " + g_global_var_796 
         + "\nMaximum Buy Level Reached = " + g_global_var_792 
         + "\n\nAccount Authorized = " + ls_8 
         + "\n\nMonitor And Close = " + ls_16 
      + "\nDoTrades = " + ls_0);
   }
}

/*double search_for_latest_closed(int ai_0) {
   gi_564 = OrdersHistoryTotal();
   int l_datetime_4 = 0;
   bool li_8 = FALSE;
   int l_ticket_12 = 0;
   int li_unused_16 = 0;
   for (int l_pos_20 = gi_564 - 1; l_pos_20 >= 0; l_pos_20--) {
      if (!OrderSelect(l_pos_20, SELECT_BY_POS, MODE_HISTORY)) {
         g_error_568 = GetLastError();
         Print("OrderSelect( ", l_pos_20, ", SELECT_BY_POS ) - Error #", g_error_568);
      } else {
         if (OrderMagicNumber() == MagicNumber) {
            if (OrderSymbol() == Symbol()) {
               if (OrderCloseTime() != 0) {
                  if (ai_0 == 1 && OrderType() == OP_BUY) continue;
                  if (ai_0 == 2 && OrderType() == OP_SELL) continue;
                  if (OrderCloseTime() > l_datetime_4) {
                     l_datetime_4 = OrderCloseTime();
                     l_ticket_12 = OrderTicket();
                     li_8 = TRUE;
                  }
               }
            }
         }
      }
   }
   if (li_8 == TRUE) {
      for (l_pos_20 = gi_564 - 1; l_pos_20 >= 0; l_pos_20--) {
         if (!OrderSelect(l_pos_20, SELECT_BY_POS, MODE_HISTORY)) {
            g_error_568 = GetLastError();
            Print("OrderSelect( ", l_pos_20, ", SELECT_BY_POS ) - Error #", g_error_568);
         } else {
            if (OrderSymbol() == Symbol())
               if (OrderTicket() == l_ticket_12) return (OrderProfit());
         }
      }
   }
   return (0.0);
}*/

void CalculateLots() {
   double ld_8;
   double l_lotsize_0 = MarketInfo(Symbol(), MODE_LOTSIZE);
   if (TradeLots != 0.0) {
      gd_484 = TradeLots;
      if (gd_484 < MarketInfo(Symbol(), MODE_MINLOT)) gd_484 = MarketInfo(Symbol(), MODE_MINLOT);
      if (gd_484 > MarketInfo(Symbol(), MODE_MAXLOT)) gd_484 = MarketInfo(Symbol(), MODE_MAXLOT);
      gd_484 = NormalizeDouble(gd_484, gi_732);
      gd_548 = NormalizeDouble(gd_484, gi_732);
   }
   if (TradeLots == 0.0) {
      ld_8 = BalanceFactor;
      ld_8 /= 100000 / l_lotsize_0;
      gd_484 = MathFloor(gd_848 / ld_8) / 100.0;
      if (gd_484 > MaxLots) gd_484 = MaxLots;
      if (gd_484 < MarketInfo(Symbol(), MODE_MINLOT)) gd_484 = MarketInfo(Symbol(), MODE_MINLOT);
      if (gd_484 > MarketInfo(Symbol(), MODE_MAXLOT)) gd_484 = MarketInfo(Symbol(), MODE_MAXLOT);
      gd_484 = NormalizeDouble(gd_484, gi_732);
      gd_548 = NormalizeDouble(gd_484, gi_732);
   }
}

void GetMartingaleLevel(double ad_0) {
   g_count_776 = 0;
   if (ad_0 == gd_548) g_count_776 = 0;
   if (ad_0 == gd_548 * gi_144) g_count_776 = 1;
   if (ad_0 == gd_548 * MathPow(gi_144, 2)) g_count_776 = 2;
   if (ad_0 == gd_548 * MathPow(gi_144, 3)) g_count_776 = 3;
   if (ad_0 == gd_548 * MathPow(gi_144, 4)) g_count_776 = 4;
   if (ad_0 == gd_548 * MathPow(gi_144, 5)) g_count_776 = 5;
   if (ad_0 == gd_548 * MathPow(gi_144, 6)) g_count_776 = 6;
   if (ad_0 == gd_548 * MathPow(gi_144, 7)) g_count_776 = 7;
   if (ad_0 == gd_548 * MathPow(gi_144, 8)) g_count_776 = 8;
   if (ad_0 == gd_548 * MathPow(gi_144, 9)) g_count_776 = 9;
   if (ad_0 == gd_548 * MathPow(gi_144, 10)) g_count_776 = 10;
   if (ad_0 == gd_548 * MathPow(gi_144, 11)) g_count_776 = 11;
   if (ad_0 == gd_548 * MathPow(gi_144, 12)) g_count_776 = 12;
   if (ad_0 == gd_548 * MathPow(gi_144, 13)) g_count_776 = 13;
   if (ad_0 == gd_548 * MathPow(gi_144, 14)) g_count_776 = 14;
   if (ad_0 == gd_548 * MathPow(gi_144, 15)) g_count_776 = 15;
   if (ad_0 == gd_548 * MathPow(gi_144, 16)) g_count_776 = 16;
   if (ad_0 == gd_548 * MathPow(gi_144, 17)) g_count_776 = 17;
   g_count_776++;
}

double GetMartingaleLevel2(int ai_0) {
   gi_564 = OrdersTotal();
   int l_count_4 = 0;
   double ld_8 = MathFloor(gi_688 / 2) * Point;
   if (ai_0 == 1) ld_8 = MathFloor(gi_692 / 2) * Point;
   double l_ord_open_price_16 = 0.0;
   for (int l_pos_24 = gi_564 - 1; l_pos_24 >= 0; l_pos_24--) {
      if (!OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES)) {
         g_error_568 = GetLastError();
         Print("OrderSelect( ", l_pos_24, ", SELECT_BY_POS ) - Error #", g_error_568);
      } else {
         if (OrderSymbol() == Symbol()) {
            if (OrderMagicNumber() == MagicNumber) {
               if (OrderCloseTime() == 0) {
                  if (ai_0 == 1 && OrderType() == OP_BUY) continue;
                  if (ai_0 == 2 && OrderType() == OP_SELL) continue;
                  if (l_ord_open_price_16 == 0.0 || MathAbs(l_ord_open_price_16 - OrderOpenPrice()) > ld_8) l_count_4++;
                  l_ord_open_price_16 = OrderOpenPrice();
               }
            }
         }
      }
   }
   return (l_count_4);
}

void SendTheMail() {
   if (gi_492) {
      SendMail("NxGnAllDay Report", " " + Symbol() + " account = " + DoubleToStr(AccountNumber(), 0) + " BuyLevel = " + DoubleToStr(g_count_780, 0) + " SellLevel = " + DoubleToStr(g_count_784, 0) +
         " BuySide = " + DoubleToStr(EAProfitAll(2), 2) + " SellSide = " + DoubleToStr(EAProfitAll(1), 2));
      Sleep(5000);
      SendMail("NxGnAllDay Report-2", " " + Symbol() + " account = " + DoubleToStr(AccountNumber(), 0) + " MaxBuyLevel Reached = " + DoubleToStr(g_global_var_792, 0) + " MaxSellLevel Reached = " +
         DoubleToStr(g_global_var_796, 0) + " Balance = " + DoubleToStr(AccountBalance(), 2) + " Equity = " + DoubleToStr(AccountEquity(), 2));
   }
   if (!gi_492) {
      SendMail("NxGnAllDay Rpt.", " " + Symbol() + " account = " + DoubleToStr(AccountNumber(), 0) + " BuyLevel = " + DoubleToStr(g_count_780, 0) + ", " + DoubleToStr(g_global_var_792, 0) +
         " SellLevel = " + DoubleToStr(g_count_784, 0) + ", " + DoubleToStr(g_global_var_796, 0) + " BuySide = " + DoubleToStr(EAProfitAll(2), 2) + " SellSide = " + DoubleToStr(EAProfitAll(1), 2) + " Balance = " + DoubleToStr(AccountBalance(), 2) + " Equity = " + DoubleToStr(AccountEquity(), 2));
   }
}

void SendTheMail2() {
   SendMail("NxGnAllDay Rpt.", " " + Symbol() + " account = " + DoubleToStr(AccountNumber(), 0) + " Your profit goal has been reached and you have money waiting to withdraw from your account. " +
      " Balance = " + DoubleToStr(AccountBalance(), 2) + " Equity = " + DoubleToStr(AccountEquity(), 2));
}

void SendTheSecurityMail() {
   SendMail("NxGnAllDay Notice:", " " + Symbol() + " account = " + DoubleToStr(AccountNumber(), 0) + " Something has happened. This account is not enabled for the NxGnAllDay." +
      " Please restart the EA.");
}

void RunMartingaleDisrupter() {
   if (!LimitToThisPair) {
      gd_1016 = (AccountBalance() - AccountEquity()) / AccountBalance();
      if (100.0 * gd_1016 > MaxDrawDownPct) {
         ClosePairType(OP_BUY);
         ClosePairType(OP_SELL);
         CalculateLots();
      }
   }
   if (LimitToThisPair) {
      gd_1016 = (AccountBalance() - (AccountBalance() + EAProfitAll(1) + EAProfitAll(2))) / AccountBalance();
      if (100.0 * gd_1016 > MaxDrawDownPct) {
         ClosePairType(OP_BUY);
         ClosePairType(OP_SELL);
         CalculateLots();
      }
   }
   if (gd_1016 > gd_1024) gd_1024 = gd_1016;
   gi_864 = FALSE;
   if (DisrupterClose != 0.0 && g_count_780 >= OnlyAfterLevel && g_count_780 < OnlyAfterLevel2 && EAProfitAll(2) >= DisrupterClose) gi_864 = TRUE;
   if (DisrupterClose2 != 0.0 && g_count_780 >= OnlyAfterLevel2 && EAProfitAll(2) >= DisrupterClose2) gi_864 = TRUE;
   if (gi_864) {
      Print("Close of all buy trades due to Martingale Disrupter(tm).");
      ClosePairType(OP_BUY);
      Print("All buy trades were closed due to Martingale Disrupter(tm).");
      gi_864 = FALSE;
   }
   gi_864 = FALSE;
   if (DisrupterClose != 0.0 && g_count_784 >= OnlyAfterLevel && g_count_784 < OnlyAfterLevel2 && EAProfitAll(1) >= DisrupterClose) gi_864 = TRUE;
   if (DisrupterClose2 != 0.0 && g_count_784 >= OnlyAfterLevel2 && EAProfitAll(1) >= DisrupterClose2) gi_864 = TRUE;
   if (gi_864) {
      Print("Close of all sell trades due to Martingale Disrupter(tm).");
      ClosePairType(OP_SELL);
      Print("All sell trades were closed due to Martingale Disrupter(tm).");
      gi_864 = FALSE;
   }
}

void EvaluateTrades() {
   gd_516 = search_for(2);
   g_count_780 = GetMartingaleLevel2(2);
   GetMartingaleLevel(gd_516);
   if (g_count_776 > g_count_780) g_count_780 = g_count_776;
   if (gd_516 == 0.0) g_count_780 = 0;
   g_ord_open_price_532 = g_ord_open_price_572;
   gd_508 = search_for(1);
   g_count_784 = GetMartingaleLevel2(1);
   GetMartingaleLevel(gd_508);
   if (g_count_776 > g_count_784) g_count_784 = g_count_776;
   if (gd_508 == 0.0) g_count_784 = 0;
   g_ord_open_price_524 = g_ord_open_price_572;
}

void TestTakeProfit() {
   EvaluateTrades();
   if (gi_472 >= 0 && gd_516 > g_ord_lots_832) {
      gi_460 = gi_1012;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_780 >= OnlyAfterLevel) gi_460 = gi_1012 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_780 >= OnlyAfterLevel2) gi_460 = gi_1012 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_780 >= gi_252) gi_460 = gi_1012 + gi_296;
      gd_868 = 0.0;
      gi_468 = gi_460;
      gd_868 = g_ord_open_price_532 + gi_468 * Point;
      if (gi_176 && g_count_780 > 1 && g_ord_open_price_816 != 0.0) gd_868 = g_ord_open_price_816;
      if (gd_924 != 0.0 && gd_868 < gd_924 && gd_924 > gd_876 && MathAbs(gd_924 - gd_868) < gi_984 * Point && AdjustTakeProfit) gd_868 = gd_924;
      gd_868 = NormalizeDouble(gd_868, Digits);
      if (g_count_780 == 0) gd_876 = 0.0;
      if (AdjustTakeProfit && g_count_780 > 0 && gi_988 == FALSE || gd_876 == 0.0 || gd_868 > gd_876) gd_876 = gd_868;
      if (!AdjustTakeProfit && g_count_780 > 0) gd_876 = gd_868;
      if (gi_976) gd_1048 = 0.0;
      if (g_count_780 > 0) {
         if (gd_876 != gd_1048) AddTakeProfit(2, gd_876);
         gd_1048 = gd_876;
         gi_988 = TRUE;
      }
   }
   if (gi_472 <= 0 && gd_508 > g_ord_lots_840) {
      gi_464 = gi_1012;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_784 >= OnlyAfterLevel) gi_464 = gi_1012 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_784 >= OnlyAfterLevel2) gi_464 = gi_1012 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_784 >= gi_252) gi_464 = gi_1012 + gi_296;
      gd_868 = 0.0;
      gi_468 = gi_464;
      gd_868 = g_ord_open_price_524 - gi_468 * Point;
      if (gi_176 && g_count_784 > 1 && g_ord_open_price_824 != 0.0) gd_868 = g_ord_open_price_824;
      if (gd_948 != 0.0 && gd_868 > gd_948 && gd_948 < gd_884 && MathAbs(gd_868 - gd_948) < gi_984 * Point && AdjustTakeProfit) gd_868 = gd_948;
      gd_868 = NormalizeDouble(gd_868, Digits);
      if (g_count_784 == 0) gd_884 = 0.0;
      if (AdjustTakeProfit && g_count_784 > 0 && gi_992 == FALSE || gd_884 == 0.0 || gd_868 < gd_884) gd_884 = gd_868;
      if (!AdjustTakeProfit && g_count_784 > 0) gd_884 = gd_868;
      if (gi_976) gd_1040 = 0.0;
      if (g_count_784 > 0) {
         if (gd_884 != gd_1040) AddTakeProfit(1, gd_884);
         gd_1040 = gd_884;
         gi_992 = TRUE;
      }
   }
   if (gi_976 && gd_876 != 0.0 && Bid >= gd_876) {
      if (gi_1096 == FALSE) Print("Close of all buy trades due to TakeProfit Reached (Stealth Mode).");
      ClosePairType(OP_BUY);
      if (gi_1096 == FALSE) Print("All buy trades were closed due to TakeProfit Reached (Stealth Mode).");
      gi_1096 = TRUE;
      g_count_780 = 0;
   }
   if (gi_976 && gd_884 != 0.0 && Ask <= gd_884) {
      if (gi_1096 == FALSE) Print("Close of all sell trades due to TakeProfit Reached (Stealth Mode).");
      ClosePairType(OP_SELL);
      if (gi_1096 == FALSE) Print("All sell trades were closed due to TakeProfit Reached (Stealth Mode).");
      g_count_784 = 0;
      gi_1096 = TRUE;
   }
   if (gd_876 != 0.0 && Bid >= gd_876) {
      if (gi_1096 == FALSE) Print("Close of all buy trades due to TakeProfit Reached.");
      ClosePairType(OP_BUY);
      g_count_780 = 0;
      if (gi_1096 == FALSE) Print("All buy trades were closed due to TakeProfit Reached.");
      gi_1096 = TRUE;
   }
   if (gd_884 != 0.0 && Ask <= gd_884) {
      if (gi_1096 == FALSE) Print("Close of all sell trades due to TakeProfit Reached.");
      ClosePairType(OP_SELL);
      g_count_784 = 0;
      if (gi_1096 == FALSE) Print("All sell trades were closed due to TakeProfit Reached.");
      gi_1096 = TRUE;
   }
}

void CheckProfitGrab() {
   double ld_0;
   if (ControlBalance != 0.0 && LockInProfits != 0.0) {
      ld_0 = AccountEquity() - gd_856;
      if (ld_0 >= ControlBalance + LockInProfits) {
         if (AccountEquity() - ControlBalance < 2.0 * LockInProfits) {
            Print("All trades being closed due to Profit Target Reached.");
            ClosePairType(OP_BUY);
            ClosePairType(OP_SELL);
            g_count_780 = 0;
            g_count_784 = 0;
            Print("All trades were closed due to Profit Target Reached.");
            if (Send_Email) SendTheMail2();
         }
         gd_856 += LockInProfits;
      }
   }
   gd_848 = AccountBalance() - gd_856;
   if (gd_848 < ControlBalance) gd_848 += gd_856;
}

void GetVariables() {
   g_global_var_792 = GlobalVariableGet("GVMaxBuyLevel" + g_dbl2str_808 + Symbol());
   g_global_var_796 = GlobalVariableGet("GVMaxSellLevel" + g_dbl2str_808 + Symbol());
   gd_856 = GlobalVariableGet("GVFundsWithdrawn" + g_dbl2str_808 + Symbol());
}

void WriteVariables() {
   GlobalVariableSet("GVMaxBuyLevel" + g_dbl2str_808 + Symbol(), g_global_var_792);
   GlobalVariableSet("GVMaxSellLevel" + g_dbl2str_808 + Symbol(), g_global_var_796);
   GlobalVariableSet("GVFundsWithdrawn" + g_dbl2str_808 + Symbol(), gd_856);
}
/*
int GetAuth() {
   int li_ret_0 = 0;
   g_acc_number_1132 = AccountNumber();
   if (!IsDemo()) gi_1136 = 7;
   if (IsDemo()) gi_1136 = 8;
   li_ret_0 = simpleclient(g_acc_number_1132, gi_1136);
   if (li_ret_0 != 1 && IsDemo()) {
      Sleep(1000);
      li_ret_0 = simpleclient(g_acc_number_1132, gi_1136);
      if (li_ret_0 != 1)
         if (gi_76) g_acc_number_1132 = gi_80;
   }
   if (li_ret_0 != 1) {
      Sleep(1000);
      li_ret_0 = simpleclient(g_acc_number_1132, gi_1136);
   }
   if (li_ret_0 != 1) {
      Sleep(2000);
      li_ret_0 = simpleclient(g_acc_number_1132, gi_1136);
   }
   if (li_ret_0 != 1) {
      Sleep(3000);
      li_ret_0 = simpleclient(g_acc_number_1132, gi_1136);
   }
   if (li_ret_0 != 1 && IsDemo()) {
      g_acc_number_1132 = AccountNumber();
      li_ret_0 = simpleclient(g_acc_number_1132, gi_1136);
   }
   return (li_ret_0);
}
*/
void CalculateClosePrice() {
   double ld_0;
   int li_8;
   int li_12;
   if (gda_892[1] == 0.0 && gda_892[2] == 0.0) {
      gda_892[1] = Bid;
      gda_900[1] = EAProfitAll(2);
   }
   if (Bid != gda_892[1] && gda_892[1] != 0.0) {
      gda_892[2] = Bid;
      gda_900[2] = EAProfitAll(2);
   }
   gd_908 = 0.0;
   gd_unused_916 = 0.0;
   gd_924 = 0.0;
   gi_956 = FALSE;
   gd_960 = 0.0;
   gd_968 = 0.0;
   if (gda_892[2] != 0.0 && gda_892[1] != 0.0) {
      gd_908 = MathAbs(gda_900[2] - gda_900[1]);
      gd_908 /= MathAbs(gda_892[2] / Point - gda_892[1] / Point);
   }
   gd_960 = 0.0;
   if (OnlyAfterLevel != 0 && g_count_780 >= OnlyAfterLevel) gd_960 = DisrupterClose;
   if (OnlyAfterLevel2 != 0 && g_count_780 >= OnlyAfterLevel2) gd_960 = DisrupterClose2;
   if (gi_252 != 0 && g_count_780 >= gi_252) gd_960 = gd_224;
   if (gd_960 != 0.0 && gd_908 != 0.0) {
      ld_0 = EAProfitAll(2);
      if (ld_0 < 0.0) gd_968 = MathAbs(gd_960 - MathAbs(ld_0));
      if (ld_0 > 0.0) gd_968 = gd_960 - ld_0;
      gi_956 = gd_968 / gd_908;
      gd_924 = Bid + gi_956 * Point;
   }
   if (gda_896[1] == 0.0 && gda_896[2] == 0.0) {
      gda_896[1] = Ask;
      gda_904[1] = EAProfitAll(1);
   }
   if (Ask != gda_896[1] && gda_896[1] != 0.0) {
      gda_896[2] = Ask;
      gda_904[2] = EAProfitAll(1);
   }
   gd_932 = 0.0;
   gd_unused_940 = 0.0;
   gd_948 = 0.0;
   gi_956 = FALSE;
   gd_960 = 0.0;
   gd_968 = 0.0;
   if (gda_896[2] != 0.0 && gda_896[1] != 0.0) {
      gd_932 = MathAbs(gda_904[2] - gda_904[1]);
      gd_932 /= MathAbs(gda_896[2] / Point - gda_896[1] / Point);
   }
   gd_960 = 0.0;
   if (OnlyAfterLevel != 0 && g_count_784 >= OnlyAfterLevel) gd_960 = DisrupterClose;
   if (OnlyAfterLevel2 != 0 && g_count_784 >= OnlyAfterLevel2) gd_960 = DisrupterClose2;
   if (gi_252 != 0 && g_count_784 >= gi_252) gd_960 = gd_224;
   if (gd_960 != 0.0 && gd_932 != 0.0) {
      ld_0 = EAProfitAll(1);
      if (ld_0 < 0.0) gd_968 = MathAbs(gd_960 - MathAbs(ld_0));
      if (ld_0 > 0.0) gd_968 = gd_960 - ld_0;
      gi_956 = gd_968 / gd_932;
      gd_948 = Ask - gi_956 * Point;
      if (gi_980 == FALSE) gi_980 = TRUE;
   }
   if (gd_948 != 0.0) {
      li_8 = gi_692;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_784 >= OnlyAfterLevel) li_8 = gi_692 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_784 >= OnlyAfterLevel2) li_8 = gi_692 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_784 >= gi_252) li_8 = gi_692 + gi_296;
      li_8 += gi_984;
      if (MathAbs(Ask - gd_948) > li_8 * Point) {
         ArrayInitialize(gda_896, 0.0);
         ArrayInitialize(gda_904, 0.0);
      }
   }
   if (gd_924 != 0.0) {
      li_12 = gi_688;
      if (UseGridExpander && OnlyAfterLevel != 0 && g_count_780 >= OnlyAfterLevel) li_12 = gi_688 + ExpandPips;
      if (UseGridExpander && OnlyAfterLevel2 != 0 && g_count_780 >= OnlyAfterLevel2) li_12 = gi_688 + ExpandPips2;
      if (UseGridExpander && gi_252 != 0 && g_count_780 >= gi_252) li_12 = gi_688 + gi_296;
      li_12 += gi_984;
      if (MathAbs(gd_924 - Bid) > li_12 * Point) {
         ArrayInitialize(gda_892, 0.0);
         ArrayInitialize(gda_900, 0.0);
      }
   }
}

void CheckStealthMode() {
   if (!AutoStealthMode) gi_976 = StealthMode;
   if (AutoStealthMode && DayOfWeek() == 5 && Hour() >= 16) {
      gi_976 = TRUE;
      if (gi_1000 == FALSE) gi_996 = 30;
      gi_1000 = TRUE;
   }
   if (AutoStealthMode && (DayOfWeek() == 0 && Hour() >= 23) || (DayOfWeek() == 1 && Hour() > 1) || (DayOfWeek() > 1 && DayOfWeek() < 5) || (DayOfWeek() == 5 && Hour() < 16)) {
      if (gi_1000 == TRUE) gi_996 = 30;
      gi_976 = FALSE;
      gi_1000 = FALSE;
   }
}

void SetDirection() {
   EvaluateTrades();
   gi_472 = 9;
   if (gd_516 > 0.0 && gd_508 > 0.0 && TradeDirection == 2 || TradeDirection == 3 || TradeDirection == 4) gi_472 = 0;
   if (TradeDirection == 3) {
      if (gd_508 == 0.0 && gd_516 == 0.0 && TradeDirection == 3 && Bid <= gd_540) gi_472 = 1;
      if (gd_508 == 0.0 && gd_516 == 0.0 && TradeDirection == 3 && Bid >= gd_540) gi_472 = -1;
      if (gd_508 == 0.0 && Trad        

Recommend