#include <WinUser32.mqh>
//#include <stdlib.mqh>
#import "stdlib.ex4"
   string ErrorDescription(int a0);
#import "PipJet.dll"
   int GetParams(int a0, int a1, int a2, double& a3[]);
   void Activate(string a0, int a1, string a2, string a3, string a4, int a5, string a6, int a7);
   int GetState();
   bool GetStateMessage(string a0, int a1, string a2, int a3);
   bool GetInfoMessage(string a0, int a1, string a2, int a3);
   bool GetAdvMessage(string a0, int a1, string a2, int a3);
   void GetStatus(int a0, int a1, double a2, double a3, double a4);
   int Increment(string a0, int a1, int a2, int a3);
   bool Decrement(int a0);
   bool IsTradeTime(int a0, int a1, int a2, int a3);
   bool s1_SetRules(int a0, int a1, int a2, double a3, double a4, double a5, double a6, double a7);
   bool s1_Buy(int a0, double a1);
   bool s1_Sell(int a0, double a1);
   bool s2_SetRules(int a0, int a1, int a2, double a3, double a4, double a5, double a6);
   bool s2_Buy(int a0, double a1, double a2);
   bool s2_Sell(int a0, double a1, double a2);
   bool s1_Init(int a0, double& a1[]);
   bool s2_Init(int a0, double& a1[]);
   void AddLink(int a0, int a1, int a2, int a3, int a4, string a5);
   void LinksBegin(int a0);
   void LinksEnd(int a0);
#import

extern string Ver.1.00 = "";
extern string _1 = "System Parameters";
extern bool Stealth = TRUE;
extern bool Aggressive = TRUE;
extern double GmtOffset = 0.0;
extern bool NFA = FALSE;
extern bool AutoLocalGmtOffset = TRUE;
extern bool AutoServerGmtOffset = TRUE;
extern int S1_Reference = 74123;
extern int S2_Reference = 32147;
extern string ReceiptCode = "0";
extern string _2 = "Comment Position";
extern int TopPadding = 30;
extern int LeftPadding = 20;
extern color TextColor1 = Orange;
extern color TextColor2 = Orange;
extern color TextColor3 = C'0x64,0x64,0xFF';
extern string _3 = "Strategy Parameters";
extern bool RemoteSafetyMode = TRUE;
extern int Slippage = 3;
extern bool SendEmails = FALSE;
extern string OrderComments = "";
extern string _4 = "Order Management";
extern double LotSize = 0.1;
extern string _5 = "Ratio Order Management";
extern double RiskLevel = 0.2;
extern bool RecoveryMode = TRUE;
double gd_228 = 2.0;
bool gi_236 = TRUE;
bool gi_240 = TRUE;
int gi_244 = 3;
bool gi_248 = TRUE;
int gi_252;
int g_datetime_256;
int gi_260;
double g_hour_264;
int gi_272;
int g_spread_276;
int g_spread_280;
int gi_284;
double gd_288;
double gd_296;
bool gi_312 = TRUE;
int gi_316 = 0;
int gi_320 = 0;
int gi_324 = 0;
int gi_328;
int gi_unused_332 = 1;
bool g_global_var_336 = FALSE;
bool gi_340 = FALSE;
double gd_344 = 0.0;
string gs_352 = "";
string gs_360 = "";
string gs_368 = "";
string gs_376 = "";
string gs_384 = "";
string gs_392 = "";
string gs_400;
string gs_408;
string gs_416;
int g_timeframe_424 = PERIOD_M15;
int gi_428 = 10;
int gi_432 = 50;
int gi_436 = 200;
int gi_440 = 20;
int gi_444 = 0;
int gi_448 = 16711680;
int gi_452 = 255;
int g_period_456 = 6;
int g_period_460 = 20;
int g_period_464 = 8;
bool gi_468 = TRUE;
bool gi_472 = TRUE;
int gi_476 = 12;
bool gi_480 = TRUE;
int gi_484 = 20;
bool gi_488 = TRUE;
bool gi_492 = FALSE;
double gd_496 = 1.0;
double gd_504 = 24.0;
bool gi_512 = TRUE;
double gd_516 = 1.0;
double gd_524 = 1.0;
bool gi_532 = FALSE;
int gi_536 = 0;
bool gi_540 = TRUE;
int g_timeframe_544 = PERIOD_M5;
int gi_548 = 35;
int gi_552 = 60;
int gi_556 = 200;
int gi_560 = 20;
double gd_564 = 1.0;
int gi_572 = 0;
int gi_576 = 16748574;
int gi_580 = 9639167;
int gi_584 = 36;
int g_period_588 = 168;
int g_period_592 = 275;
bool gi_596 = TRUE;
bool gi_600 = FALSE;
bool gi_604 = TRUE;
double gd_608 = 1.0;
double gd_616 = 12.0;
double gd_624 = 24.0;
bool gi_632 = FALSE;
bool gi_636 = FALSE;
int gi_640 = 0;
bool gi_644 = TRUE;
int gi_648 = 0;
int gi_652 = 0;
int gi_656 = 0;
int gi_660;
int gi_664;
int gi_668;
int gi_672;
double gd_676 = 0.0;
double gd_684 = 0.0;
bool gi_692 = FALSE;
bool gi_696;
bool gi_700;
bool gi_704;
int g_count_708 = 0;
int g_ticket_712 = -2;
int g_ticket_716 = -2;
double g_order_profit_720 = 0.0;
double g_order_profit_728 = 0.0;
int g_ticket_736 = -2;
int g_ticket_740 = -2;
double g_order_profit_744 = 0.0;
double g_order_profit_752 = 0.0;
int gi_760 = 0;
int gi_764 = 0;
double gd_768 = 2.0;
int gi_776 = 0;
int gi_780 = 0;
double g_irsi_784;
double g_irsi_792;
double g_irsi_800;
double g_irsi_808;
double g_icci_816;
double g_icci_824;
double g_icci_832;
double g_ima_856;
bool gi_864 = TRUE;
bool gi_868 = TRUE;
double g_ihigh_872 = 0.0;
double g_ilow_880 = 0.0;
bool gi_888 = FALSE;
int gi_892 = 0;
int gi_896 = 0;
int gi_900 = 0;
int gi_904 = 0;
int gi_908 = 0;
int gi_912 = 0;
int gi_916;
int g_datetime_920 = 0;
int g_datetime_924 = 0;
int g_ticket_928 = -1;
int g_datetime_932 = 0;
int g_ticket_936 = -1;
int g_datetime_940 = 0;
bool gi_944 = TRUE;
int g_datetime_948 = 0;
int g_datetime_952 = 0;
int gi_956 = 0;
double g_icci_960;
double g_icci_968;
double g_ihigh_976;
double g_ilow_984;
double g_ihigh_992;
double g_ilow_1000;
bool gi_1008 = FALSE;
int gi_1012 = 0;
int gi_1016 = 0;
int gi_1020 = 0;
int gi_1024 = 0;
int g_ticket_1028 = -1;
int gi_1032;
int gi_1036;
int g_datetime_1040;
int g_datetime_1044;
double g_order_open_price_1048;
int g_ticket_1056 = -1;
int gi_1060;
int gi_1064;
int g_datetime_1068;
int g_datetime_1072;
double g_order_open_price_1076;
bool gi_1084 = TRUE;
int g_datetime_1088 = 0;
int g_datetime_1092 = 0;
string gsa_1096[] = {".", "..", "...", "....", "....."};
int gi_unused_1100 = 0;
int gi_unused_1104 = 0;
string gs_1108 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gi_unused_1116 = 0;
int gi_unused_1120 = 0;
double gda_unused_1124[];
bool gi_1128 = FALSE;

int f0_20() {
   double lda_0[21];
   if (s1_Init(gi_328, lda_0)) {
      gi_428 = lda_0[0];
      gi_436 = lda_0[1];
      gi_440 = lda_0[2];
      gi_444 = lda_0[3];
      g_period_456 = lda_0[4];
      g_period_460 = lda_0[5];
      g_period_464 = lda_0[6];
      gd_496 = lda_0[11];
      gd_504 = lda_0[12];
      gd_516 = lda_0[13];
      gd_524 = lda_0[14];
      gi_536 = lda_0[15];
      g_timeframe_424 = lda_0[20];
      return (1);
   }
   return (0);
}

int f0_15() {
   double lda_0[17];
   if (s2_Init(gi_328, lda_0)) {
      gi_548 = lda_0[0];
      gi_556 = lda_0[1];
      gi_560 = lda_0[2];
      gd_564 = lda_0[3];
      gi_572 = lda_0[4];
      gi_584 = lda_0[5];
      g_period_588 = lda_0[6];
      g_period_592 = lda_0[7];
      gd_608 = lda_0[8];
      gd_616 = lda_0[9];
      gd_624 = lda_0[10];
      gi_640 = lda_0[11];
      g_timeframe_544 = lda_0[16];
      return (1);
   }
   return (0);
}

