//+------------------------------------------------------------------+
//|                                                  avtoforex11.mq4 |
//|                                                  Aleksandr Комар |
//|                                           http://www.akgnozis.ru |
//+------------------------------------------------------------------+
#property copyright "Aleksandr Комар"
#property link      "http://www.akgnozis.ru"

extern string separator0 = "Торговать по рынку или отложенными лимит ордерами";
extern bool TradeByMarketOrders = FALSE;
extern string separator1 = "Алгоритм закрытия позиций IR или WQ";
extern bool IR_ili_WQ = TRUE;
extern string separator2 = "Ждать ли закрытия бара перед началом торгов";
extern bool NeedWaitNewBar = FALSE;
extern string separator3 = "Меджик номер ордера";
extern int MAGIC = 123456;
extern string separator4 = "Общие параметры советника если NeedDiffParameters=true";
extern string separator5 = "То параметры беруться из настроек для каждого ордера";
extern bool NeedDiffParameters = FALSE;
extern double Lots = 0.01;
extern int MaxTrades = 10;
extern int Pips = 10;
extern double Doble = 2.0;
extern int TakeProfit1 = 60;
extern int InitialStop1 = 0;
extern int TrailingStop1 = 50;
extern int Revers = 0;
extern string separator6 = "Профит по всем позициям в валюте депозита закрываемый советником";
extern int ProfitIndex = 10;
extern string separator7 = "Кол-во закрываемых позиций по ProfitIndex";
extern string separator8 = "Если ABG_Algoritm=MaxTrades то вся пачка будет закрываться по ProfitIndex ";
extern int ABG_Algoritm = 10;
extern string separator9 = "Если Doble2-10=0 то размер позиции по ордерам выставляется в ручную";
extern string separator10 = "Настроек всего 10, 11 и последующие ордера выставляються с параметрами 10";
extern string separator11 = "Параметры ордера 2";
extern int Pips2 = 10;
extern double Lots2 = 0.01;
extern double Doble2 = 2.0;
extern int TakeProfit2 = 40;
extern int InitialStop2 = 0;
extern int TrailingStop2 = 30;
extern string separator12 = "Параметры ордера 3";
extern int Pips3 = 10;
extern double Lots3 = 0.01;
extern double Doble3 = 2.0;
extern int TakeProfit3 = 40;
extern int InitialStop3 = 0;
extern int TrailingStop3 = 30;
extern string separator13 = "Параметры ордера 4";
extern int Pips4 = 10;
extern double Lots4 = 0.01;
extern double Doble4 = 2.0;
extern int TakeProfit4 = 40;
extern int InitialStop4 = 0;
extern int TrailingStop4 = 30;
extern string separator14 = "Параметры ордера 5";
extern int Pips5 = 10;
extern double Lots5 = 0.01;
extern double Doble5 = 2.0;
extern int TakeProfit5 = 40;
extern int InitialStop5 = 0;
extern int TrailingStop5 = 30;
extern string separator15 = "Параметры ордера 6";
extern int Pips6 = 10;
extern double Lots6 = 0.01;
extern double Doble6 = 2.0;
extern int TakeProfit6 = 40;
extern int InitialStop6 = 0;
extern int TrailingStop6 = 30;
extern string separator16 = "Параметры ордера 7";
extern int Pips7 = 10;
extern double Lots7 = 0.01;
extern double Doble7 = 2.0;
extern int TakeProfit7 = 20;
extern int InitialStop7 = 0;
extern int TrailingStop7 = 30;
extern string separator17 = "Параметры ордера 8";
extern int Pips8 = 10;
extern double Lots8 = 0.01;
extern double Doble8 = 2.0;
extern int TakeProfit8 = 40;
extern int InitialStop8 = 0;
extern int TrailingStop8 = 30;
extern string separato18 = "Параметры ордера 9";
extern int Pips9 = 10;
extern double Lots9 = 0.01;
extern double Doble9 = 2.0;
extern int TakeProfit9 = 20;
extern int InitialStop9 = 0;
extern int TrailingStop9 = 30;
extern string separator19 = "Параметры ордера 10";
extern int Pips10 = 10;
extern double Lots10 = 0.01;
extern double Doble10 = 2.0;
extern int TakeProfit10 = 20;
extern int InitialStop10 = 0;
extern int TrailingStop10 = 30;
extern string separator20 = "Выбор индикатора для анализа рынка";
extern string separator21 = "0=MACD2,1=OSMA,2=AO,3=AC,4=DigitalMACD,5=ZeroLag MACD";
extern string separator22 = "6=5_34_5,7=ElliottWaveOscillator,8=Ergodic,9=MACD";
extern string separator23 = "10=CoeffoLine_Hist,11=AO_Adaptive,12=FiboFan";
extern string separator24 = "13=OSMA недельный график,14=MAMA_NK,15=MAMAXX_NK 16=NDuet";
extern string separator25 = "17=MACDonRSI 18=Комбинация OsMA,ZeroLagMACD,MACD 19=Svs_trend";
extern int AnaliseIndicator = 0;
extern string separator26 = "Параметры индикатора AO_Adaptive";
extern int PriceMA1 = 5;
extern int MinPeriod1 = 5;
extern int MaxPeriod1 = 10;
extern int LevelStdDevPoint1 = 8;
extern int Smooth1 = 1;
extern int PriceMA2 = 5;
extern int MinPeriod2 = 34;
extern int MaxPeriod2 = 68;
extern int LevelStdDevPoint2 = 8;
extern int Smooth2 = 1;
extern string separator27 = "Параметры индикатора CoeffoLine_Hist";
extern int ndot = 30;
extern string separator28 = "Параметры индикатора Ergodic";
extern int r = 2;
extern int s = 5;
extern int u = 8;
extern int smooth = 2;
extern string separator29 = "Параметры индикатора MACD";
extern int FastEMAMACD = 12;
extern int SlowEMAMACD = 26;
extern string separator30 = "Параметры индикатора OSMA,";
extern int FastEMAOSMA = 12;
extern int SlowEMAOSMA = 26;
extern int SignalSMAOSMA = 9;
extern string separator31 = "Параметры индикатора ZeroLagMACD,";
extern int FastEMAZeroLagMACD = 12;
extern int SlowEMAZeroLagMACD = 26;
extern string separator32 = "Параметры индикатора #MACD";
extern int FastEMAMACD2 = 9;
extern int SlowEMAMACD2 = 64;
extern int SignalEMAMACD2 = 112;
extern string separator33 = "Параметры индикатора FiboFan";
extern int Period_Q = 24;
extern int Period_R = 12;
extern int Period_S = 6;
extern string separator34 = "Параметры индикатора MAMA_NK и MAMAXX_NK";
extern double FastLimit = 0.5;
extern double SlowLimit = 0.05;
extern int IPC = 4;
extern string separator35 = "Параметры индикатора NDuet";
extern int sper = 55;
extern int fper = 21;
extern string separator36 = "Параметры индикатора MACDonRSI";
extern int MA = 5;
extern int RSIperiod = 3;
extern int FastEMAMACDonRSI = 10;
extern int SlowEMAMACDonRSI = 20;
extern int SignalSMAMACDonRSI = 5;
extern string separator37 = "Параметры индикатора Svs_trend";
extern int Period1 = 4;
extern int Period2 = 8;
extern string separator38 = "Параметры индикатора Stochastic";
extern double Kperiod = 8.0;
extern double Dperiod = 3.0;
extern double Slowing = 4.0;
int gi_940 = 1;
int gi_944 = 0;
int g_slippage_948 = 3;
int gi_952 = 2;
int g_count_956;
int g_pos_960;
int gi_968;
int gi_972;
int gi_976;
int g_magic_980;
int g_magic_984;
int gi_988;
int gi_992;
int gi_996;
int gi_1000;
double g_price_1012;
double g_price_1020;
double g_maxlot_1028;
double g_minlot_1036;
double g_lotstep_1044;
double g_price_1052;
double g_price_1060;
double gd_1068;
double g_lots_1076;
double g_ord_open_price_1084;
double g_ord_lots_1092;
double gd_1100;
double gd_1108;
double gd_1116;
double g_tickvalue_1132;
bool gi_1140 = TRUE;
bool gi_1144;
bool gi_1148;
string gs_1152;
datetime g_time_1160;

