//+------------------------------------------------------------------+
//|                                                      Gognoos.mq4 |
//|                                              Copyright 2022, VS. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, VS."
#property version   "1.00"

//------------------------
extern bool ContinueTrade = TRUE;
extern string Hint_Break = "If Filled 10 Ea Stop After Take 10 times";
extern int Rest = 100;
extern string __OperatingHours__ = "If True, Ea Will Activate As Scheduled";
extern bool CutLoss = FALSE;
extern bool Marti = TRUE;
extern double LotExponent = 1.6;
extern string __Compound__ = "If True, EA Automatically Changes Its Lots";
extern bool Compound = FALSE;
extern double Divider = 10000.0;
extern double Lots = 0.01;
extern double LotsDigits = 2.0;
extern double TakePropit = 4.0;
extern double StopLoss = 0.0;
extern double PipsStep = 3.0;
extern int MaxTrades = 20;
extern string __Trailling__ = "If True, EA Automatically Locks the StopLoss";
extern bool Use_Trailing = FALSE;
extern double LockProfit = 7.0;
extern double TrailingStop = 5.0;
extern bool UseEquityStop = FALSE;
extern double TotalEquityRisk = 20.0;
extern string __Daily_Target__ = "If it is true, the accumulation is filled with capital+target";
extern bool Target = FALSE;
extern double Accumulation = 100.0;
extern bool CloseAll = FALSE;
extern int magic = 1148;
extern string Comment = "ffff";