int init() {
   double global_var_4;
   double ld_12;
   if (gi_248) gi_252 = 0;
   else gi_252 = 1;
   gi_328 = Increment(Symbol(), Digits, IsTesting(), WindowHandle(Symbol(), Period()));
   gi_664 = LeftPadding;
   gi_660 = TopPadding;
   if (gi_668 != LeftPadding || gi_672 != TopPadding) {
      gi_668 = LeftPadding;
      gi_672 = TopPadding;
   } else f0_5(0, gi_664, gi_660);
   gi_652 = 0;
   gi_648 = 0;
   gs_400 = "PipJet" + " ver: " + "1.00" + " Symbol: " + Symbol();
   f0_36(gs_400, TextColor2);
   f0_34();
   ObjectsRedraw();
   for (int count_0 = 0; !IsStopped() && StringLen(AccountName()) <= 0; count_0++) {
      f0_36("Waiting for connection" + f0_13(count_0), TextColor1, 2, 2);
      ObjectsRedraw();
      Sleep(150);
   }
   f0_36("Authentication...", TextColor1, 2, 2);
   ObjectsRedraw();
   gi_320 = 0;
   ReceiptCode = StringTrimLeft(StringTrimRight(ReceiptCode));
   if (StringLen(ReceiptCode) <= 0) {
      if (GlobalVariableCheck("GV_PipJet_REC")) {
         global_var_4 = GlobalVariableGet("GV_PipJet_REC");
         ReceiptCode = f0_51(global_var_4);
      } else gi_320 |= 32;
   } else {
      ld_12 = f0_17(ReceiptCode);
      if (GlobalVariableSet("GV_PipJet_REC", ld_12) == 0) gi_320 |= 64;
   }
   Activate("1.00", AccountNumber(), AccountCurrency(), AccountCompany(), AccountServer(), IsDemo(), ReceiptCode, 1);
   gi_316 = GetState();
   if (!IsTesting()) f0_21();
   f0_40(gi_316 | gi_320, 2, 2);
   LinksBegin(gi_328);
   int str_len_20 = StringLen(gs_352);
   int str_len_24 = StringLen(gs_360);
   if (str_len_20 > 1) f0_36(gs_352);
   if (str_len_24 > 0) f0_43(gs_360, TextColor2, gi_652, gi_648 - 1, 7 * (str_len_20 + 1));
   f0_34();
   str_len_20 = StringLen(gs_368);
   str_len_24 = StringLen(gs_376);
   if (str_len_20 > 1) f0_36(gs_368);
   if (str_len_24 > 0) f0_43(gs_376, TextColor2, gi_652, gi_648 - 1, 7 * (str_len_20 + 1));
   if (str_len_20 > 1 || str_len_24 > 0) f0_34();
   bool li_28 = FALSE;
   bool li_32 = FALSE;
   li_28 = f0_20();
   li_32 = f0_15();
   if (li_28) {
      gi_236 = TRUE;
      if (Aggressive) gi_240 = li_32;
      else gi_240 = FALSE;
   } else {
      if (li_32) {
         gi_236 = FALSE;
         gi_240 = TRUE;
      } else {
         gi_240 = FALSE;
         gi_236 = FALSE;
      }
   }
   if ((!gi_236) && !gi_240) {
      gs_408 = "Error:";
      gs_416 = "This currency is not supported!";
   } else {
      gs_408 = "Aggressive:";
      gs_416 = f0_11(gi_236 && gi_240);
      if (Aggressive && (!(gi_236 && gi_240))) gs_416 = gs_416 + " (not supported)";
   }
   f0_36(gs_408);
   f0_36(gs_416, TextColor2, gi_652, gi_648 - 1, 7 * (StringLen(gs_408) + 1));
   f0_34();
   str_len_20 = StringLen(gs_384);
   str_len_24 = StringLen(gs_392);
   if (str_len_20 > 1) f0_36(gs_384);
   if (str_len_24 > 0) f0_43(gs_392, TextColor2, gi_652, gi_648 - 1, 7 * (str_len_20 + 1));
   ObjectsRedraw();
   LinksEnd(gi_328);
   if ((!gi_236) && !gi_240) MessageBox("You have selected the wrong currency pair!", gs_400 + ": Warning", MB_ICONEXCLAMATION);
   gi_324 = FALSE;
   if (IsTesting()) gi_312 = FALSE;
   g_global_var_336 = 0;
   gi_340 = FALSE;
   if (!IsTesting())
      if (GlobalVariableCheck("GV_PipJet_MKT")) g_global_var_336 = GlobalVariableGet("GV_PipJet_MKT");
   return (0);
}

void f0_21() {
   string ls_0 = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
   string ls_8 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
   if (gi_316 & 65536 > 0) {
      if (GetStateMessage(ls_0, 60, ls_8, 255)) {
         gs_352 = StringConcatenate(ls_0, ":");
         gs_360 = StringTrimLeft(ls_8);
      } else {
         gs_352 = "";
         gs_360 = "";
      }
   }
   if (GetInfoMessage(ls_0, 60, ls_8, 255)) {
      gs_368 = StringConcatenate(ls_0, ":");
      gs_376 = StringTrimLeft(ls_8);
   } else {
      gs_368 = "";
      gs_376 = "";
   }
   if (GetAdvMessage(ls_0, 60, ls_8, 255)) {
      gs_384 = StringConcatenate(ls_0, ":");
      gs_392 = StringTrimLeft(ls_8);
      return;
   }
   gs_384 = "";
   gs_392 = "";
}

int deinit() {
   Decrement(gi_328);
   if (IsTesting()) {
      if (!(!IsVisualMode())) return (0);
      f0_36("GmtOffset:");
      f0_36(DoubleToStr(GmtOffset, 1), TextColor2, gi_652, gi_648 - 1, 77);
      f0_34();
      f0_36("Digits:");
      f0_36(Digits, TextColor2, gi_652, gi_648 - 1, 56);
      f0_36("Spread:");
      f0_36(StringConcatenate(DoubleToStr(g_spread_276 / gd_288, 1), " (", g_spread_276, " pips)"), TextColor2, gi_652, gi_648 - 1, 56);
      f0_34();
      return (0);
   }
   GlobalVariableSet("GV_PipJet_MKT", g_global_var_336);
   switch (UninitializeReason()) {
   case REASON_CHARTCLOSE:
   case REASON_REMOVE:
      f0_47(0, gi_656);
      gi_656 = 0;
      break;
   case REASON_RECOMPILE:
   case REASON_CHARTCHANGE:
   case REASON_PARAMETERS:
   case REASON_ACCOUNT:
      f0_47(1, gi_656);
      gi_656 = 1;
   }
   return (0);
}

void f0_18(bool ai_0) {
   double lda_4[1];
   if (ai_0) RefreshRates();
   g_datetime_256 = TimeCurrent();
   if (!IsTesting()) {
      gi_324 = GetParams(gi_328, g_datetime_256, AutoServerGmtOffset, lda_4);
      if (gi_324 == 4 && (!AutoLocalGmtOffset)) gi_324 = FALSE;
      else GmtOffset = lda_4[0];
   }
   gi_260 = g_datetime_256 - 3600.0 * GmtOffset;
   g_hour_264 = TimeHour(gi_260);
   gi_272 = g_datetime_256 - 3600.0 * g_hour_264 - 60 * TimeMinute(gi_260) - TimeSeconds(gi_260);
   g_spread_276 = MarketInfo(Symbol(), MODE_SPREAD);
   gi_284 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   gd_288 = 0.0001 / Point;
   if (Digits < 4) gd_288 = 100.0 * gd_288;
}

int f0_27() {
   for (int count_0 = 0; IsTradeContextBusy() && count_0 < 10; count_0++) Sleep(15);
   if (count_0 >= 10) Print("Trade context is buisy more than ", DoubleToStr(15 * count_0 / 1000, 2), " seconds");
   else
      if (count_0 > 0) Print("Trade context was buisy ", DoubleToStr(15 * count_0 / 1000, 2), " seconds");
   return (count_0);
}