int init() {
   g_maxlot_1028 = MarketInfo(Symbol(), MODE_MAXLOT);
   g_minlot_1036 = MarketInfo(Symbol(), MODE_MINLOT);
   g_lotstep_1044 = MarketInfo(Symbol(), MODE_LOTSTEP);
   g_time_1160 = Time[0];
   g_magic_980 = 10 * MAGIC;
   g_tickvalue_1132 = MarketInfo(Symbol(), MODE_TICKVALUE);
   return (0);
}

int start() {
   int l_ticket_0;
   if (!IsTesting()) {
      if (!IsExpertEnabled()) {
         Comment("В торговом терминале запрещён запуск экспертов.");
         return (0);
      }
      if (!IsTradeAllowed()) {
         Comment("Торговля советниками запрещена или торговый поток занят.");
         return (0);
      }
   }
   if (AccountNumber() != 10052) return (0);
   if (NeedWaitNewBar && Time[0] == g_time_1160) return (0);
   if (gi_944 != 0) gd_1068 = AccountFreeMargin() / 1000.0 * (gi_952 / 100.0);
   else gd_1068 = Lots;
   if (gd_1068 < g_minlot_1036) gd_1068 = g_minlot_1036;
   else {
      if (gd_1068 > g_maxlot_1028) gd_1068 = g_maxlot_1028;
      else gd_1068 = NormalizeDouble(gd_1068 / g_lotstep_1044, 0) * g_lotstep_1044;
   }
   gi_976 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   gd_1116 = 0;
   gi_1144 = FALSE;
   g_count_956 = 0;
   for (g_pos_960 = 0; g_pos_960 < OrdersTotal(); g_pos_960++) {
      OrderSelect(g_pos_960, SELECT_BY_POS);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_980 || OrderMagicNumber() > g_magic_980 + 9) continue;
      if (OrderType() > OP_SELL) gi_1144 = TRUE;
      else {
         l_ticket_0 = OrderTicket();
         g_count_956++;
         InitParam(OrderMagicNumber());
         if (OrderType() == OP_BUY) {
            gd_1116 += (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point;
            if (OrderTakeProfit() == 0.0 && OrderStopLoss() == 0.0 && gi_988 != 0 || gi_992 != 0) {
               if (gi_988 == 0) g_price_1020 = 0;
               else {
                  if (OrderTakeProfit() == 0.0) g_price_1020 = NormalizeDouble(OrderOpenPrice() + gi_988 * Point, Digits);
                  else g_price_1020 = NormalizeDouble(OrderTakeProfit(), Digits);
               }
               if (gi_992 == 0) g_price_1012 = 0;
               else g_price_1012 = NormalizeDouble(OrderOpenPrice() - gi_992 * Point, Digits);
               OrderModify(OrderTicket(), OrderOpenPrice(), g_price_1012, g_price_1020, 0, CLR_NONE);
            }
         } else {
            if (OrderType() == OP_SELL) {
               gd_1116 += (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point;
               if (OrderTakeProfit() == 0.0 && OrderStopLoss() == 0.0 && gi_988 != 0 || gi_992 != 0) {
                  if (gi_988 == 0) g_price_1020 = 0;
                  else {
                     if (OrderTakeProfit() == 0.0) g_price_1020 = NormalizeDouble(OrderOpenPrice() - gi_988 * Point, Digits);
                     else g_price_1020 = NormalizeDouble(OrderTakeProfit(), Digits);
                  }
                  if (gi_992 == 0) g_price_1012 = 0;
                  else g_price_1012 = NormalizeDouble(OrderOpenPrice() + gi_992 * Point, Digits);
                  OrderModify(OrderTicket(), OrderOpenPrice(), g_price_1012, g_price_1020, 0, CLR_NONE);
               }
            }
         }
      }
   }
   gs_1152 = "Суммарный профит по ордерам в пунктах*лот =" + gd_1116;
   gd_1116 *= g_tickvalue_1132;
   gs_1152 = gs_1152 + ".\nСуммарный профит по ордерам = $" + gd_1116 
      + "\nОткрыто ордеров " + g_count_956 
      + "\nMaxTrades-ABG_Algoritm=" + ((MaxTrades - ABG_Algoritm)) 
   + "\nProfitIndex=" + ProfitIndex;
   Comment(gs_1152);
   if (gi_972 > g_count_956) {
      gi_1148 = FALSE;
      if (IR_ili_WQ) {
         for (g_pos_960 = OrdersTotal() - 1; g_pos_960 >= 0; g_pos_960--) {
            OrderSelect(g_pos_960, SELECT_BY_POS);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_980 || OrderMagicNumber() > g_magic_980 + 9) continue;
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_948, Blue);
            else {
               if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_948, Red);
               else OrderDelete(OrderTicket());
            }
            gi_1148 = TRUE;
         }
      } else {
         for (g_pos_960 = 0; g_pos_960 < OrdersTotal(); g_pos_960++) {
            OrderSelect(g_pos_960, SELECT_BY_POS);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_980 || OrderMagicNumber() > g_magic_980 + 9) continue;
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_948, Blue);
            else {
               if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_948, Red);
               else OrderDelete(OrderTicket());
            }
            gi_1148 = TRUE;
         }
      }
      if (gi_1148) return (0);
   }
   gi_972 = g_count_956;
   if (g_count_956 >= MaxTrades - ABG_Algoritm && gi_940 == 1) {
      if (gd_1116 >= ProfitIndex) {
         OrderSelect(l_ticket_0, SELECT_BY_TICKET);
         if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_948, Yellow);
         else {
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_948, Yellow);
            else gi_1140 = FALSE;
         }
         return (0);
      }
   }
   if (g_count_956 >= MaxTrades) gi_1140 = FALSE;
   else gi_1140 = TRUE;
   if (g_ord_open_price_1084 == 0.0) {
      g_ord_open_price_1084 = 0;
      for (g_pos_960 = 0; g_pos_960 < OrdersTotal(); g_pos_960++) {
         OrderSelect(g_pos_960, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_980 || OrderMagicNumber() > g_magic_980 + 9) continue;
         if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT) {
            gi_968 = 2;
            if (g_ord_open_price_1084 > OrderOpenPrice() || g_ord_open_price_1084 == 0.0) {
               g_ord_lots_1092 = OrderLots();
               g_ord_open_price_1084 = OrderOpenPrice();
            }
         } else {
            if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT) {
               gi_968 = 1;
               if (g_ord_open_price_1084 < OrderOpenPrice()) {
                  g_ord_lots_1092 = OrderLots();
                  g_ord_open_price_1084 = OrderOpenPrice();
               }
            }
         }
      }
   }
   if (g_count_956 == 0) {
      switch (AnaliseIndicator) {
      case 1:
         gi_968 = AnaliseIndicator1();
         break;
      case 2:
         gi_968 = AnaliseIndicator2();
         break;
      case 3:
         gi_968 = AnaliseIndicator3();
         break;
      case 4:
         gi_968 = AnaliseIndicator4();
         break;
      case 5:
         gi_968 = AnaliseIndicator5();
         break;
      case 6:
         gi_968 = AnaliseIndicator6();
         break;
      case 7:
         gi_968 = AnaliseIndicator7();
         break;
      case 8:
         gi_968 = AnaliseIndicator8();
         break;
      case 9:
         gi_968 = AnaliseIndicator9();
         break;
      case 10:
         gi_968 = AnaliseIndicator10();
         break;
      case 11:
         gi_968 = AnaliseIndicator11();
         break;
      case 12:
         gi_968 = AnaliseIndicator12();
         break;
      case 13:
         gi_968 = AnaliseIndicator13();
         break;
      case 14:
         gi_968 = AnaliseIndicator14();
         break;
      case 15:
         gi_968 = AnaliseIndicator15();
         break;
      case 16:
         gi_968 = AnaliseIndicator16();
         break;
      case 17:
         gi_968 = AnaliseIndicator17();
         break;
      case 18:
         gi_968 = AnaliseIndicator18();
         break;
      case 19:
         gi_968 = AnaliseIndicator19();
         break;
      case 20:
         gi_968 = AnaliseIndicator20();
         break;
      default:
         gi_968 = AnaliseIndicator0();
      }
      if (Revers == 1) {
         if (gi_968 == 1) gi_968 = 2;
         else
            if (gi_968 == 2) gi_968 = 1;
      }
   }
   if (IR_ili_WQ) {
      for (g_pos_960 = OrdersTotal() - 1; g_pos_960 >= 0; g_pos_960--) {
         OrderSelect(g_pos_960, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_980 || OrderMagicNumber() > g_magic_980 + 9 || OrderType() > OP_SELL) continue;
         InitParam(OrderMagicNumber());
         if (gi_996 != 0) {
            if (OrderType() == OP_SELL) {
               if (OrderOpenPrice() - Ask >= (gi_996 + gi_1000) * Point && NormalizeDouble(OrderStopLoss(), Digits) > NormalizeDouble(Ask + Point * gi_996, Digits) || OrderStopLoss() == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gi_996, Digits), OrderTakeProfit(), 0, Purple);
            } else {
               if (OrderType() == OP_BUY)
                  if (Bid - OrderOpenPrice() >= (gi_996 + gi_1000) * Point && NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(Bid - Point * gi_996, Digits)) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gi_996, Digits), OrderTakeProfit(), 0, Yellow);
            }
         }
      }
   } else {
      if (!IR_ili_WQ) {
         for (g_pos_960 = 0; g_pos_960 < OrdersTotal(); g_pos_960++) {
            OrderSelect(g_pos_960, SELECT_BY_POS);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_980 || OrderMagicNumber() > g_magic_980 + 9 || OrderType() > OP_SELL) continue;
            InitParam(OrderMagicNumber());
            if (gi_996 != 0) {
               if (OrderType() == OP_SELL) {
                  if (OrderOpenPrice() - Ask >= (gi_996 + gi_1000) * Point && NormalizeDouble(OrderStopLoss(), Digits) > NormalizeDouble(Ask + Point * gi_996, Digits) || OrderStopLoss() == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gi_996, Digits), OrderTakeProfit(), 0, Purple);
               } else {
                  if (OrderType() == OP_BUY)
                     if (Bid - OrderOpenPrice() >= (gi_996 + gi_1000) * Point && NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(Bid - Point * gi_996, Digits)) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gi_996, Digits), OrderTakeProfit(), 0, Yellow);
               }
            }
         }
      }
   }
   if (gi_968 == 1 && gi_1140) {
      if (g_count_956 == 0) {
         g_ord_open_price_1084 = 0;
         g_lots_1076 = gd_1068;
         if (g_lots_1076 < g_minlot_1036) g_lots_1076 = g_minlot_1036;
         else {
            if (g_lots_1076 > g_maxlot_1028) g_lots_1076 = g_maxlot_1028;
            else g_lots_1076 = NormalizeDouble(g_lots_1076 / g_lotstep_1044, 0) * g_lotstep_1044;
         }
         OrderSend(Symbol(), OP_SELL, g_lots_1076, Bid, g_slippage_948, 0, 0, "DTv.11.10 Universal" + MAGIC, g_magic_980, 0, Red);
         return (0);
      }
      if (!gi_1144) {
         InitParam(g_magic_980 + g_count_956);
         if (gd_1100 == 0.0) g_lots_1076 = gd_1108;
         else g_lots_1076 = g_ord_lots_1092 * gd_1100;
         if (g_lots_1076 < g_minlot_1036) g_lots_1076 = g_minlot_1036;
         else {
            if (g_lots_1076 > g_maxlot_1028) g_lots_1076 = g_maxlot_1028;
            else g_lots_1076 = NormalizeDouble(g_lots_1076 / g_lotstep_1044, 0) * g_lotstep_1044;
         }
         g_price_1060 = g_ord_open_price_1084 + gi_1000 * Point;
         if (Bid + gi_976 * Point <= g_price_1060 && !TradeByMarketOrders) OrderSend(Symbol(), OP_SELLLIMIT, g_lots_1076, g_price_1060, 0, 0, 0, "DTv.11.10 Universal" + MAGIC, g_magic_984, 0, Red);
         else
            if (Bid - g_ord_open_price_1084 >= gi_1000 * Point) OrderSend(Symbol(), OP_SELL, g_lots_1076, Bid, 0, 0, 0, "DTv.11.10 Universal" + MAGIC, g_magic_984, 0, Red);
         g_ord_open_price_1084 = 0;
         return (0);
      }
   }
   if (gi_968 == 2 && gi_1140) {
      if (g_count_956 == 0) {
         g_ord_open_price_1084 = 0;
         g_lots_1076 = gd_1068;
         if (g_lots_1076 < g_minlot_1036) g_lots_1076 = g_minlot_1036;
         else {
            if (g_lots_1076 > g_maxlot_1028) g_lots_1076 = g_maxlot_1028;
            else g_lots_1076 = NormalizeDouble(g_lots_1076 / g_lotstep_1044, 0) * g_lotstep_1044;
         }
         OrderSend(Symbol(), OP_BUY, g_lots_1076, Ask, g_slippage_948, 0, 0, "DTv.11.10 Universal" + MAGIC, g_magic_980, 0, Blue);
         return (0);
      }
      if (!gi_1144) {
         InitParam(g_magic_980 + g_count_956);
         if (gd_1100 == 0.0) g_lots_1076 = gd_1108;
         else g_lots_1076 = g_ord_lots_1092 * gd_1100;
         if (g_lots_1076 < g_minlot_1036) g_lots_1076 = g_minlot_1036;
         else {
            if (g_lots_1076 > g_maxlot_1028) g_lots_1076 = g_maxlot_1028;
            else g_lots_1076 = NormalizeDouble(g_lots_1076 / g_lotstep_1044, 0) * g_lotstep_1044;
         }
         g_price_1052 = g_ord_open_price_1084 - gi_1000 * Point;
         if (Ask - gi_976 * Point >= g_price_1052 && !TradeByMarketOrders) OrderSend(Symbol(), OP_BUYLIMIT, g_lots_1076, g_price_1052, 0, 0, 0, "DTv.11.10 Universal" + MAGIC, g_magic_984, 0, Blue);
         else
            if (g_ord_open_price_1084 - Ask >= gi_1000 * Point) OrderSend(Symbol(), OP_BUY, g_lots_1076, Ask, 0, 0, 0, "DTv.11.10 Universal" + MAGIC, g_magic_984, 0, Blue);
         g_ord_open_price_1084 = 0;
         return (0);
      }
   }
   return (0);
}