int Gi_324 = 1;
double G_slippage_192 = 5.0;
int Gi_108;
int Gi_unused_144 = 65280;
int G_color_148 = Blue;
int G_color_152 = White;
double Gd_344 = 0.0;
bool Gi_352 = FALSE;
double G_price_356;
double Gd_364;
double Gd_unused_372;
double Gd_unused_380;
double G_price_388;
double G_bid_396;
double G_ask_404;
double Gd_412;
double Gd_420;
double Gd_428;
bool Gi_436;
int Gi_440 = 0;
int Gi_444;
int Gi_448 = 0;
double Gd_452;
int G_pos_460 = 0;
int Gi_464;
double Gd_468 = 0.0;
bool Gi_476 = FALSE;
bool Gi_480 = FALSE;
bool Gi_484 = FALSE;
int Gi_488;
bool Gi_492 = FALSE;
int G_datetime_496 = 0;
int G_datetime_500 = 0;
double Gd_504;
double Gd_512;
double Gd_520;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   if(Digits == 3 || Digits == 5)
      Gd_520 = 10.0 * Point;
   else
      Gd_520 = Point;
   Gd_428 = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   return (0);
  }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll();
   return (0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double order_lots_0;
   double order_lots_8;
   double iclose_16;
   double iclose_24;
   string text_44;
   string text_52;
   if(Compound)
      Lots = AccountBalance() / Divider;

   Gd_428 = MarketInfo(Symbol(), MODE_SPREAD) * Gd_520;


   if(Target)
     {
      if(AccountEquity() > Accumulation)
        {
         f0_4();
         text_52 = "STOP!!! Target Has Been Achieved";
         ObjectCreate("Target", OBJ_LABEL, 0, 0, 1.0);
         ObjectSet("Target", OBJPROP_CORNER, 2);
         ObjectSet("Target", OBJPROP_XDISTANCE, 220);
         ObjectSet("Target", OBJPROP_YDISTANCE, 10);
         ObjectSetText("Target", text_52, 40, "Times New Roman", Red);
         return (0);
        }
     }

   string Ls_68 = "false";
   string Ls_76 = "false";
   if(Gi_352 == FALSE || Gi_352)
      Ls_68 = "true";
   if(Gi_352)
      Ls_76 = "true";
   if(Use_Trailing)
      f0_17(LockProfit, TrailingStop, G_price_388);
   if(CloseAll)
     {
      if(TimeCurrent() >= Gi_444)
        {
         f0_4();
         Print("Time_run_out");
        }
     }
   if(Gi_440 == Time[0])
      return (0);
   Gi_440 = Time[0];
   double Ld_84 = f0_6();
   if(UseEquityStop)
     {
      if(Ld_84 < 0.0 && MathAbs(Ld_84) > TotalEquityRisk / 100.0 * f0_8())
        {
         f0_4();
         Print("Done");
         Gi_492 = FALSE;
        }
     }
   Gi_464 = f0_14();
   if(Gi_464 == 0)
      Gi_436 = FALSE;
   for(G_pos_460 = OrdersTotal() - 1; G_pos_460 >= 0; G_pos_460--)
     {
      if(!OrderSelect(G_pos_460, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
        {
         if(OrderType() == OP_BUY)
           {
            Gi_480 = TRUE;
            Gi_484 = FALSE;
            order_lots_0 = OrderLots();
            break;
           }
        }
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
        {
         if(OrderType() == OP_SELL)
           {
            Gi_480 = FALSE;
            Gi_484 = TRUE;
            order_lots_8 = OrderLots();
            break;
           }
        }
     }
   if(Gi_464 > 0 && Gi_464 <= MaxTrades)
     {
      RefreshRates();
      Gd_412 = f0_3();
      Gd_420 = f0_7();
      if(Gi_480 && Gd_412 - Ask >= PipsStep * Gd_520)
         Gi_476 = TRUE;
      if(Gi_484 && Bid - Gd_420 >= PipsStep * Gd_520)
         Gi_476 = TRUE;
     }
   if(Gi_464 < 1)
     {
      Gi_484 = FALSE;
      Gi_480 = FALSE;
      Gi_476 = TRUE;
      Gd_364 = AccountEquity();
     }
   if(Gi_476)
     {
      Gd_412 = f0_3();
      Gd_420 = f0_7();
      if(Gi_484)
        {
         if(CutLoss || Ls_76 == "true")
           {
            f0_2(0);
            Gd_452 = NormalizeDouble(LotExponent * order_lots_8, LotsDigits);
           }
         else
            Gd_452 = f0_12(OP_SELL);
         if(Marti && Ls_68 == "true")
           {
            Gi_448 = Gi_464;
            if(Gd_452 > 0.0)
              {
               RefreshRates();
               Gi_488 = f0_13(1, Gd_452, Bid, G_slippage_192, Ask, 0, 0, Comment + "-" + Gi_448, magic, 0, CLR_NONE);
               if(Gi_488 < 0)
                 {
                  Print("Error: ", GetLastError());
                  return (0);
                 }
               Gd_420 = f0_7();
               Gi_476 = FALSE;
               Gi_492 = TRUE;
              }
           }
        }
      else
        {
         if(Gi_480)
           {
            if(CutLoss || Ls_76 == "true")
              {
               f0_2(1);
               Gd_452 = NormalizeDouble(LotExponent * order_lots_0, LotsDigits);
              }
            else
               Gd_452 = f0_12(OP_BUY);
            if(Marti && Ls_68 == "true")
              {
               Gi_448 = Gi_464;
               if(Gd_452 > 0.0)
                 {
                  Gi_488 = f0_13(0, Gd_452, Ask, G_slippage_192, Bid, 0, 0, Comment + "-" + Gi_448, magic, 0, CLR_NONE);
                  if(Gi_488 < 0)
                    {
                     Print("Error: ", GetLastError());
                     return (0);
                    }
                  Gd_412 = f0_3();
                  Gi_476 = FALSE;
                  Gi_492 = TRUE;
                 }
              }
           }
        }
     }
   if(Gi_108 < Rest && ContinueTrade)
     {
      if(Gi_476 && Gi_464 < 1)
        {
         iclose_16 = iClose(Symbol(), 0, 2);
         iclose_24 = iClose(Symbol(), 0, 1);
         G_bid_396 = Bid;
         G_ask_404 = Ask;
         if((!Gi_484) && !Gi_480 && Ls_68 == "true")
           {
            Gi_448 = Gi_464;
            if(iclose_16 > iclose_24)
              {
               Gd_452 = f0_12(OP_SELL);
               if(Gd_452 > 0.0)
                 {
                  Gi_488 = f0_13(1, Gd_452, G_bid_396, G_slippage_192, G_bid_396, 0, 0, Comment + "-" + Gi_448, magic, 0, CLR_NONE);
                  Gi_108++;
                  if(Gi_488 < 0)
                    {
                     Print(Gd_452, "Error: ", GetLastError());
                     return (0);
                    }
                  Gd_412 = f0_3();
                  Gi_492 = TRUE;
                 }
              }
            else
              {
               Gd_452 = f0_12(OP_BUY);
               if(Gd_452 > 0.0)
                 {
                  Gi_488 = f0_13(0, Gd_452, G_ask_404, G_slippage_192, G_ask_404, 0, 0, Comment + "-" + Gi_448, magic, 0, CLR_NONE);
                  Gi_108++;
                  if(Gi_488 < 0)
                    {
                     Print(Gd_452, "Error: ", GetLastError());
                     return (0);
                    }
                  Gd_420 = f0_7();
                  Gi_492 = TRUE;
                 }
              }
           }
        }
      if(Gi_488 > 0)
         Gi_444 = TimeCurrent() + 60.0 * (60.0 * Gd_344);
      Gi_476 = FALSE;
     }
   Gi_464 = f0_14();
   G_price_388 = 0;
   double Ld_92 = 0;
   for(G_pos_460 = OrdersTotal() - 1; G_pos_460 >= 0; G_pos_460--)
     {
      if(!OrderSelect(G_pos_460, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
        {
         if(OrderType() == OP_BUY || OrderType() == OP_SELL)
           {
            G_price_388 += OrderOpenPrice() * OrderLots();
            Ld_92 += OrderLots();
           }
        }
     }
   if(Gi_464 > 0)
      G_price_388 = NormalizeDouble(G_price_388 / Ld_92, Digits);
   if(Gi_492)
     {
      for(G_pos_460 = OrdersTotal() - 1; G_pos_460 >= 0; G_pos_460--)
        {
         if(!OrderSelect(G_pos_460, SELECT_BY_POS, MODE_TRADES))
            continue;
         if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
            continue;
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
           {
            if(OrderType() == OP_BUY)
              {
               G_price_356 = G_price_388 + TakePropit * Gd_520;
               Gd_unused_372 = G_price_356;
               Gd_468 = G_price_388 - StopLoss * Gd_520;
               Gi_436 = TRUE;
              }
           }
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
           {
            if(OrderType() == OP_SELL)
              {
               G_price_356 = G_price_388 - TakePropit * Gd_520;
               Gd_unused_380 = G_price_356;
               Gd_468 = G_price_388 + StopLoss * Gd_520;
               Gi_436 = TRUE;
              }
           }
        }
     }
   if(Gi_492)
     {
      if(Gi_436 == TRUE)
        {
         for(G_pos_460 = OrdersTotal() - 1; G_pos_460 >= 0; G_pos_460--)
           {
            if(!OrderSelect(G_pos_460, SELECT_BY_POS, MODE_TRADES))
               continue;
            if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
               continue;
            if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
               if(OrderModify(OrderTicket(), G_price_388, OrderStopLoss(), G_price_356, 0, White))
                  continue;
            Gi_492 = FALSE;
           }
        }
     }
   return (0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_10(double Ad_0)
  {
   return (NormalizeDouble(Ad_0, Digits));
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int f0_2(int Ai_4)
  {
   Ai_4 = 0;
   for(int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--)
     {
      if(OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
           {
            if(OrderType() == OP_BUY)
              {
               RefreshRates();
               if(!IsTradeContextBusy())
                 {
                  if(!OrderClose(OrderTicket(), OrderLots(), f0_10(Bid), 5, CLR_NONE))
                    {
                     Print("Error Close BUY " + OrderTicket());
                     Ai_4 = -1;
                    }
                 }
               else
                 {
                  if(G_datetime_496 == iTime(NULL, 0, 0))
                     return (-2);
                  G_datetime_496 = iTime(NULL, 0, 0);
                  Print("Must Close BUY " + OrderTicket() + ". Busy Trade Context");
                  return (-2);
                 }
              }
            if(OrderType() == OP_SELL)
              {
               RefreshRates();
               if(!IsTradeContextBusy())
                 {
                  if(!(!OrderClose(OrderTicket(), OrderLots(), f0_10(Ask), 5, CLR_NONE)))
                     continue;
                  Print("Error Close SELL " + OrderTicket());
                  Ai_4 = -1;
                  continue;
                 }
               if(G_datetime_500 == iTime(NULL, 0, 0))
                  return (-2);
               G_datetime_500 = iTime(NULL, 0, 0);
               Print("Must Close SELL " + OrderTicket() + ". Busy Trade Context");
               return (-2);
              }
           }
        }
     }
   return (Ai_4);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_12(int A_cmd_0)
  {
   double lots_4;
   int datetime_12;
   switch(Gi_324)
     {
      case 0:
         lots_4 = Lots;
         break;
      case 1:
         lots_4 = NormalizeDouble(Lots * MathPow(LotExponent, Gi_448), LotsDigits);
         break;
      case 2:
         datetime_12 = 0;
         lots_4 = Lots;
         for(int pos_20 = OrdersHistoryTotal() - 1; pos_20 >= 0; pos_20--)
           {
            if(OrderSelect(pos_20, SELECT_BY_POS, MODE_HISTORY))
              {
               if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
                 {
                  if(datetime_12 < OrderCloseTime())
                    {
                     datetime_12 = OrderCloseTime();
                     if(OrderProfit() < 0.0)
                       {
                        lots_4 = NormalizeDouble(OrderLots() * LotExponent, LotsDigits);
                        continue;
                       }
                     lots_4 = Lots;
                    }
                 }
              }
            else
               return (-3);
           }
     }
   if(AccountFreeMarginCheck(Symbol(), A_cmd_0, lots_4) <= 0.0)
      return (-1);
   if(GetLastError() == 134/* NOT_ENOUGH_MONEY */)
      return (-2);
   return (lots_4);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int f0_14()
  {
   int count_0 = 0;
   for(int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--)
     {
      if(!OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
         if(OrderType() == OP_SELL || OrderType() == OP_BUY)
            count_0++;
     }
   return (count_0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void f0_4()
  {
   for(int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--)
     {
      if(!OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() == Symbol())
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
           {
            if(OrderType() == OP_BUY)
               if(OrderClose(OrderTicket(), OrderLots(), Bid, G_slippage_192, Blue))
                  continue;
            if(OrderType() == OP_SELL)
               if(OrderClose(OrderTicket(), OrderLots(), Ask, G_slippage_192, Gold))
                  continue;
           }
         Sleep(1000);
        }
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int f0_13(int Ai_0, double A_lots_4, double A_price_12, int A_slippage_20, double Ad_24, int Ai_unused_32, int Ai_36, string A_comment_40, int A_magic_48, int A_datetime_52, color A_color_56)
  {
   int ticket_60 = 0;
   int error_64 = 0;
   int count_68 = 0;
   int Li_72 = 100;
   switch(Ai_0)
     {
      case 2:
         for(count_68 = 0; count_68 < Li_72; count_68++)
           {
            ticket_60 = OrderSend(Symbol(), OP_BUYLIMIT, A_lots_4, A_price_12, A_slippage_20, f0_11(Ad_24, StopLoss), f0_15(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
                                  A_color_56);
            error_64 = GetLastError();
            if(error_64 == 0/* NO_ERROR */)
               break;
            if(!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */)))
               break;
            Sleep(1000);
           }
         break;
      case 4:
         for(count_68 = 0; count_68 < Li_72; count_68++)
           {
            ticket_60 = OrderSend(Symbol(), OP_BUYSTOP, A_lots_4, A_price_12, A_slippage_20, f0_11(Ad_24, StopLoss), f0_15(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
                                  A_color_56);
            error_64 = GetLastError();
            if(error_64 == 0/* NO_ERROR */)
               break;
            if(!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */)))
               break;
            Sleep(5000);
           }
         break;
      case 0:
         for(count_68 = 0; count_68 < Li_72; count_68++)
           {
            RefreshRates();
            ticket_60 = OrderSend(Symbol(), OP_BUY, A_lots_4, Ask, A_slippage_20, f0_11(Bid, StopLoss), f0_15(Ask, Ai_36), A_comment_40, A_magic_48, A_datetime_52, A_color_56);
            error_64 = GetLastError();
            if(error_64 == 0/* NO_ERROR */)
               break;
            if(!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */)))
               break;
            Sleep(5000);
           }
         break;
      case 3:
         for(count_68 = 0; count_68 < Li_72; count_68++)
           {
            ticket_60 = OrderSend(Symbol(), OP_SELLLIMIT, A_lots_4, A_price_12, A_slippage_20, f0_0(Ad_24, StopLoss), f0_5(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
                                  A_color_56);
            error_64 = GetLastError();
            if(error_64 == 0/* NO_ERROR */)
               break;
            if(!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */)))
               break;
            Sleep(5000);
           }
         break;
      case 5:
         for(count_68 = 0; count_68 < Li_72; count_68++)
           {
            ticket_60 = OrderSend(Symbol(), OP_SELLSTOP, A_lots_4, A_price_12, A_slippage_20, f0_0(Ad_24, StopLoss), f0_5(A_price_12, Ai_36), A_comment_40, A_magic_48, A_datetime_52,
                                  A_color_56);
            error_64 = GetLastError();
            if(error_64 == 0/* NO_ERROR */)
               break;
            if(!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */)))
               break;
            Sleep(5000);
           }
         break;
      case 1:
         for(count_68 = 0; count_68 < Li_72; count_68++)
           {
            ticket_60 = OrderSend(Symbol(), OP_SELL, A_lots_4, Bid, A_slippage_20, f0_0(Ask, StopLoss), f0_5(Bid, Ai_36), A_comment_40, A_magic_48, A_datetime_52, A_color_56);
            error_64 = GetLastError();
            if(error_64 == 0/* NO_ERROR */)
               break;
            if(!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */)))
               break;
            Sleep(5000);
           }
     }
   return (ticket_60);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_11(double Ad_0, int Ai_8)
  {
   if(Ai_8 == 0)
      return (0);
   return (Ad_0 - Ai_8 * Gd_520);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_0(double Ad_0, int Ai_8)
  {
   if(Ai_8 == 0)
      return (0);
   return (Ad_0 + Ai_8 * Gd_520);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_15(double Ad_0, int Ai_8)
  {
   if(Ai_8 == 0)
      return (0);
   return (Ad_0 + Ai_8 * Gd_520);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_5(double Ad_0, int Ai_8)
  {
   if(Ai_8 == 0)
      return (0);
   return (Ad_0 - Ai_8 * Gd_520);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_6()
  {
   double Ld_ret_0 = 0;
   for(G_pos_460 = OrdersTotal() - 1; G_pos_460 >= 0; G_pos_460--)
     {
      if(!OrderSelect(G_pos_460, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic)
         if(OrderType() == OP_BUY || OrderType() == OP_SELL)
            Ld_ret_0 += OrderProfit();
     }
   return (Ld_ret_0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void f0_17(int Ai_0, int Ai_4, double A_price_8)
  {
   int Li_16;
   double order_stoploss_20;
   double price_28;
   if(Ai_4 != 0)
     {
      for(int pos_36 = OrdersTotal() - 1; pos_36 >= 0; pos_36--)
        {
         if(OrderSelect(pos_36, SELECT_BY_POS, MODE_TRADES))
           {
            if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
               continue;
            if(OrderSymbol() == Symbol() || OrderMagicNumber() == magic)
              {
               if(OrderType() == OP_BUY)
                 {
                  Li_16 = NormalizeDouble((Bid - A_price_8) / Gd_520, 0);
                  if(Li_16 < Ai_0)
                     continue;
                  order_stoploss_20 = OrderStopLoss();
                  price_28 = Bid - Ai_4 * Gd_520;
                  if(order_stoploss_20 == 0.0 || (order_stoploss_20 != 0.0 && price_28 > order_stoploss_20))
                     if(OrderModify(OrderTicket(), A_price_8, price_28, OrderTakeProfit(), 0, White))
                        continue;
                 }
               if(OrderType() == OP_SELL)
                 {
                  Li_16 = NormalizeDouble((A_price_8 - Ask) / Gd_520, 0);
                  if(Li_16 < Ai_0)
                     continue;
                  order_stoploss_20 = OrderStopLoss();
                  price_28 = Ask + Ai_4 * Gd_520;
                  if(order_stoploss_20 == 0.0 || (order_stoploss_20 != 0.0 && price_28 < order_stoploss_20))
                     if(OrderModify(OrderTicket(), A_price_8, price_28, OrderTakeProfit(), 0, Blue))
                        continue;
                 }
              }
            Sleep(1000);
           }
        }
     }
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_8()
  {
   if(f0_14() == 0)
      Gd_504 = AccountEquity();
   if(Gd_504 < Gd_512)
      Gd_504 = Gd_512;
   else
      Gd_504 = AccountEquity();
   Gd_512 = AccountEquity();
   return (Gd_504);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_3()
  {
   double order_open_price_0;
   int ticket_8;
   double Ld_unused_12 = 0;
   int ticket_20 = 0;
   for(int pos_24 = OrdersTotal() - 1; pos_24 >= 0; pos_24--)
     {
      if(!OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_BUY)
        {
         ticket_8 = OrderTicket();
         if(ticket_8 > ticket_20)
           {
            order_open_price_0 = OrderOpenPrice();
            Ld_unused_12 = order_open_price_0;
            ticket_20 = ticket_8;
           }
        }
     }
   return (order_open_price_0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double f0_7()
  {
   double order_open_price_0;
   int ticket_8;
   double Ld_unused_12 = 0;
   int ticket_20 = 0;
   for(int pos_24 = OrdersTotal() - 1; pos_24 >= 0; pos_24--)
     {
      if(!OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES))
         continue;
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != magic)
         continue;
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == magic && OrderType() == OP_SELL)
        {
         ticket_8 = OrderTicket();
         if(ticket_8 > ticket_20)
           {
            order_open_price_0 = OrderOpenPrice();
            Ld_unused_12 = order_open_price_0;
            ticket_20 = ticket_8;
           }
        }
     }
   return (order_open_price_0);
  }



//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void f0_1(int Ai_0, string As_4, string As_12)
  {
   int Li_20;
   int Li_24;
   if((!IsTradeAllowed()) || !IsExpertEnabled())
     {
      ObjectDelete("baris0");
      return;
     }
   switch(Ai_0)
     {
      case 3:
         Li_20 = 100;
         Li_24 = 85;
         break;
      case 4:
         Li_20 = 100;
         Li_24 = 100;
         break;
      case 5:
         Li_20 = 100;
         Li_24 = 115;
         break;
      case 6:
         Li_20 = 100;
         Li_24 = 130;
         break;
      case 7:
         Li_20 = 100;
         Li_24 = 145;
         break;
      case 8:
         Li_20 = 100;
         Li_24 = 160;
         break;
      case 9:
         Li_20 = 100;
         Li_24 = 175;
         break;
      case 10:
         Li_20 = 100;
         Li_24 = 190;
         break;
      case 11:
         Li_20 = 100;
         Li_24 = 205;
         break;
      case 14:
         Li_20 = 100;
         Li_24 = 220;
         break;
      case 15:
         Li_20 = 100;
         Li_24 = 235;
         break;
      case 16:
         Li_20 = 100;
         Li_24 = 215;
         break;
      case 17:
         Li_20 = 100;
         Li_24 = 225;
         break;
      case 18:
         Li_20 = 100;
         Li_24 = 235;
         break;
      case 19:
         Li_20 = 100;
         Li_24 = 245;
         break;
      case 20:
         Li_20 = 100;
         Li_24 = 255;
         break;
      case 21:
         Li_20 = 100;
         Li_24 = 265;
         break;
      case 22:
         Li_20 = 100;
         Li_24 = 280;
     }

  }


//+------------------------------------------------------------------+