int f0_28(int a_cmd_0, double a_lots_4, double a_price_12, double a_price_20, double a_price_28, int a_magic_36, color a_color_40, bool ai_44 = FALSE) {
   double price_48;
   double price_56;
   int error_68;
   double price_76;
   int ticket_64 = -1;
   int count_72 = 0;
   bool li_84 = FALSE;
   double ld_88 = gd_768 * gd_288 * Point;
   while (!li_84) {
      if (!ai_44) {
         price_48 = a_price_20;
         price_56 = a_price_28;
      } else {
         price_48 = 0;
         price_56 = 0;
      }
      if (a_cmd_0 == OP_BUY) price_76 = MarketInfo(Symbol(), MODE_ASK);
      else
         if (a_cmd_0 == OP_SELL) price_76 = MarketInfo(Symbol(), MODE_BID);
      if (count_72 > 0 && MathAbs(price_76 - a_price_12) > ld_88) {
         Print("Price is too far");
         break;
      }
      f0_27();
      ticket_64 = OrderSend(Symbol(), a_cmd_0, a_lots_4, a_price_12, Slippage * gd_288, price_56, price_48, OrderComments, a_magic_36, 0, a_color_40);
      if (ticket_64 >= 0) {
         gd_344 += a_lots_4;
         break;
      }
      count_72++;
      error_68 = GetLastError();
      switch (error_68) {
      case 130/* INVALID_STOPS */:
         if (!ai_44) g_global_var_336 = 1;
      case 0/* NO_ERROR */:
         if (!ai_44) ai_44 = TRUE;
         else li_84 = TRUE;
         break;
      case 4/* SERVER_BUSY */: break;
      case 6/* NO_CONNECTION */: break;
      case 129/* INVALID_PRICE */: break;
      case 136/* OFF_QUOTES */: break;
      case 137/* BROKER_BUSY */: break;
      case 146/* TRADE_CONTEXT_BUSY */: break;
      case 135/* PRICE_CHANGED */:
      case 138/* REQUOTE */:
         RefreshRates();
         break;
      default:
         li_84 = TRUE;
      }
      if (count_72 > 10) break;
   }
   if (ticket_64 >= 0) {
      if (ai_44) {
         if (OrderSelect(ticket_64, SELECT_BY_TICKET)) {
            Sleep(1000);
            f0_27();
            OrderModify(ticket_64, OrderOpenPrice(), a_price_28, a_price_20, 0, a_color_40);
         }
      }
      if (count_72 > 5) Print(f0_29(a_cmd_0) + " operation attempts: ", count_72);
      if (SendEmails) SendMail(gs_400, "Open " + f0_29(a_cmd_0) + ": [" + Symbol() + "] " + NormalizeDouble(a_price_12, Digits));
   } else Print(f0_29(a_cmd_0) + " operation failed - error(", error_68, "): ", ErrorDescription(error_68), " attempts: ", count_72);
   return (ticket_64);
}

int f0_42(int ai_0, color a_color_4, bool ai_8 = FALSE) {
   double price_12;
   double order_takeprofit_20;
   double order_stoploss_28;
   int error_40;
   if (ai_8) {
      f0_27();
      order_takeprofit_20 = OrderTakeProfit();
      order_stoploss_28 = OrderStopLoss();
      OrderModify(OrderTicket(), OrderOpenPrice(), 0, 0, 0, a_color_4);
   }
   for (int count_36 = 0; count_36 < 10; count_36++) {
      if (f0_27() > 5) RefreshRates();
      if (ai_0 == 0) price_12 = Bid;
      else price_12 = Ask;
      if (OrderClose(OrderTicket(), OrderLots(), price_12, Slippage * gd_288, a_color_4)) return (-1);
      error_40 = GetLastError();
      Print("Order close operation failed - error(", error_40, "): ", ErrorDescription(error_40));
      if (error_40 == 4108/* INVALID_TICKET */) return (-2);
      RefreshRates();
   }
   if (ai_8) {
      f0_27();
      OrderModify(OrderTicket(), OrderOpenPrice(), order_stoploss_28, order_takeprofit_20, 0, a_color_4);
   }
   Print("Order close operation failed");
   return (OrderTicket());
}

double f0_49(double ad_0, double ad_8, int &ai_16) {
   if (AccountLeverage() < 100) return (f0_9(ad_0 * ad_8 / MarketInfo(Symbol(), MODE_MARGINREQUIRED), ai_16));
   return (f0_9(ad_0 * ad_8 / MarketInfo(Symbol(), MODE_MARGINREQUIRED) / (AccountLeverage() / 100.0), ai_16));
}

double f0_9(double ad_0, int &ai_8) {
   double lotstep_20 = MarketInfo(Symbol(), MODE_LOTSTEP);
   double ld_28 = MarketInfo(Symbol(), MODE_MINLOT);
   double ld_36 = MarketInfo(Symbol(), MODE_MAXLOT);
   double ld_ret_12 = MathCeil(ad_0 / lotstep_20) * lotstep_20;
   ai_8 = 0;
   if (ld_ret_12 < ld_28) {
      ld_ret_12 = ld_28;
      ai_8 = -1;
   }
   if (ld_ret_12 > ld_36) {
      ld_ret_12 = ld_36;
      ai_8 = 1;
   }
   return (ld_ret_12);
}

void f0_30(double ad_0, double ad_8, int ai_16) {
   double ld_20 = (ad_8 - ad_0) / (Point * gd_288);
   if (ai_16 == 1) ld_20 = -ld_20;
   gd_676 += ld_20;
   if (gd_684 < gd_676) gd_684 = gd_676;
}

double f0_4(double ad_0) {
   int li_8;
   if (gd_684 > gd_676 + gd_228 * gd_288 && gi_760 > gi_776) {
      gi_340 = TRUE;
      return (f0_9(2.0 * ad_0, li_8));
   }
   gi_340 = FALSE;
   gi_776 = gi_760;
   return (ad_0);
}

int f0_31() {
   int count_0 = 0;
   gd_676 = 0;
   gd_684 = 0;
   for (int pos_4 = OrdersHistoryTotal() - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS, MODE_HISTORY)) {
         if (OrderMagicNumber() != S1_Reference && OrderMagicNumber() != S2_Reference) continue;
         f0_30(OrderOpenPrice(), OrderClosePrice(), OrderType());
         count_0++;
      }
   }
   return (count_0);
}

int f0_16(int a_magic_0, int a_cmd_4) {
   for (int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--) {
      if (OrderSelect(pos_8, SELECT_BY_POS)) {
         if (OrderMagicNumber() == a_magic_0) {
            if (OrderSymbol() == Symbol())
               if (OrderType() == a_cmd_4) return (OrderTicket());
         }
      }
   }
   return (-1);
}

void f0_8() {
   g_count_708 = 0;
   for (int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--) {
      if (OrderSelect(pos_0, SELECT_BY_POS)) {
         if (OrderSymbol() == Symbol())
            if (OrderMagicNumber() != S1_Reference && OrderMagicNumber() != S2_Reference) g_count_708++;
      }
   }
}

int f0_12() {
   return (g_count_708 <= 0 && g_ticket_712 < 0 && g_ticket_716 < 0 && g_ticket_736 < 0 && g_ticket_740 < 0);
}

int f0_33() {
   if (g_icci_816 >= 0.0 || g_irsi_784 >= 50.0) g_datetime_924 = g_datetime_256;
   if (g_icci_816 <= 0.0 || g_irsi_784 <= 50.0) g_datetime_920 = g_datetime_256;
   if (g_datetime_924 > 0 && g_datetime_256 - g_datetime_924 > 3600.0 * gd_516) return (2);
   if (g_datetime_920 > 0 && g_datetime_256 - g_datetime_920 > 3600.0 * gd_516) return (3);
   if (g_datetime_924 == 0 || g_datetime_920 == 0) return (0);
   return (1);
}

void f0_3() {
   int shift_0;
   if (g_datetime_256 - gi_272 < 3600.0 * gi_476) shift_0 = iBarShift(NULL, g_timeframe_424, gi_272 - 86400);
   else shift_0 = iBarShift(NULL, g_timeframe_424, gi_272);
   g_ihigh_872 = iHigh(NULL, g_timeframe_424, iHighest(NULL, g_timeframe_424, MODE_HIGH, shift_0 - gi_252, gi_252));
   g_ilow_880 = iLow(NULL, g_timeframe_424, iLowest(NULL, g_timeframe_424, MODE_LOW, shift_0 - gi_252, gi_252));
}