void InitParam(int a_magic_0) {
   if (!NeedDiffParameters) {
      gi_1000 = Pips;
      gd_1108 = Lots;
      gd_1100 = Doble;
      gi_988 = TakeProfit1;
      gi_992 = InitialStop1;
      gi_996 = TrailingStop1;
      g_magic_984 = g_magic_980;
      return;
   }
   if (a_magic_0 == g_magic_980) {
      gi_988 = TakeProfit1;
      gd_1108 = Lots;
      gi_992 = InitialStop1;
      gi_996 = TrailingStop1;
      return;
   }
   if (a_magic_0 == g_magic_980 + 1) {
      gi_1000 = Pips2;
      gd_1108 = Lots2;
      gd_1100 = Doble2;
      gi_988 = TakeProfit2;
      gi_992 = InitialStop2;
      gi_996 = TrailingStop2;
      g_magic_984 = g_magic_980 + 1;
      return;
   }
   if (a_magic_0 == g_magic_980 + 2) {
      gi_1000 = Pips3;
      gd_1108 = Lots3;
      gd_1100 = Doble3;
      gi_988 = TakeProfit3;
      gi_992 = InitialStop3;
      gi_996 = TrailingStop3;
      g_magic_984 = g_magic_980 + 2;
      return;
   }
   if (a_magic_0 == g_magic_980 + 3) {
      gi_1000 = Pips4;
      gd_1108 = Lots4;
      gd_1100 = Doble4;
      gi_988 = TakeProfit4;
      gi_992 = InitialStop4;
      gi_996 = TrailingStop4;
      g_magic_984 = g_magic_980 + 3;
      return;
   }
   if (a_magic_0 == g_magic_980 + 4) {
      gi_1000 = Pips5;
      gd_1108 = Lots5;
      gd_1100 = Doble5;
      gi_988 = TakeProfit5;
      gi_992 = InitialStop5;
      gi_996 = TrailingStop5;
      g_magic_984 = g_magic_980 + 4;
      return;
   }
   if (a_magic_0 == g_magic_980 + 5) {
      gi_1000 = Pips6;
      gd_1108 = Lots6;
      gd_1100 = Doble6;
      gi_988 = TakeProfit6;
      gi_992 = InitialStop6;
      gi_996 = TrailingStop6;
      g_magic_984 = g_magic_980 + 5;
      return;
   }
   if (a_magic_0 == g_magic_980 + 6) {
      gi_1000 = Pips7;
      gd_1108 = Lots7;
      gd_1100 = Doble7;
      gi_988 = TakeProfit7;
      gi_992 = InitialStop7;
      gi_996 = TrailingStop7;
      g_magic_984 = g_magic_980 + 6;
      return;
   }
   if (a_magic_0 == g_magic_980 + 7) {
      gi_1000 = Pips8;
      gd_1108 = Lots8;
      gd_1100 = Doble8;
      gi_988 = TakeProfit8;
      gi_992 = InitialStop8;
      gi_996 = TrailingStop8;
      g_magic_984 = g_magic_980 + 7;
      return;
   }
   if (a_magic_0 == g_magic_980 + 8) {
      gi_1000 = Pips9;
      gd_1108 = Lots9;
      gd_1100 = Doble9;
      gi_988 = TakeProfit9;
      gi_992 = InitialStop9;
      gi_996 = TrailingStop9;
      g_magic_984 = g_magic_980 + 8;
      return;
   }
   gi_1000 = Pips10;
   gd_1108 = Lots10;
   gd_1100 = Doble10;
   gi_988 = TakeProfit10;
   gi_992 = InitialStop10;
   gi_996 = TrailingStop10;
   g_magic_984 = g_magic_980 + 9;
}