void f0_53() {
   int li_0;
   HideTestIndicators(TRUE);
   g_irsi_784 = iRSI(NULL, g_timeframe_424, g_period_456, PRICE_CLOSE, gi_252);
   g_irsi_792 = iRSI(NULL, g_timeframe_424, g_period_456, PRICE_CLOSE, gi_252 + 1);
   g_irsi_800 = iRSI(NULL, g_timeframe_424, g_period_456, PRICE_CLOSE, gi_252 + 2);
   if (gi_468) g_irsi_808 = iRSI(NULL, PERIOD_M1, g_period_460, PRICE_CLOSE, gi_252);
   g_icci_816 = iCCI(NULL, g_timeframe_424, g_period_464, PRICE_TYPICAL, gi_252);
   g_icci_824 = iCCI(NULL, g_timeframe_424, g_period_464, PRICE_TYPICAL, gi_252 + 1);
   g_icci_832 = iCCI(NULL, g_timeframe_424, g_period_464, PRICE_TYPICAL, gi_252 + 2);
   g_ima_856 = iMA(NULL, g_timeframe_424, g_period_464, 0, MODE_SMA, PRICE_MEDIAN, gi_252);
   if (gi_480) {
      if (g_irsi_784 >= 50 - gi_484 / 2 && g_irsi_784 <= gi_484 / 2 + 50) {
         gi_864 = TRUE;
         gi_868 = TRUE;
      }
   }
   if (gi_472) f0_3();
   if (gi_512) {
      li_0 = gi_908;
      gi_908 = f0_33();
      if (li_0 != gi_908) {
         gi_912 = li_0;
         if (gi_908 == 1) gi_916 = g_datetime_256 + 3600.0 * gd_524;
      }
   }
   if (gi_536 > 0) {
      if (g_spread_276 > gi_536 * gd_288) {
         if (g_spread_280 < g_spread_276) {
            Print("Strategy1: Safe spread limit exceeded: spread = ", g_spread_276);
            if (gi_540) Print("Strategy1: Using DayDirection filter");
         }
         gi_888 = TRUE;
      } else {
         if (g_spread_280 > gi_536 * gd_288) Print("Strategy1: Safe spread limit normalized: spread = ", g_spread_276);
         gi_888 = FALSE;
      }
   }
   HideTestIndicators(FALSE);
}

int f0_6() {
   double iclose_0;
   double iclose_8;
   int shift_16;
   int shift_20;
   if (!gi_864) return (0);
   if (gi_512) {
      if (gi_908 == 2) return (0);
      if (g_datetime_256 <= gi_916)
         if (gi_912 == 2) return (0);
   }
   if (gi_532 || gi_888) {
      if (g_datetime_256 - gi_272 < 43200.0) {
         shift_16 = iBarShift(NULL, g_timeframe_424, gi_272 - 86400);
         shift_20 = iBarShift(NULL, g_timeframe_424, gi_272);
      } else {
         shift_16 = iBarShift(NULL, g_timeframe_424, gi_272);
         shift_20 = gi_252;
      }
      iclose_8 = iClose(NULL, g_timeframe_424, shift_16);
      iclose_0 = iClose(NULL, g_timeframe_424, shift_20);
      if (iclose_0 < iclose_8) return (0);
   }
   return (s1_Buy(gi_328, Ask));
}

int f0_50() {
   double iclose_0;
   double iclose_8;
   int shift_16;
   int shift_20;
   if (!gi_868) return (0);
   if (gi_512) {
      if (gi_908 == 3) return (0);
      if (g_datetime_256 <= gi_916)
         if (gi_912 == 3) return (0);
   }
   if (gi_532 || gi_888) {
      if (g_datetime_256 - gi_272 < 43200.0) {
         shift_16 = iBarShift(NULL, g_timeframe_424, gi_272 - 86400);
         shift_20 = iBarShift(NULL, g_timeframe_424, gi_272);
      } else {
         shift_16 = iBarShift(NULL, g_timeframe_424, gi_272);
         shift_20 = gi_252;
      }
      iclose_8 = iClose(NULL, g_timeframe_424, shift_16);
      iclose_0 = iClose(NULL, g_timeframe_424, shift_20);
      if (iclose_0 > iclose_8) return (0);
   }
   return (s1_Sell(gi_328, Bid));
}

int f0_10() {
   if (Stealth || OrderTakeProfit() == 0.0) {
      if (gi_428 > 0)
         if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_428 * Point * gd_288, Digits)) return (1);
   }
   if (OrderStopLoss() == 0.0) {
      if (gi_896 > 0)
         if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_896 * Point, Digits)) return (1);
   }
   if (gi_492) {
      if (g_ticket_928 != OrderTicket()) {
         g_datetime_932 = OrderOpenTime();
         g_ticket_928 = OrderTicket();
      }
      if (g_icci_816 >= 0.0 || g_irsi_784 >= 50.0) g_datetime_932 = g_datetime_256;
      if (g_icci_832 < g_icci_824 && g_irsi_800 < g_irsi_792) g_datetime_932 = iTime(NULL, g_timeframe_424, gi_252);
      if (g_datetime_256 - g_datetime_932 > 3600.0 * gd_496 && OrderProfit() < 0.0) return (1);
   }
   if (gi_488) {
      if (g_datetime_256 - OrderOpenTime() > 3600.0 * gd_496) {
         if (g_icci_816 > 0.0 && g_irsi_784 > 50.0 && OrderProfit() > 0.0) return (1);
         if (g_datetime_256 - OrderOpenTime() > 3600.0 * gd_504) return (1);
      }
   }
   return (0);
}

int f0_26() {
   if (Stealth || OrderTakeProfit() == 0.0) {
      if (gi_428 > 0)
         if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_428 * Point * gd_288, Digits)) return (1);
   }
   if (OrderStopLoss() == 0.0) {
      if (gi_904 > 0)
         if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_904 * Point, Digits)) return (1);
   }
   if (gi_492) {
      if (g_ticket_936 != OrderTicket()) {
         g_datetime_940 = OrderOpenTime();
         g_ticket_936 = OrderTicket();
      }
      if (g_icci_816 <= 0.0 || g_irsi_784 <= 50.0) g_datetime_940 = g_datetime_256;
      if (g_icci_832 > g_icci_824 && g_irsi_800 > g_irsi_792) g_datetime_940 = iTime(NULL, g_timeframe_424, gi_252);
      if (g_datetime_256 - g_datetime_940 > 3600.0 * gd_496 && OrderProfit() < 0.0) return (1);
   }
   if (gi_488) {
      if (g_datetime_256 - OrderOpenTime() > 3600.0 * gd_496) {
         if (g_icci_816 < 0.0 && g_irsi_784 < 50.0 && OrderProfit() > 0.0) return (1);
         if (g_datetime_256 - OrderOpenTime() > 3600.0 * gd_504) return (1);
      }
   }
   return (0);
}

int f0_41() {
   double ld_0 = 0;
   double ld_8 = 0;
   if (g_ilow_880 > 0.0) {
      gi_896 = (Bid - g_ilow_880 + Point * gd_288) / Point;
      if (gi_436 > 0 && gi_896 > gi_436 * gd_288) gi_896 = gi_436 * gd_288;
      if (gi_896 < gi_440 * gd_288) gi_896 = gi_440 * gd_288;
   } else gi_896 = gi_440 * gd_288;
   if (gi_896 < gi_284) gi_896 = gi_284;
   if (Stealth) gi_892 = gi_432 * gd_288;
   else gi_892 = gi_428 * gd_288;
   if (gi_892 < gi_284) gi_892 = gi_284;
   ld_8 = NormalizeDouble(Bid - gi_896 * Point, Digits);
   ld_0 = NormalizeDouble(Ask + gi_892 * Point, Digits);
   return (f0_28(OP_BUY, gd_296, Ask, ld_0, ld_8, S1_Reference, gi_448, g_global_var_336));
}

int f0_48() {
   double ld_0 = 0;
   double ld_8 = 0;
   if (g_ihigh_872 > 0.0) {
      gi_904 = (g_ihigh_872 - Ask + Point * gd_288) / Point;
      if (gi_436 > 0 && gi_904 > gi_436 * gd_288) gi_904 = gi_436 * gd_288;
      if (gi_904 < gi_440 * gd_288) gi_904 = gi_440 * gd_288;
   } else gi_904 = gi_440 * gd_288;
   if (gi_904 < gi_284) gi_904 = gi_284;
   if (Stealth) gi_900 = gi_432 * gd_288;
   else gi_900 = gi_428 * gd_288;
   if (gi_900 < gi_284) gi_900 = gi_284;
   ld_8 = NormalizeDouble(Ask + gi_904 * Point, Digits);
   ld_0 = NormalizeDouble(Bid - gi_900 * Point, Digits);
   return (f0_28(OP_SELL, gd_296, Bid, ld_0, ld_8, S1_Reference, gi_452, g_global_var_336));
}

int f0_0() {
   int li_ret_16;
   double order_takeprofit_0 = OrderTakeProfit();
   double order_stoploss_8 = OrderStopLoss();
   if (order_takeprofit_0 == 0.0 || order_stoploss_8 == 0.0) {
      if (order_takeprofit_0 == 0.0) {
         if (gi_892 < gi_284) gi_892 = gi_284;
         order_takeprofit_0 = NormalizeDouble(Ask + gi_892 * Point, Digits);
      }
      if (order_stoploss_8 == 0.0) {
         if (gi_896 < gi_284) gi_896 = gi_284;
         order_stoploss_8 = NormalizeDouble(Bid - gi_896 * Point, Digits);
      }
      f0_27();
      OrderModify(OrderTicket(), OrderOpenPrice(), order_stoploss_8, order_takeprofit_0, 0, Green);
   }
   if (f0_10()) {
      li_ret_16 = f0_42(0, Violet, g_global_var_336);
      if (li_ret_16 < 0) return (li_ret_16);
   }
   if (gi_444 > 0) {
      if (Bid - OrderOpenPrice() > Point * gd_288 * gi_444) {
         if (OrderStopLoss() < Bid - Point * gd_288 * gi_444 || OrderStopLoss() == 0.0) {
            f0_27();
            OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gd_288 * gi_444, Digits), OrderTakeProfit(), 0, Green);
         }
      }
   }
   return (OrderTicket());
}

int f0_46() {
   int li_ret_16;
   double order_takeprofit_0 = OrderTakeProfit();
   double order_stoploss_8 = OrderStopLoss();
   if (order_takeprofit_0 == 0.0 || order_stoploss_8 == 0.0) {
      if (order_takeprofit_0 == 0.0) {
         if (gi_900 < gi_284) gi_900 = gi_284;
         order_takeprofit_0 = NormalizeDouble(Bid - gi_900 * Point, Digits);
      }
      if (order_stoploss_8 == 0.0) {
         if (gi_904 < gi_284) gi_904 = gi_284;
         order_stoploss_8 = NormalizeDouble(Ask + gi_904 * Point, Digits);
      }
      f0_27();
      OrderModify(OrderTicket(), OrderOpenPrice(), order_stoploss_8, order_takeprofit_0, 0, Red);
   }
   if (f0_26()) {
      li_ret_16 = f0_42(1, Violet, g_global_var_336);
      if (li_ret_16 < 0) return (li_ret_16);
   }
   if (gi_444 > 0) {
      if (OrderOpenPrice() - Ask > Point * gd_288 * gi_444) {
         if (OrderStopLoss() > Ask + Point * gd_288 * gi_444 || OrderStopLoss() == 0.0) {
            f0_27();
            OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gd_288 * gi_444, Digits), OrderTakeProfit(), 0, Red);
         }
      }
   }
   return (OrderTicket());
}

void f0_1() {
   if (g_ticket_712 == -2) {
      g_ticket_712 = f0_16(S1_Reference, OP_BUY);
      if (g_ticket_712 >= 0) {
         OrderSelect(g_ticket_712, SELECT_BY_TICKET);
         OrderPrint();
         Print("Strategy1: Order found:");
      }
   }
   if (g_ticket_716 == -2) {
      g_ticket_716 = f0_16(S1_Reference, OP_SELL);
      if (g_ticket_716 >= 0) {
         OrderSelect(g_ticket_716, SELECT_BY_TICKET);
         OrderPrint();
         Print("Strategy1: Order found:");
      }
   }
   f0_53();
   gi_696 = s1_SetRules(gi_328, gi_260, gi_888, g_icci_816, g_irsi_784, g_irsi_808, g_ima_856, Point * gd_288);
   if (gi_944 != gi_696) {
      if (gi_696) gi_760++;
      gi_944 = gi_696;
   }
   if (g_ticket_712 >= 0) {
      if (OrderSelect(g_ticket_712, SELECT_BY_TICKET)) {
         if (OrderCloseTime() == 0) g_ticket_712 = f0_0();
         else g_ticket_712 = -1;
         g_order_profit_720 = OrderProfit();
         if (g_ticket_712 < 0) f0_30(OrderOpenPrice(), OrderClosePrice(), OrderType());
      } else {
         g_ticket_712 = -2;
         g_order_profit_720 = 0;
      }
   }
   if (g_ticket_716 >= 0) {
      if (OrderSelect(g_ticket_716, SELECT_BY_TICKET)) {
         if (OrderCloseTime() == 0) g_ticket_716 = f0_46();
         else g_ticket_716 = -1;
         g_order_profit_728 = OrderProfit();
         if (g_ticket_716 < 0) f0_30(OrderOpenPrice(), OrderClosePrice(), OrderType());
      } else {
         g_ticket_716 = -2;
         g_order_profit_728 = 0;
      }
   }
   if ((!gi_696) || !gi_704 || gi_692) return;
   if (NFA && !f0_12()) return;
   int li_0 = f0_6();
   int li_4 = f0_50();
   if (g_datetime_948 != iTime(NULL, g_timeframe_424, gi_252) && li_0 && g_ticket_712 < 0) {
      g_ticket_712 = f0_41();
      if (g_ticket_712 < 0) return;
      g_datetime_948 = iTime(NULL, g_timeframe_424, gi_252);
      if (gi_480) {
         gi_864 = FALSE;
         gi_868 = TRUE;
      }
      gi_780++;
      return;
   }
   if (g_datetime_952 != iTime(NULL, g_timeframe_424, gi_252) && li_4 && g_ticket_716 < 0) {
      g_ticket_716 = f0_48();
      if (g_ticket_716 >= 0) {
         g_datetime_952 = iTime(NULL, g_timeframe_424, gi_252);
         if (gi_480) {
            gi_864 = TRUE;
            gi_868 = FALSE;
         }
         gi_780++;
      }
   }
}

void f0_35() {
   HideTestIndicators(TRUE);
   if (gi_596 || gi_604) g_icci_960 = iCCI(NULL, g_timeframe_544, g_period_588, PRICE_TYPICAL, gi_252);
   if (gi_600) g_icci_968 = iCCI(NULL, g_timeframe_544, g_period_592, PRICE_TYPICAL, gi_252);
   g_ihigh_976 = iHigh(NULL, g_timeframe_544, iHighest(NULL, g_timeframe_544, MODE_HIGH, gi_584, 1));
   g_ilow_984 = iLow(NULL, g_timeframe_544, iLowest(NULL, g_timeframe_544, MODE_LOW, gi_584, 1));
   if (gi_640 > 0) {
      if (g_spread_276 > gi_640 * gd_288) {
         if (g_spread_280 < g_spread_276) {
            Print("Strategy2: Safe spread limit exceeded: spread = ", g_spread_276);
            if (gi_644) Print("Strategy2: Using DayDirection filter");
         }
         gi_1008 = TRUE;
      } else {
         if (g_spread_280 > gi_640 * gd_288) Print("Strategy2: Safe spread limit normalized: spread = ", g_spread_276);
         gi_1008 = FALSE;
      }
   }
   HideTestIndicators(TRUE);
}

int f0_7() {
   double iclose_0;
   double iclose_8;
   int shift_16;
   int shift_20;
   if (gi_636 || gi_1008) {
      if (g_datetime_256 - gi_272 < 43200.0) {
         shift_16 = iBarShift(NULL, g_timeframe_544, gi_272 - 86400);
         shift_20 = iBarShift(NULL, g_timeframe_544, gi_272);
      } else {
         shift_16 = iBarShift(NULL, g_timeframe_544, gi_272);
         shift_20 = gi_252;
      }
      iclose_8 = iClose(NULL, g_timeframe_544, shift_16);
      iclose_0 = iClose(NULL, g_timeframe_544, shift_20);
      if (iclose_0 < iclose_8) return (0);
   }
   return (s2_Buy(gi_328, Ask, Bid));
}

int f0_22() {
   double iclose_0;
   double iclose_8;
   int shift_16;
   int shift_20;
   if (gi_636 || gi_1008) {
      if (g_datetime_256 - gi_272 < 43200.0) {
         shift_16 = iBarShift(NULL, g_timeframe_544, gi_272 - 86400);
         shift_20 = iBarShift(NULL, g_timeframe_544, gi_272);
      } else {
         shift_16 = iBarShift(NULL, g_timeframe_544, gi_272);
         shift_20 = gi_252;
      }
      iclose_8 = iClose(NULL, g_timeframe_544, shift_16);
      iclose_0 = iClose(NULL, g_timeframe_544, shift_20);
      if (iclose_0 > iclose_8) return (0);
   }
   return (s2_Sell(gi_328, Ask, Bid));
}

int f0_23() {
   double order_profit_0;
   if (Stealth || OrderTakeProfit() == 0.0) {
      if (gi_548 > 0)
         if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_548 * Point * gd_288, Digits)) return (1);
   }
   if (OrderStopLoss() == 0.0) {
      if (gi_1016 > 0)
         if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_1016 * Point, Digits)) return (1);
   }
   if (gi_604) {
      if (g_ticket_1028 != OrderTicket()) {
         gi_1032 = 0;
         gi_1036 = 0;
         g_datetime_1044 = OrderOpenTime();
         g_datetime_1040 = g_datetime_1044;
         g_ticket_1028 = OrderTicket();
         g_order_open_price_1048 = OrderOpenPrice();
      }
      order_profit_0 = OrderProfit();
      if (Ask > g_order_open_price_1048) {
         gi_1032 += g_datetime_256 - g_datetime_1040;
         g_datetime_1040 = g_datetime_256;
      } else {
         gi_1036 += g_datetime_256 - g_datetime_1040;
         g_datetime_1040 = g_datetime_256;
      }
      if (g_datetime_256 - g_datetime_1044 > 3600.0 * gd_608) {
         if (g_icci_960 > 0.0 && order_profit_0 > 0.0 && gi_1032 < gi_1036) return (1);
         if (g_icci_960 > 100.0 && order_profit_0 > 0.0) return (1);
         if (g_datetime_256 - g_datetime_1044 > 3600.0 * gd_616 && order_profit_0 > 0.0) return (1);
         if (g_datetime_256 - g_datetime_1044 > 3600.0 * gd_624) return (1);
      }
   }
   if (gi_632) return (Bid >= g_ihigh_976);
   return (Bid >= g_ihigh_992);
}