int AnaliseIndicator0() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "#Macd", FastEMAMACD2, SlowEMAMACD2, SignalEMAMACD2, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "#Macd", FastEMAMACD2, SlowEMAMACD2, SignalEMAMACD2, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator1() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "OsMA", FastEMAOSMA, SlowEMAOSMA, SignalSMAOSMA, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "OsMA", FastEMAOSMA, SlowEMAOSMA, SignalSMAOSMA, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator2() {
   int li_ret_0 = 3;
   double l_iao_4 = iAO(NULL, 0, 0);
   double l_iao_12 = iAO(NULL, 0, 1);
   if (l_iao_4 > l_iao_12) li_ret_0 = 2;
   if (l_iao_4 < l_iao_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator3() {
   int li_ret_0 = 3;
   double l_iac_4 = iAC(NULL, 0, 0);
   double l_iac_12 = iAC(NULL, 0, 1);
   if (l_iac_4 > l_iac_12) li_ret_0 = 2;
   if (l_iac_4 < l_iac_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator4() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "Digital MACD", 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "Digital MACD", 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator5() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "ZeroLag MACD", FastEMAZeroLagMACD, SlowEMAZeroLagMACD, 1, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "ZeroLag MACD", FastEMAZeroLagMACD, SlowEMAZeroLagMACD, 1, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator6() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "5_34_5", 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "5_34_5", 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator7() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "Elliott Wave Oscillator", 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "Elliott Wave Oscillator", 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator8() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "Ergodic", r, s, u, smooth, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "Ergodic", r, s, u, smooth, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator9() {
   int li_ret_0 = 3;
   double l_imacd_4 = iMACD(NULL, 0, FastEMAMACD, SlowEMAMACD, 1, PRICE_CLOSE, MODE_MAIN, 0);
   double l_imacd_12 = iMACD(NULL, 0, FastEMAMACD, SlowEMAMACD, 1, PRICE_CLOSE, MODE_MAIN, 1);
   if (l_imacd_4 > l_imacd_12) li_ret_0 = 2;
   if (l_imacd_4 < l_imacd_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator10() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "CoeffoLine_Hist", ndot, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "CoeffoLine_Hist", ndot, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator11() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "AO_Adaptive", PriceMA1, MinPeriod1, MaxPeriod1, LevelStdDevPoint1, Smooth1, PriceMA2, MinPeriod2, MaxPeriod2, LevelStdDevPoint2, Smooth2, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "AO_Adaptive", PriceMA1, MinPeriod1, MaxPeriod1, LevelStdDevPoint1, Smooth1, PriceMA2, MinPeriod2, MaxPeriod2, LevelStdDevPoint2, Smooth2, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator12() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "FiboFan", Period_Q, Period_R, Period_S, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "FiboFan", Period_Q, Period_R, Period_S, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator13() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, PERIOD_W1, "OsMA", FastEMAOSMA, SlowEMAOSMA, SignalSMAOSMA, 0, 0);
   double l_icustom_12 = iCustom(NULL, PERIOD_W1, "OsMA", FastEMAOSMA, SlowEMAOSMA, SignalSMAOSMA, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator14() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "MAMA_NK", FastLimit, SlowLimit, IPC, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "MAMA_NK", FastLimit, SlowLimit, IPC, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator15() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "MAMAXX_NK", FastLimit, SlowLimit, IPC, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "MAMAXX_NK", FastLimit, SlowLimit, IPC, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator16() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "NDuet", sper, fper, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "NDuet", sper, fper, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator17() {
   int li_ret_0 = 3;
   double l_icustom_4 = iCustom(NULL, 0, "MACDonRSI", MA, RSIperiod, FastEMAMACDonRSI, SlowEMAMACDonRSI, SignalSMAMACDonRSI, 0, 0);
   double l_icustom_12 = iCustom(NULL, 0, "MACDonRSI", MA, RSIperiod, FastEMAMACDonRSI, SlowEMAMACDonRSI, SignalSMAMACDonRSI, 0, 1);
   if (l_icustom_4 > l_icustom_12) li_ret_0 = 2;
   if (l_icustom_4 < l_icustom_12) li_ret_0 = 1;
   return (li_ret_0);
}

int AnaliseIndicator18() {
   double l_icustom_0 = iCustom(NULL, 0, "OsMA", FastEMAOSMA, SlowEMAOSMA, SignalSMAOSMA, 0, 0);
   double l_icustom_8 = iCustom(NULL, 0, "OsMA", FastEMAOSMA, SlowEMAOSMA, SignalSMAOSMA, 0, 1);
   double l_icustom_16 = iCustom(NULL, 0, "ZeroLag MACD", FastEMAZeroLagMACD, SlowEMAZeroLagMACD, 1, 0, 0);
   double l_icustom_24 = iCustom(NULL, 0, "ZeroLag MACD", FastEMAZeroLagMACD, SlowEMAZeroLagMACD, 1, 0, 1);
   double l_imacd_32 = iMACD(NULL, 0, FastEMAMACD, SlowEMAMACD, 1, PRICE_CLOSE, MODE_MAIN, 0);
   double l_imacd_40 = iMACD(NULL, 0, FastEMAMACD, SlowEMAMACD, 1, PRICE_CLOSE, MODE_MAIN, 1);
   if (l_icustom_0 > l_icustom_8 && l_icustom_16 > l_icustom_24 && l_imacd_32 > l_imacd_40) gi_968 = 2;
   if (l_icustom_0 < l_icustom_8 && l_icustom_16 < l_icustom_24 && l_imacd_32 < l_imacd_40) gi_968 = 1;
   return (gi_968);
}

int AnaliseIndicator19() {
   double l_icustom_0 = iCustom(NULL, 0, "svs_trend", Period1, Period2, 0, 0);
   double l_icustom_8 = iCustom(NULL, 0, "svs_trend", Period1, Period2, 0, 1);
   if (l_icustom_0 > l_icustom_8) gi_968 = 2;
   if (l_icustom_0 < l_icustom_8) gi_968 = 1;
   return (gi_968);
}

int AnaliseIndicator20() {
   double l_istochastic_0 = iStochastic(NULL, 0, Kperiod, Dperiod, Slowing, MODE_LWMA, 1, MODE_MAIN, 0);
   double l_istochastic_8 = iStochastic(NULL, 0, Kperiod, Dperiod, Slowing, MODE_LWMA, 1, MODE_SIGNAL, 1);
   if (l_istochastic_0 > l_istochastic_8) gi_968 = 2;
   if (l_istochastic_0 < l_istochastic_8) gi_968 = 1;
   return (gi_968);
}