int f0_14() {
   double order_profit_0;
   if (Stealth || OrderTakeProfit() == 0.0) {
      if (gi_548 > 0)
         if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) >= NormalizeDouble(gi_548 * Point * gd_288, Digits)) return (1);
   }
   if (OrderStopLoss() == 0.0) {
      if (gi_1024 > 0)
         if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) >= NormalizeDouble(gi_1024 * Point, Digits)) return (1);
   }
   if (gi_604) {
      if (g_ticket_1056 != OrderTicket()) {
         gi_1060 = 0;
         gi_1064 = 0;
         g_datetime_1072 = OrderOpenTime();
         g_datetime_1068 = g_datetime_1072;
         g_ticket_1056 = OrderTicket();
         g_order_open_price_1076 = OrderOpenPrice();
      }
      order_profit_0 = OrderProfit();
      if (Bid < g_order_open_price_1076) {
         gi_1060 += g_datetime_256 - g_datetime_1068;
         g_datetime_1068 = g_datetime_256;
      } else {
         gi_1064 += g_datetime_256 - g_datetime_1068;
         g_datetime_1068 = g_datetime_256;
      }
      if (g_datetime_256 - g_datetime_1072 > 3600.0 * gd_608) {
         if (g_icci_960 < 0.0 && order_profit_0 > 0.0 && gi_1060 < gi_1064) return (1);
         if (g_icci_960 < -100.0 && order_profit_0 > 0.0) return (1);
         if (g_datetime_256 - g_datetime_1072 > 3600.0 * gd_616 && order_profit_0 > 0.0) return (1);
         if (g_datetime_256 - g_datetime_1072 > 3600.0 * gd_624) return (1);
      }
   }
   if (gi_632) return (Ask <= g_ilow_984);
   return (Ask <= g_ilow_1000);
}

int f0_19() {
   double ld_0 = 0;
   double ld_8 = 0;
   if (gd_564 > 0.0) {
      gi_1016 = gd_564 * (g_ihigh_976 - g_ilow_984) / Point;
      if (gi_556 > 0 && gi_1016 > gi_556 * gd_288) gi_1016 = gi_556 * gd_288;
      if (gi_1016 < gi_560 * gd_288) gi_1016 = gi_560 * gd_288;
   } else gi_1016 = gi_560 * gd_288;
   if (gi_1016 < gi_284) gi_1016 = gi_284;
   if (Stealth) gi_1012 = gi_552 * gd_288;
   else gi_1012 = gi_548 * gd_288;
   if (gi_1012 < gi_284) gi_1012 = gi_284;
   ld_8 = NormalizeDouble(Bid - gi_1016 * Point, Digits);
   ld_0 = NormalizeDouble(Ask + gi_1012 * Point, Digits);
   return (f0_28(OP_BUY, gd_296, Ask, ld_0, ld_8, S2_Reference, gi_576, g_global_var_336));
}

int f0_39() {
   double ld_0 = 0;
   double ld_8 = 0;
   if (gd_564 > 0.0) {
      gi_1024 = gd_564 * (g_ihigh_976 - g_ilow_984) / Point;
      if (gi_556 > 0 && gi_1024 > gi_556 * gd_288) gi_1024 = gi_556 * gd_288;
      if (gi_1024 < gi_560 * gd_288) gi_1024 = gi_560 * gd_288;
   } else gi_1024 = gi_560 * gd_288;
   if (gi_1024 < gi_284) gi_1024 = gi_284;
   if (Stealth) gi_1020 = gi_552 * gd_288;
   else gi_1020 = gi_548 * gd_288;
   if (gi_1020 < gi_284) gi_1020 = gi_284;
   ld_8 = NormalizeDouble(Ask + gi_1024 * Point, Digits);
   ld_0 = NormalizeDouble(Bid - gi_1020 * Point, Digits);
   return (f0_28(OP_SELL, gd_296, Bid, ld_0, ld_8, S2_Reference, gi_580, g_global_var_336));
}

int f0_32() {
   int li_ret_16;
   double order_takeprofit_0 = OrderTakeProfit();
   double order_stoploss_8 = OrderStopLoss();
   if (order_takeprofit_0 == 0.0 || order_stoploss_8 == 0.0) {
      if (order_takeprofit_0 == 0.0) {
         if (gi_1012 < gi_284) gi_1012 = gi_284;
         order_takeprofit_0 = NormalizeDouble(Ask + gi_1012 * Point, Digits);
      }
      if (order_stoploss_8 == 0.0) {
         if (gi_1016 < gi_284) gi_1016 = gi_284;
         order_stoploss_8 = NormalizeDouble(Bid - gi_1016 * Point, Digits);
      }
      f0_27();
      OrderModify(OrderTicket(), OrderOpenPrice(), order_stoploss_8, order_takeprofit_0, 0, Green);
   }
   if (f0_23()) {
      li_ret_16 = f0_42(0, Violet, g_global_var_336);
      if (li_ret_16 < 0) return (li_ret_16);
   }
   if (gi_572 > 0) {
      if (Bid - OrderOpenPrice() > Point * gd_288 * gi_572) {
         if (OrderStopLoss() < Bid - Point * gd_288 * gi_572 || OrderStopLoss() == 0.0) {
            f0_27();
            OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gd_288 * gi_572, Digits), OrderTakeProfit(), 0, Green);
         }
      }
   }
   return (OrderTicket());
}

int f0_45() {
   int li_ret_16;
   double order_takeprofit_0 = OrderTakeProfit();
   double order_stoploss_8 = OrderStopLoss();
   if (order_takeprofit_0 == 0.0 || order_stoploss_8 == 0.0) {
      if (order_takeprofit_0 == 0.0) {
         if (gi_1020 < gi_284) gi_1020 = gi_284;
         order_takeprofit_0 = NormalizeDouble(Bid - gi_1020 * Point, Digits);
      }
      if (order_stoploss_8 == 0.0) {
         if (gi_1024 < gi_284) gi_1024 = gi_284;
         order_stoploss_8 = NormalizeDouble(Ask + gi_1024 * Point, Digits);
      }
      f0_27();
      OrderModify(OrderTicket(), OrderOpenPrice(), order_stoploss_8, order_takeprofit_0, 0, Red);
   }
   if (f0_14()) {
      li_ret_16 = f0_42(1, Violet, g_global_var_336);
      if (li_ret_16 < 0) return (li_ret_16);
   }
   if (gi_572 > 0) {
      if (OrderOpenPrice() - Ask > Point * gd_288 * gi_572) {
         if (OrderStopLoss() > Ask + Point * gd_288 * gi_572 || OrderStopLoss() == 0.0) {
            f0_27();
            OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gd_288 * gi_572, Digits), OrderTakeProfit(), 0, Red);
         }
      }
   }
   return (OrderTicket());
}

void f0_38() {
   if (g_ticket_736 == -2) {
      g_ticket_736 = f0_16(S2_Reference, OP_BUY);
      if (g_ticket_736 >= 0) {
         OrderSelect(g_ticket_736, SELECT_BY_TICKET);
         OrderPrint();
         Print("Strategy2: Order found:");
      }
   }
   if (g_ticket_740 == -2) {
      g_ticket_740 = f0_16(S2_Reference, OP_SELL);
      if (g_ticket_740 >= 0) {
         OrderSelect(g_ticket_740, SELECT_BY_TICKET);
         OrderPrint();
         Print("Strategy2: Order found:");
      }
   }
   f0_35();
   gi_700 = s2_SetRules(gi_328, gi_260, gi_1008, g_icci_960, g_icci_968, g_ilow_984, g_ihigh_976);
   if (gi_1084 != gi_700) {
      if (gi_700) {
         g_order_profit_744 = 0;
         g_order_profit_752 = 0;
         gi_764++;
      }
      gi_1084 = gi_700;
   }
   if (g_ticket_736 >= 0) {
      if (OrderSelect(g_ticket_736, SELECT_BY_TICKET)) {
         if (OrderCloseTime() == 0) g_ticket_736 = f0_32();
         else g_ticket_736 = -1;
         g_order_profit_744 = OrderProfit();
         if (g_ticket_736 < 0) f0_30(OrderOpenPrice(), OrderClosePrice(), OrderType());
      } else {
         g_ticket_736 = -2;
         g_order_profit_744 = 0;
      }
   }
   if (g_ticket_740 >= 0) {
      if (OrderSelect(g_ticket_740, SELECT_BY_TICKET)) {
         if (OrderCloseTime() == 0) g_ticket_740 = f0_45();
         else g_ticket_740 = -1;
         g_order_profit_752 = OrderProfit();
         if (g_ticket_740 < 0) f0_30(OrderOpenPrice(), OrderClosePrice(), OrderType());
      } else {
         g_ticket_740 = -2;
         g_order_profit_752 = 0;
      }
   }
   if ((!gi_700) || !gi_704 || gi_692) return;
   if (NFA && !f0_12()) return;
   int li_0 = f0_7();
   int li_4 = f0_22();
   if (g_datetime_1088 != iTime(NULL, g_timeframe_544, gi_252) && li_0 && g_ticket_736 < 0 && g_order_profit_744 >= 0.0) {
      g_ticket_736 = f0_19();
      if (g_ticket_736 < 0) return;
      g_datetime_1088 = iTime(NULL, g_timeframe_544, gi_252);
      g_ihigh_992 = g_ihigh_976;
      g_ilow_1000 = g_ilow_984;
      g_order_profit_752 = 0;
      gi_956++;
      return;
   }
   if (g_datetime_1092 != iTime(NULL, g_timeframe_544, gi_252) && li_4 && g_ticket_740 < 0 && g_order_profit_752 >= 0.0) {
      g_ticket_740 = f0_39();
      if (g_ticket_740 >= 0) {
         g_datetime_1092 = iTime(NULL, g_timeframe_544, gi_252);
         g_ihigh_992 = g_ihigh_976;
         g_ilow_1000 = g_ilow_984;
         g_order_profit_744 = 0;
         gi_956++;
      }
   }
}

string f0_11(bool ai_0) {
   if (ai_0) return ("True");
   return ("False");
}

string f0_2(bool ai_0, string as_4, string as_12 = "") {
   if (ai_0) return (as_4);
   return (as_12);
}

string f0_29(int ai_0) {
   switch (ai_0) {
   case 0:
      return ("Buy");
   case 1:
      return ("Sell");
   }
   return ("Order");
}

string f0_24(int ai_0) {
   switch (ai_0) {
   case 1:
      return ("automatic: server");
   case 2:
      return ("automatic: server");
   case 4:
      return ("automatic: local");
   }
   return ("manual");
}

string f0_37(int ai_0) {
   switch (ai_0) {
   case 1:
      return ("Correction");
   case 3:
      return ("Upward Impulse");
   case 2:
      return ("Downward Impulse");
   }
   return ("");
}

string f0_13(int ai_0) {
   int li_4 = MathMod(ai_0, 5);
   return (gsa_1096[li_4]);
}

void f0_40(int ai_0, int ai_4 = -1, int ai_8 = -1) {
   if (ai_4 == -1) ai_4 = gi_652;
   if (ai_8 == -1) ai_8 = gi_648;
   gi_652 = ai_4;
   gi_648 = ai_8;
   if (ai_0 & 16384 > 0) f0_36("Authenticated", TextColor1);
   else f0_36("Authentication failed - error(" + ai_0 + ")", TextColor1);
   if (ai_0 & 512 > 0) f0_36("Attention: Upgrade available", TextColor1);
   if (ai_0 & 1024 > 0) f0_36("Error: Upgrade required", TextColor1);
   if (ai_0 & 1 > 0) f0_36("Error: Internet initialization failed", TextColor1);
   if (ai_0 & 2 > 0) f0_36("Error: Internet connection failed", TextColor1);
   if (ai_0 & 4 > 0) f0_36("Error: Invalid account number", TextColor1);
   if (ai_0 & 8 > 0) f0_36("Error: Invalid account status", TextColor1);
   if (ai_0 & 16 > 0) f0_36("Error: Dll and Expert versions mismatch", TextColor1);
   if (ai_0 & 128 > 0) f0_36("Error: Unable to retrieve authentication code", TextColor1);
   if (ai_0 & 256 > 0) f0_36("Error: Server response failure", TextColor1);
   if (ai_0 & 2048 > 0) f0_36("Error: Invalid authorisation details", TextColor1);
   if (ai_0 & 4096 > 0) f0_36("Error: Authorisation declined", TextColor1);
}

string f0_52(int ai_0) {
   return (StringConcatenate("PipJet", " lb: ", ai_0));
}

void f0_5(int ai_0, int &ai_4, int &ai_8) {
   string name_12 = f0_52(ai_0);
   if (ObjectFind(name_12) == 0) {
      ai_4 = ObjectGet(name_12, OBJPROP_XDISTANCE);
      ai_8 = ObjectGet(name_12, OBJPROP_YDISTANCE);
   }
}

void f0_36(string a_text_0, color a_color_8 = -1, int ai_12 = -1, double ad_16 = -1.0, int ai_24 = 0) {
   if (a_color_8 == CLR_NONE) a_color_8 = TextColor1;
   if (ai_12 == -1) ai_12 = gi_652;
   if (ad_16 == -1.0) ad_16 = gi_648;
   string name_28 = f0_52(ai_12);
   if (ObjectFind(name_28) != 0) {
      ObjectCreate(name_28, OBJ_LABEL, 0, 0, 0);
      ObjectSet(name_28, OBJPROP_CORNER, 0);
   }
   ObjectSetText(name_28, a_text_0, 9, "Courier New", a_color_8);
   ObjectSet(name_28, OBJPROP_XDISTANCE, gi_664 + ai_24);
   ObjectSet(name_28, OBJPROP_YDISTANCE, gi_660 + 14.0 * ad_16);
   if (gi_648 < ad_16 + 1.0) gi_648 = ad_16 + 1.0;
   if (gi_652 < ai_12 + 1) gi_652 = ai_12 + 1;
   if (gi_656 < ai_12) gi_656 = ai_12;
}

void f0_34(int ai_0 = -1, double ad_4 = -1.0, int ai_12 = 0) {
   if (ai_0 == -1) ai_0 = gi_652;
   if (ad_4 == -1.0) ad_4 = gi_648;
   f0_36("_______", TextColor2, ai_0, ad_4 - 0.3, ai_12);
   if (gi_648 < ad_4 + 1.0) gi_648 = ad_4 + 1.0;
}

int f0_43(string as_0, int ai_8 = -1, int ai_12 = -1, double ad_16 = -1.0, int ai_24 = 0) {
   string ls_36;
   int li_52;
   int li_56;
   string ls_60;
   string ls_68;
   string ls_76;
   string name_84;
   int li_92;
   int li_96;
   int li_28 = 0;
   int li_32 = 0;
   if (ai_12 == -1) ai_12 = gi_652;
   if (ad_16 == -1.0) ad_16 = gi_648;
   int li_44 = StringLen(as_0);
   int li_48 = 0;
   while (li_32 < li_44) {
      li_48 = 0;
      li_32 = StringFind(as_0, 
      "\n", li_28);
      if (li_32 == -1) li_32 = li_44;
      else li_48 = 1;
      ls_36 = StringSubstr(as_0, li_28, li_32 - li_28);
      if (ls_36 == "0") {
         f0_34(ai_12, ad_16, ai_24);
         ai_12++;
      } else {
         li_52 = StringFind(ls_36, "<a>");
         li_56 = -1;
         if (li_52 >= 0) li_56 = StringFind(ls_36, "</a>", li_52 + 3);
         if (li_52 >= 0 && li_56 > 0) {
            if (li_52 > 0) ls_60 = StringSubstr(ls_36, 0, li_52);
            else ls_60 = "";
            ls_68 = StringSubstr(ls_36, li_52 + 3, li_56 - li_52 - 3);
            ls_76 = StringSubstr(ls_36, li_56 + 4);
            if (StringLen(ls_60) > 0) {
               f0_36(ls_60, ai_8, ai_12, ad_16, ai_24);
               ai_12++;
            }
            name_84 = f0_52(ai_12);
            f0_36(ls_68, TextColor3, ai_12, ad_16, ai_24 + 7 * StringLen(ls_60));
            li_92 = ObjectGet(name_84, OBJPROP_XDISTANCE);
            li_96 = ObjectGet(name_84, OBJPROP_YDISTANCE);
            AddLink(gi_328, li_92, li_96, li_92 + 7 * StringLen(ls_68), li_96 + 14, ls_68);
            ai_12++;
            if (StringLen(ls_76) > 0) {
               f0_36(ls_76, ai_8, ai_12, ad_16, ai_24 + 7 * (StringLen(ls_60) + StringLen(ls_68)));
               ai_12++;
            }
         } else {
            if (li_32 - li_28 > 60) li_32 = li_28 + 60;
            ls_36 = StringSubstr(as_0, li_28, li_32 - li_28);
            f0_36(ls_36, ai_8, ai_12, ad_16, ai_24);
            ai_12++;
         }
      }
      li_28 = li_32 + li_48;
      ad_16++;
   }
   return (ai_12);
}

void f0_47(int ai_0, int ai_4) {
   for (int li_8 = ai_0; li_8 <= ai_4; li_8++) ObjectDelete(f0_52(li_8));
}

double f0_17(string as_0) {
   int li_24;
   as_0 = f0_44(as_0);
   int str_len_8 = StringLen(as_0);
   double ld_ret_12 = 0;
   for (int li_20 = 0; li_20 < str_len_8; li_20++) {
      li_24 = StringFind(gs_1108, StringSubstr(as_0, str_len_8 - li_20 - 1, 1));
      ld_ret_12 += li_24 * MathPow(36, li_20);
   }
   return (ld_ret_12);
}

string f0_51(double ad_0) {
   string str_concat_8 = "";
   for (ad_0 = MathAbs(ad_0); ad_0 >= 1.0; ad_0 = MathFloor(ad_0 / 36.0)) str_concat_8 = StringConcatenate(StringSubstr(gs_1108, MathMod(ad_0, 36), 1), str_concat_8);
   return (str_concat_8);
}

string f0_44(string as_0) {
   int li_8;
   int li_20;
   int str_len_16 = StringLen(as_0);
   for (int li_12 = 0; li_12 < str_len_16; li_12++) {
      li_20 = 0;
      li_8 = StringGetChar(as_0, li_12);
      if (li_8 > '`' && li_8 < '{') li_20 = li_8 - 32;
      if (li_8 > '฿' && li_8 < 256) li_20 = li_8 - 32;
      if (li_8 == 'ธ') li_20 = 168;
      if (li_20 > 0) as_0 = StringSetChar(as_0, li_12, li_20);
   }
   return (as_0);
}

int f0_25() {
   int li_ret_0;
   if (RiskLevel > 0.0) {
      gd_296 = f0_49(RiskLevel, AccountFreeMargin(), li_ret_0);
      if (RecoveryMode) gd_296 = f0_4(gd_296);
   } else gd_296 = f0_9(LotSize, li_ret_0);
   return (li_ret_0);
}

int start() {
   int li_0;
   if ((!gi_236) && !gi_240) return (0);
   gi_316 = GetState();
   if (Bars < 100) {
      Print("Bars less than 100");
      return (0);
   }
   if (!IsTesting()) f0_21();
   g_spread_280 = g_spread_276;
   f0_18(0);
   if (gi_312) {
      gi_312 = FALSE;
      li_0 = f0_31();
      Print("Orders in history: ", li_0, " profit made: ", DoubleToStr(gd_676, 0), " pips");
   }
   int li_4 = f0_25();
   double ld_8 = NormalizeDouble(MarketInfo(Symbol(), MODE_MARGINREQUIRED) * gd_296, 8);
   gi_692 = NormalizeDouble(AccountFreeMargin(), 8) < ld_8;
   gi_704 = IsTradeTime(gi_328, gi_260, gi_244, RemoteSafetyMode);
   if (RemoteSafetyMode && (!IsTesting()) && gi_316 & 262144 > 0) gi_704 = FALSE;
   if (NFA) f0_8();
   if (gi_236) f0_1();
   f0_18(1);
   li_4 = f0_25();
   gi_692 = NormalizeDouble(AccountFreeMargin(), 8) < ld_8;
   if (gi_240) f0_38();
   if (IsTesting() && (!IsVisualMode())) return (0);
   f0_5(0, gi_664, gi_660);
   gi_652 = 0;
   gi_648 = 0;
   f0_36(gs_400, TextColor2);
   f0_34();
   f0_40(gi_316 | gi_320);
   LinksBegin(gi_328);
   int str_len_16 = StringLen(gs_352);
   int str_len_20 = StringLen(gs_360);
   if (str_len_16 > 1) f0_36(gs_352);
   if (str_len_20 > 0) f0_43(gs_360, TextColor2, gi_652, gi_648 - 1, 7 * (str_len_16 + 1));
   f0_34();
   str_len_16 = StringLen(gs_368);
   str_len_20 = StringLen(gs_376);
   if (str_len_16 > 1) f0_36(gs_368);
   if (str_len_20 > 0) f0_43(gs_376, TextColor2, gi_652, gi_648 - 1, 7 * (str_len_16 + 1));
   if (str_len_16 > 1 || str_len_20 > 0) f0_34();
   f0_36(gs_408);
   f0_36(gs_416, TextColor2, gi_652, gi_648 - 1, 7 * (StringLen(gs_408) + 1));
   f0_34();
   string ls_24 = DoubleToStr(GmtOffset, 1);
   if (!IsTesting()) ls_24 = StringConcatenate(ls_24, " (", f0_24(gi_324), ")");
   f0_36("ServerTime:");
   f0_36(TimeToStr(g_datetime_256), TextColor2, gi_652, gi_648 - 1, 84);
   f0_36("UtcTime:");
   f0_36(TimeToStr(gi_260), TextColor2, gi_652, gi_648 - 1, 63);
   f0_36("GmtOffset:");
   f0_36(ls_24, TextColor2, gi_652, gi_648 - 1, 77);
   f0_34();
   f0_36("Lot:");
   f0_36(DoubleToStr(gd_296, 2), TextColor2, gi_652, gi_648 - 1, 35);
   switch (li_4) {
   case 1:
      f0_36("Maximum Lot size exeeded!");
      break;
   case -1:
      f0_36("Minimum Lot size exeeded!");
   }
   if (gi_340) f0_36("Recovery Mode is Active!");
   f0_36("Spread:");
   f0_36(StringConcatenate(DoubleToStr(g_spread_276 / gd_288, 1), " (", g_spread_276, " pips)"), TextColor2, gi_652, gi_648 - 1, 56);
   f0_36("Leverage:");
   f0_36(AccountLeverage() + ":1", TextColor2, gi_652, gi_648 - 1, 70);
   if (AccountLeverage() < 100) {
      f0_36("Warning:");
      f0_36("Your account leverage is lower than 1:100,", TextColor2, gi_652, gi_648 - 1, 63);
      f0_36("the lot size will be reduced to prevent a loss.", TextColor2, gi_652, gi_648, 70);
   }
   if (gi_1128 != gi_692) {
      if (gi_692) Print("Not enough money! Available margin = ", DoubleToStr(AccountFreeMargin(), 2), ", Required margin = ", DoubleToStr(ld_8, 2));
      gi_1128 = gi_692;
   }
   if (gi_692) {
      f0_34();
      f0_36("Not enough money!");
      f0_36("Available margin =");
      f0_36(DoubleToStr(AccountFreeMargin(), 2), TextColor2, gi_652, gi_648 - 1, 133);
      f0_36("Required margin =");
      f0_36(DoubleToStr(ld_8, 2), TextColor2, gi_652, gi_648 - 1, 126);
   }
   f0_34();
   if (IsTesting()) f0_36("Backtesting");
   else {
      GetStatus(gi_328, g_spread_276, gd_296, gd_344, AccountBalance());
      gd_344 = 0;
   }
   if (gi_236 && gi_512) {
      if (gi_908 == 0) f0_36("Analyzing market");
      else f0_36(f0_37(gi_908) + " detected");
      if (g_datetime_256 <= gi_916 && gi_908 != gi_912 && gi_912 != 0) f0_36(f0_37(gi_912) + " fading: " + TimeToStr(gi_916 - g_datetime_256, TIME_SECONDS));
   } else f0_36(f0_2(gi_696 || gi_700, "Running", "Collecting Data"));
   if (NFA && g_count_708 > 0) {
      f0_34();
      f0_36("Waiting for trades to close:");
      f0_36(g_count_708, TextColor2, gi_652, gi_648 - 1, 203);
   }
   if (g_ticket_712 >= 0 || g_ticket_716 >= 0 || g_ticket_736 >= 0 || g_ticket_740 >= 0) {
      f0_34();
      if (g_ticket_712 >= 0) f0_36("Strategy1: Long position open");
      if (g_ticket_716 >= 0) f0_36("Strategy1: Short position open");
      if (g_ticket_736 >= 0) f0_36("Strategy2: Long position open");
      if (g_ticket_740 >= 0) f0_36("Strategy2: Short position open");
   }
   str_len_16 = StringLen(gs_384);
   str_len_20 = StringLen(gs_392);
   if (str_len_16 > 1 || str_len_20 > 0) f0_34();
   if (str_len_16 > 1) f0_36(gs_384);
   if (str_len_20 > 0) f0_43(gs_392, TextColor2, gi_652, gi_648 - 1, 7 * (str_len_16 + 1));
   f0_47(gi_652, gi_656);
   gi_656 = gi_652 - 1;
   ObjectsRedraw();
   LinksEnd(gi_328);
   return (0);
}