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

extern string com0 = "Открывать позиции с уровнями (SL,TP) ли модификация после открытия";
extern bool SetSlTpAtOpen = FALSE;
extern string com01 = "Торговать одним ордером или пачкой";
extern bool OnlyOneOrder = FALSE;
extern string com02 = "Переставлять профиты по крайнему профиту крайней позы";
extern bool MoveProfit = TRUE;
extern string com03 = "Торговать по рынку или отложенными лимит ордерами";
extern bool TradeByMarketOrders = FALSE;
extern string com04 = "Алгоритм закрытия прибыльных позиций IR(прямой) или WQ(обратный)";
extern bool IR_ili_WQ = TRUE;
extern string com05 = "Ждать ли закрытия бара перед началом торгов";
extern bool NeedWaitNewBar = FALSE;
extern string com06 = "Меджик номер ордера";
extern int MAGIC = 123456;
extern string com07 = "Манименеджмент если 0 то лот фиксированный задается в Lots";
extern string com08 = "Манименеджмент если 1 то лот задаеться как процент от депо";
extern int mm = 0;
extern string com09 = "Процент от депо при ММ=1 ОСТОРОЖНО советник использует Мартингейл";
extern double risk = 0.1;
extern string com10 = "Проскальзывание в пунктах допустимое";
extern int slippage = 2;
extern string com11 = "Минимум маржи на депо для защиты от слива";
extern double MinMargin = 100.0;
extern string com12 = "Максимум маржи на депо для ограничения прибыли";
extern double MaxMargin = 500000.0;
extern string com13 = "Общие параметры советника если NeedDiffParameters=true";
extern string com14 = "То параметры беруться из настроек для каждого ордера";
extern bool NeedDiffParameters = FALSE;
extern double Lots = 0.01;
extern int MaxTrades = 15;
extern int Pips = 40;
extern double Doble = 2.5;
extern int TakeProfit1 = 40;
extern int StopLoss1 = 0;
extern int TrailingStop1 = 0;
extern string com15 = "Если Revers=0 то позиции открываються по выбранному индикатору если 1 то против него";
extern int Revers = 0;
extern string com16 = "Профит по всем позициям в валюте депозита закрываемый советником";
extern string com17 = "Если ProfitCloce=0 то все позы будут закрываться по профиту либо тралу";
extern int ProfitCloce = 0;
extern string com18 = "Кол-во закрываемых позиций по ProfitCloce";
extern string com19 = "Если ABG_Algoritm=MaxTrades то вся пачка будет закрываться по ProfitCloce";
extern int ABG_Algoritm = 0;
extern string com20 = "Выбор индикатора для анализа рынка";
extern string com21 = "0=MACD2,1=OSMA,2=AO,3=AC,4=DigitalMACD,5=ZeroLag MACD";
extern string com22 = "6=5_34_5,7=ElliottWaveOscillator,8=Ergodic,9=MACD";
extern string com23 = "10=CoeffoLine_Hist,11=AO_Adaptive,12=FiboFan";
extern string com24 = "13=OSMA недельный график,14=MAMA_NK,15=MAMAXX_NK 16=NDuet";
extern string com25 = "17=MACDonRSI 18=Комбинация OsMA,ZeroLagMACD,MACD";
extern string com26 = "19=Svs_trend,20-Stochastic,21-Pivote, 22-Moving Average";
extern int AnaliseIndicator = 0;
extern string com27 = "Параметры разворотного ордера";
extern string com28 = "Ставим разворотный или нет";
extern bool NeedReverse = FALSE;
extern string com29 = "Закрываем пачку вместе с закрытием разворотного";
extern bool CloseReversOrder = FALSE;
extern string com30 = "Расстояние в пунктах от первой позы в пачке";
extern int Pipsr = 100;
extern string com31 = "Расстояние в пунктах от развортного для второго и последующих разворотныых";
extern int Pipsr2 = 20;
extern double Lotsr = 0.01;
extern int TakeProfitr = 40;
extern int StopLossr = 0;
extern int TrailingStopr = 30;
extern string com32 = "Уровень без убытка для разворотного если 0 то не работает";
extern int Bezub = 0;
extern string com33 = "Если Doble2-10=0 то размер позиции по ордерам выставляется в ручную";
extern string com34 = "Настроек всего 10, 11 и последующие ордера выставляються с параметрами 10";
extern string com35 = "Параметры ордера 2";
extern int Pips2 = 10;
extern double Lots2 = 0.01;
extern double Doble2 = 2.0;
extern int TakeProfit2 = 40;
extern int StopLoss2 = 0;
extern int TrailingStop2 = 30;
extern string com36 = "Параметры ордера 3";
extern int Pips3 = 10;
extern double Lots3 = 0.01;
extern double Doble3 = 2.0;
extern int TakeProfit3 = 40;
extern int StopLoss3 = 0;
extern int TrailingStop3 = 30;
extern string com37 = "Параметры ордера 4";
extern int Pips4 = 10;
extern double Lots4 = 0.01;
extern double Doble4 = 2.0;
extern int TakeProfit4 = 40;
extern int StopLoss4 = 0;
extern int TrailingStop4 = 30;
extern string com38 = "Параметры ордера 5";
extern int Pips5 = 10;
extern double Lots5 = 0.01;
extern double Doble5 = 2.0;
extern int TakeProfit5 = 40;
extern int StopLoss5 = 0;
extern int TrailingStop5 = 30;
extern string com39 = "Параметры ордера 6";
extern int Pips6 = 10;
extern double Lots6 = 0.01;
extern double Doble6 = 2.0;
extern int TakeProfit6 = 40;
extern int StopLoss6 = 0;
extern int TrailingStop6 = 30;
extern string com40 = "Параметры ордера 7";
extern int Pips7 = 10;
extern double Lots7 = 0.01;
extern double Doble7 = 2.0;
extern int TakeProfit7 = 20;
extern int StopLoss7 = 0;
extern int TrailingStop7 = 30;
extern string com41 = "Параметры ордера 8";
extern int Pips8 = 10;
extern double Lots8 = 0.01;
extern double Doble8 = 2.0;
extern int TakeProfit8 = 40;
extern int StopLoss8 = 0;
extern int TrailingStop8 = 30;
extern string com42 = "Параметры ордера 9";
extern int Pips9 = 10;
extern double Lots9 = 0.01;
extern double Doble9 = 2.0;
extern int TakeProfit9 = 20;
extern int StopLoss9 = 0;
extern int TrailingStop9 = 30;
extern string com43 = "Параметры ордера 10";
extern int Pips10 = 10;
extern double Lots10 = 0.01;
extern double Doble10 = 2.0;
extern int TakeProfit10 = 20;
extern int StopLoss10 = 0;
extern int TrailingStop10 = 30;
extern string com44 = "Параметры индикаторов";
extern string com45 = "Параметры индикатора 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 com46 = "Параметры индикатора CoeffoLine_Hist";
extern int ndot = 30;
extern string com47 = "Параметры индикатора Ergodic";
extern int r = 2;
extern int s = 5;
extern int u = 8;
extern int smooth = 2;
extern string com48 = "Параметры индикатора MACD";
extern int FastEMAMACD = 12;
extern int SlowEMAMACD = 26;
extern string com49 = "Параметры индикатора OSMA,";
extern int FastEMAOSMA = 12;
extern int SlowEMAOSMA = 26;
extern int SignalSMAOSMA = 9;
extern string com50 = "Параметры индикатора ZeroLagMACD,";
extern int FastEMAZeroLagMACD = 12;
extern int SlowEMAZeroLagMACD = 26;
extern string com51 = "Параметры индикатора #MACD";
extern int FastEMAMACD2 = 9;
extern int SlowEMAMACD2 = 64;
extern int SignalEMAMACD2 = 112;
extern string com52 = "Параметры индикатора FiboFan";
extern int Period_Q = 24;
extern int Period_R = 12;
extern int Period_S = 6;
extern string com53 = "Параметры индикатора MAMA_NK и MAMAXX_NK";
extern double FastLimit = 0.5;
extern double SlowLimit = 0.05;
extern int IPC = 4;
extern string com54 = "Параметры индикатора NDuet";
extern int sper = 55;
extern int fper = 21;
extern string com55 = "Параметры индикатора MACDonRSI";
extern int MA = 5;
extern int RSIperiod = 3;
extern int FastEMAMACDonRSI = 10;
extern int SlowEMAMACDonRSI = 20;
extern int SignalSMAMACDonRSI = 5;
extern string com56 = "Параметры индикатора Svs_trend";
extern int Period1 = 4;
extern int Period2 = 8;
extern string com57 = "Параметры индикатора Stochastic";
extern double Kperiod = 8.0;
extern double Dperiod = 3.0;
extern double Slowing = 4.0;
extern string com58 = "Параметры Moving Average";
extern int periodMa1 = 3;
extern int PRICE1 = 1;
extern int MODE1 = 0;
extern int periodMa2 = 8;
extern int PRICE2 = 1;
extern int MODE2 = 0;
int gi_1208 = 1;
int g_count_1212;
int g_pos_1216;
int gi_1224;
int gi_1228;
int gi_1232;
int g_magic_1236;
int g_magic_1240;
int g_magic_1244;
int gi_1248;
int gi_1252;
int gi_1256;
int gi_1260;
int gi_1264;
int gi_1268;
double g_price_1280;
double g_price_1288;
double g_maxlot_1296;
double g_minlot_1304;
double g_lotstep_1312;
double g_price_1320;
double g_price_1328;
double gd_1336;
double g_lots_1344;
double g_ord_open_price_1352;
double g_ord_open_price_1360;
double g_ord_lots_1368;
double gd_1376;
double gd_1384;
double gd_1392;
double gd_1400;
double g_tickvalue_1416;
double g_price_1424;
double g_price_1432;
bool gi_1440 = TRUE;
bool gi_1444;
bool gi_1448;
bool gi_1452;
bool gi_1456;
bool gi_1460;
string gs_1464;
datetime g_time_1472;
int g_datetime_1476;
int g_datetime_1480;

int init() {
   g_maxlot_1296 = MarketInfo(Symbol(), MODE_MAXLOT);
   g_minlot_1304 = MarketInfo(Symbol(), MODE_MINLOT);
   g_lotstep_1312 = MarketInfo(Symbol(), MODE_LOTSTEP);
   g_time_1472 = Time[0];
   g_magic_1236 = 100 * MAGIC;
   g_tickvalue_1416 = MarketInfo(Symbol(), MODE_TICKVALUE);
   g_datetime_1476 = 0;
   g_datetime_1480 = 0;
   if (ABG_Algoritm == 0) ABG_Algoritm = MaxTrades;
   return (0);
}

int start() {
   int l_ticket_0;
   int l_ticket_4;
   if (!IsTesting()) {
      if (!IsExpertEnabled()) {
         Comment("В торговом терминале запрещён запуск экспертов.");
         return (0);
      }
      if (!IsTradeAllowed()) {
         Comment("Торговля советниками запрещена или торговый поток занят.");
         return (0);
      }
   }
   if (CurrentRealBalance() < MinMargin) {
      CloseAll();
      return (0);
   }
   if (CurrentRealBalance() > MaxMargin) {
      CloseAll();
      return (0);
   }
   if (AccountNumber() != 10052) return (0);
   if (NeedWaitNewBar && Time[0] == g_time_1472) return (0);
   if (mm != 0) gd_1336 = AccountFreeMargin() / 1000.0 * (risk / 100.0);
   else gd_1336 = Lots;
   if (gd_1336 < g_minlot_1304) gd_1336 = g_minlot_1304;
   else {
      if (gd_1336 > g_maxlot_1296) gd_1336 = g_maxlot_1296;
      else gd_1336 = NormalizeDouble(gd_1336 / g_lotstep_1312, 0) * g_lotstep_1312;
   }
   gi_1232 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   gi_1264 = MarketInfo(Symbol(), MODE_SPREAD);
   gi_1460 = FALSE;
   int l_ticket_8 = 0;
   gi_1268 = 0;
   gd_1400 = 0;
   gi_1444 = FALSE;
   gi_1448 = FALSE;
   gi_1452 = FALSE;
   g_count_1212 = 0;
   int l_datetime_12 = 0;
   for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
      OrderSelect(g_pos_1216, SELECT_BY_POS);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10) continue;
      if (OrderType() > OP_SELL && OrderMagicNumber() < g_magic_1236 + 10) gi_1444 = TRUE;
      else {
         if (OrderMagicNumber() == g_magic_1236) g_datetime_1476 = OrderOpenTime();
         if (OrderMagicNumber() == g_magic_1236 + 10) {
            gi_1448 = TRUE;
            g_datetime_1480 = OrderOpenTime();
            if (OrderType() <= OP_SELL) {
               gi_1452 = TRUE;
               l_ticket_8 = OrderTicket();
               if (Bezub > 0) {
                  if (OrderType() == OP_SELL && OrderStopLoss() > OrderOpenPrice() || OrderStopLoss() == 0.0 && OrderOpenPrice() - Ask >= (gi_1232 + Bezub) * Point) {
                     g_price_1432 = NormalizeDouble(OrderOpenPrice() - Bezub * Point, Digits);
                     OrderModify(OrderTicket(), OrderOpenPrice(), g_price_1432, OrderTakeProfit(), 0, CLR_NONE);
                  }
                  if (OrderType() == OP_BUY && OrderStopLoss() < OrderOpenPrice() && Bid - OrderOpenPrice() >= (gi_1232 + Bezub) * Point) {
                     g_price_1432 = NormalizeDouble(OrderOpenPrice() + Bezub * Point, Digits);
                     OrderModify(OrderTicket(), OrderOpenPrice(), g_price_1432, OrderTakeProfit(), 0, CLR_NONE);
                  }
               }
            }
         } else {
            l_ticket_0 = OrderTicket();
            g_count_1212++;
            if (gi_1268 < OrderMagicNumber() - g_magic_1236 + 1) gi_1268 = OrderMagicNumber() - g_magic_1236 + 1;
         }
         InitParam(OrderMagicNumber());
         if (OrderType() == OP_BUY) {
            gi_1460 = TRUE;
            if (l_datetime_12 < OrderOpenTime()) {
               l_datetime_12 = OrderOpenTime();
               l_ticket_4 = OrderTicket();
               g_magic_1240 = OrderMagicNumber();
               if (OrderMagicNumber() != g_magic_1236 + 10) {
                  if (gi_1248 == 0) g_price_1424 = 0;
                  else {
                     if (OrderTakeProfit() == 0.0) g_price_1424 = NormalizeDouble(OrderOpenPrice() + gi_1248 * Point, Digits);
                     else g_price_1424 = NormalizeDouble(OrderTakeProfit(), Digits);
                  }
               }
            }
            gd_1400 += (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point;
            if (OrderTakeProfit() == 0.0 && OrderStopLoss() == 0.0 && gi_1248 != 0 || gi_1252 != 0) {
               if (gi_1248 == 0) g_price_1288 = 0;
               else {
                  if (OrderTakeProfit() == 0.0) g_price_1288 = NormalizeDouble(OrderOpenPrice() + gi_1248 * Point, Digits);
                  else g_price_1288 = NormalizeDouble(OrderTakeProfit(), Digits);
               }
               if (gi_1252 == 0) g_price_1280 = 0;
               else g_price_1280 = NormalizeDouble(OrderOpenPrice() - gi_1252 * Point, Digits);
               OrderModify(OrderTicket(), OrderOpenPrice(), g_price_1280, g_price_1288, 0, CLR_NONE);
            }
         } else {
            if (OrderType() == OP_SELL) {
               gi_1460 = TRUE;
               if (l_datetime_12 < OrderOpenTime()) {
                  l_datetime_12 = OrderOpenTime();
                  l_ticket_4 = OrderTicket();
                  g_magic_1240 = OrderMagicNumber();
                  if (OrderMagicNumber() != g_magic_1236 + 10) {
                     if (gi_1248 == 0) g_price_1424 = 0;
                     else {
                        if (OrderTakeProfit() == 0.0) g_price_1424 = NormalizeDouble(OrderOpenPrice() - gi_1248 * Point, Digits);
                        else g_price_1424 = NormalizeDouble(OrderTakeProfit(), Digits);
                     }
                  }
               }
               gd_1400 += (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point;
               if (OrderTakeProfit() == 0.0 && OrderStopLoss() == 0.0 && gi_1248 != 0 || gi_1252 != 0) {
                  if (gi_1248 == 0) g_price_1288 = 0;
                  else {
                     if (OrderTakeProfit() == 0.0) g_price_1288 = NormalizeDouble(OrderOpenPrice() - gi_1248 * Point, Digits);
                     else g_price_1288 = NormalizeDouble(OrderTakeProfit(), Digits);
                  }
                  if (gi_1252 == 0) g_price_1280 = 0;
                  else g_price_1280 = NormalizeDouble(OrderOpenPrice() + gi_1252 * Point, Digits);
                  OrderModify(OrderTicket(), OrderOpenPrice(), g_price_1280, g_price_1288, 0, CLR_NONE);
               }
            }
         }
      }
   }
   gs_1464 = "Суммарный профит по ордерам в пунктах*лот =" + gd_1400;
   gd_1400 *= g_tickvalue_1416;
   gs_1464 = gs_1464 + ".\nСуммарный профит по ордерам = $" + gd_1400 
      + "\nОткрыто ордеров " + g_count_1212 
      + "\nMaxTrades-ABG_Algoritm=" + ((MaxTrades - ABG_Algoritm)) 
   + "\nProfitCloce=" + ProfitCloce;
   Comment(gs_1464);
   if (MoveProfit && g_price_1424 > 0.0) {
      for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
         OrderSelect(g_pos_1216, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() >= g_magic_1236 + 10 || OrderType() > OP_SELL || NormalizeDouble(OrderTakeProfit(), Digits) == g_price_1424) continue;
         OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), g_price_1424, 0, CLR_NONE);
      }
   }
   if (!gi_1460) {
      for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
         OrderSelect(g_pos_1216, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10 || OrderType() <= OP_SELL) continue;
         OrderDelete(OrderTicket());
      }
   }
   if (g_count_1212 == 0 && gi_1448 && !gi_1452) {
      for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
         OrderSelect(g_pos_1216, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_1236 + 10 || OrderType() <= OP_SELL) continue;
         OrderDelete(OrderTicket());
      }
   }
   if (OnlyOneOrder) {
      g_count_1212 = 0;
      for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
         OrderSelect(g_pos_1216, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10) continue;
         if (OrderTicket() == l_ticket_4) g_count_1212++;
         else {
            if (OrderMagicNumber() == g_magic_1236 + 10) gi_1452 = FALSE;
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
            else
               if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
         }
      }
   } else {
      if (gi_1228 > g_count_1212 || (NeedReverse && !gi_1448 && g_datetime_1480 > g_datetime_1476 && !CloseReversOrder)) {
         gi_1456 = FALSE;
         if (IR_ili_WQ) {
            for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
               if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
               else
                  if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
               gi_1456 = TRUE;
            }
            for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() >= g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
               if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
               else
                  if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
               gi_1456 = TRUE;
            }
            for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() >= g_magic_1236 + 10 || OrderType() <= OP_SELL) continue;
               OrderDelete(OrderTicket());
               gi_1456 = TRUE;
            }
            for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_1236 + 10 || OrderType() <= OP_SELL) continue;
               OrderDelete(OrderTicket());
               gi_1456 = TRUE;
            }
         } else {
            for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
               if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
               else
                  if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
               gi_1456 = TRUE;
            }
            for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() >= g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
               if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
               else
                  if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
               gi_1456 = TRUE;
            }
            for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() >= g_magic_1236 + 10 || OrderType() <= OP_SELL) continue;
               OrderDelete(OrderTicket());
               gi_1456 = TRUE;
            }
            for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
               OrderSelect(g_pos_1216, SELECT_BY_POS);
               if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_1236 + 10 || OrderType() <= OP_SELL) continue;
               OrderDelete(OrderTicket());
               gi_1456 = TRUE;
            }
         }
         if (gi_1456) return (0);
      }
   }
   gi_1228 = g_count_1212;
   if (g_count_1212 >= MaxTrades - ABG_Algoritm && gi_1208 == 1 && ProfitCloce > 0 && gd_1400 >= ProfitCloce) {
      if (l_ticket_8 > 0) OrderSelect(l_ticket_8, SELECT_BY_TICKET);
      else OrderSelect(l_ticket_0, SELECT_BY_TICKET);
      if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Yellow);
      else {
         if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Yellow);
         else gi_1440 = FALSE;
      }
      gi_1228++;
      return (0);
   }
   if (g_count_1212 >= MaxTrades || gi_1268 >= MaxTrades) gi_1440 = FALSE;
   else gi_1440 = TRUE;
   if (g_ord_open_price_1352 == 0.0) {
      g_ord_open_price_1352 = 0;
      g_ord_open_price_1360 = 0;
      for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
         OrderSelect(g_pos_1216, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 9) continue;
         if (OrderMagicNumber() == g_magic_1236) g_ord_open_price_1360 = OrderOpenPrice();
         if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT) {
            gi_1224 = 2;
            if (g_ord_open_price_1352 > OrderOpenPrice() || g_ord_open_price_1352 == 0.0) {
               g_ord_lots_1368 = OrderLots();
               g_ord_open_price_1352 = OrderOpenPrice();
            }
         } else {
            if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT) {
               gi_1224 = 1;
               if (g_ord_open_price_1352 < OrderOpenPrice()) {
                  g_ord_lots_1368 = OrderLots();
                  g_ord_open_price_1352 = OrderOpenPrice();
               }
            }
         }
      }
   }
   if (g_count_1212 == 0 && !gi_1448) {
      switch (AnaliseIndicator) {
      case 1:
         gi_1224 = AnaliseIndicator1();
         break;
      case 2:
         gi_1224 = AnaliseIndicator2();
         break;
      case 3:
         gi_1224 = AnaliseIndicator3();
         break;
      case 4:
         gi_1224 = AnaliseIndicator4();
         break;
      case 5:
         gi_1224 = AnaliseIndicator5();
         break;
      case 6:
         gi_1224 = AnaliseIndicator6();
         break;
      case 7:
         gi_1224 = AnaliseIndicator7();
         break;
      case 8:
         gi_1224 = AnaliseIndicator8();
         break;
      case 9:
         gi_1224 = AnaliseIndicator9();
         break;
      case 10:
         gi_1224 = AnaliseIndicator10();
         break;
      case 11:
         gi_1224 = AnaliseIndicator11();
         break;
      case 12:
         gi_1224 = AnaliseIndicator12();
         break;
      case 13:
         gi_1224 = AnaliseIndicator13();
         break;
      case 14:
         gi_1224 = AnaliseIndicator14();
         break;
      case 15:
         gi_1224 = AnaliseIndicator15();
         break;
      case 16:
         gi_1224 = AnaliseIndicator16();
         break;
      case 17:
         gi_1224 = AnaliseIndicator17();
         break;
      case 18:
         gi_1224 = AnaliseIndicator18();
         break;
      case 19:
         gi_1224 = AnaliseIndicator19();
         break;
      case 20:
         gi_1224 = AnaliseIndicator20();
         break;
      case 21:
         gi_1224 = AnaliseIndicator21();
         break;
      case 22:
         gi_1224 = AnaliseIndicator22();
         break;
      default:
         gi_1224 = AnaliseIndicator0();
      }
      if (Revers == 1) {
         if (gi_1224 == 1) gi_1224 = 2;
         else
            if (gi_1224 == 2) gi_1224 = 1;
      }
   }
   if (IR_ili_WQ) {
      for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
         OrderSelect(g_pos_1216, SELECT_BY_POS);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
         InitParam(OrderMagicNumber());
         if (gi_1256 != 0) {
            if (OrderType() == OP_SELL) {
               if (OrderOpenPrice() - Ask >= (gi_1256 + gi_1260) * Point && NormalizeDouble(OrderStopLoss(), Digits) > NormalizeDouble(Ask + Point * gi_1256, Digits) || OrderStopLoss() == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gi_1256, Digits), OrderTakeProfit(), 0, Purple);
            } else {
               if (OrderType() == OP_BUY)
                  if (Bid - OrderOpenPrice() >= (gi_1256 + gi_1260) * Point && NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(Bid - Point * gi_1256, Digits)) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gi_1256, Digits), OrderTakeProfit(), 0, Yellow);
            }
         }
      }
   } else {
      if (!IR_ili_WQ) {
         for (g_pos_1216 = 0; g_pos_1216 < OrdersTotal(); g_pos_1216++) {
            OrderSelect(g_pos_1216, SELECT_BY_POS);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
            InitParam(OrderMagicNumber());
            if (gi_1256 != 0) {
               if (OrderType() == OP_SELL) {
                  if (OrderOpenPrice() - Ask >= (gi_1256 + gi_1260) * Point && NormalizeDouble(OrderStopLoss(), Digits) > NormalizeDouble(Ask + Point * gi_1256, Digits) || OrderStopLoss() == 0.0) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + Point * gi_1256, Digits), OrderTakeProfit(), 0, Purple);
               } else {
                  if (OrderType() == OP_BUY)
                     if (Bid - OrderOpenPrice() >= (gi_1256 + gi_1260) * Point && NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(Bid - Point * gi_1256, Digits)) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - Point * gi_1256, Digits), OrderTakeProfit(), 0, Yellow);
               }
            }
         }
      }
   }
   if (gi_1224 == 1) {
      if (!gi_1448 && !gi_1452 && g_count_1212 > 1 && NeedReverse) {
         InitParam(g_magic_1236 + 10);
         g_lots_1344 = gd_1384;
         if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
         else {
            if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
            else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
         }
         g_price_1320 = ReverseBZB(g_price_1432, g_datetime_1476);
         if (g_price_1320 == 0.0) return (0);
         gd_1392 = NormalizeDouble(g_price_1320 - gi_1264 * Point, Digits);
         if (SetSlTpAtOpen) {
            if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
            else g_price_1280 = NormalizeDouble(g_price_1320 - gi_1252 * Point, Digits);
            if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
            else g_price_1288 = NormalizeDouble(g_price_1320 + gi_1248 * Point, Digits);
         } else {
            g_price_1280 = 0;
            g_price_1288 = 0;
         }
         OrderSend(Symbol(), OP_BUYSTOP, g_lots_1344, g_price_1320, 0, g_price_1280, g_price_1288, "DTv.12.10 IN Multi##" + MAGIC, g_magic_1236 + 10, 0, Blue);
         g_price_1432 = 0;
      }
      if (!gi_1440) return (0);
      if (g_count_1212 == 0) {
         g_ord_open_price_1352 = 0;
         g_lots_1344 = gd_1336;
         if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
         else {
            if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
            else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
         }
         if (SetSlTpAtOpen) {
            if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
            else g_price_1280 = NormalizeDouble(Bid + gi_1252 * Point, Digits);
            if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
            else g_price_1288 = NormalizeDouble(Bid - gi_1248 * Point, Digits);
         } else {
            g_price_1280 = 0;
            g_price_1288 = 0;
         }
         OrderSend(Symbol(), OP_SELL, g_lots_1344, Bid, slippage, g_price_1280, g_price_1288, "DTv.12.10 IN Multi##" + MAGIC, g_magic_1236, 0, Red);
         gd_1392 = 0;
         g_price_1424 = 0;
      } else {
         if (!gi_1444 && !gi_1452) {
            if (g_magic_1240 < g_magic_1236 + 9) InitParam(g_magic_1240 + 1);
            else InitParam(g_magic_1236 + 9);
            if (gd_1376 == 0.0) g_lots_1344 = gd_1384;
            else g_lots_1344 = g_ord_lots_1368 * gd_1376;
            if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
            else {
               if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
               else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
            }
            g_price_1328 = NormalizeDouble(g_ord_open_price_1352 + gi_1260 * Point, Digits);
            if (Bid + gi_1232 * Point <= g_price_1328 && !TradeByMarketOrders && gd_1392 == 0.0 || gd_1392 > g_price_1328) {
               if (SetSlTpAtOpen) {
                  if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
                  else g_price_1280 = NormalizeDouble(g_price_1328 + gi_1252 * Point, Digits);
                  if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
                  else g_price_1288 = NormalizeDouble(g_price_1328 - gi_1248 * Point, Digits);
               } else {
                  g_price_1280 = 0;
                  g_price_1288 = 0;
               }
               OrderSend(Symbol(), OP_SELLLIMIT, g_lots_1344, g_price_1328, 0, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1244, 0, Red);
            } else {
               if (Bid - g_ord_open_price_1352 >= gi_1260 * Point && gd_1392 == 0.0 || gd_1392 > Bid) {
                  if (SetSlTpAtOpen) {
                     if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
                     else g_price_1280 = NormalizeDouble(Bid + gi_1252 * Point, Digits);
                     if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
                     else g_price_1288 = NormalizeDouble(Bid - gi_1248 * Point, Digits);
                  } else {
                     g_price_1280 = 0;
                     g_price_1288 = 0;
                  }
                  OrderSend(Symbol(), OP_SELL, g_lots_1344, Bid, slippage, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1244, 0, Red);
               }
            }
            g_ord_open_price_1352 = 0;
         }
      }
      if (!gi_1448 && !gi_1452 && g_count_1212 == 1 && NeedReverse) {
         InitParam(g_magic_1236 + 10);
         g_lots_1344 = gd_1384;
         if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
         else {
            if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
            else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
         }
         g_price_1320 = NormalizeDouble(g_ord_open_price_1360 + gi_1260 * Point, Digits);
         gd_1392 = NormalizeDouble(g_price_1320 - gi_1264 * Point, Digits);
         if (SetSlTpAtOpen) {
            if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
            else g_price_1280 = NormalizeDouble(g_price_1320 - gi_1252 * Point, Digits);
            if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
            else g_price_1288 = NormalizeDouble(g_price_1320 + gi_1248 * Point, Digits);
         } else {
            g_price_1280 = 0;
            g_price_1288 = 0;
         }
         OrderSend(Symbol(), OP_BUYSTOP, g_lots_1344, g_price_1320, 0, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1236 + 10, 0, Blue);
         g_price_1432 = 0;
      }
   }
   if (gi_1224 == 2) {
      if (!gi_1448 && !gi_1452 && g_count_1212 > 1 && NeedReverse) {
         InitParam(g_magic_1236 + 10);
         g_lots_1344 = gd_1384;
         if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
         else {
            if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
            else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
         }
         g_price_1328 = ReverseBZB(g_price_1432, g_datetime_1476);
         if (g_price_1328 == 0.0) return (0);
         gd_1392 = NormalizeDouble(g_price_1328 + gi_1264 * Point, Digits);
         if (SetSlTpAtOpen) {
            if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
            else g_price_1280 = NormalizeDouble(g_price_1328 + gi_1252 * Point, Digits);
            if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
            else g_price_1288 = NormalizeDouble(g_price_1328 - gi_1248 * Point, Digits);
         } else {
            g_price_1280 = 0;
            g_price_1288 = 0;
         }
         OrderSend(Symbol(), OP_SELLSTOP, g_lots_1344, g_price_1328, 0, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1236 + 10, 0, Red);
         g_price_1432 = 0;
      }
      if (!gi_1440) return (0);
      if (g_count_1212 == 0) {
         g_ord_open_price_1352 = 0;
         g_lots_1344 = gd_1336;
         if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
         else {
            if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
            else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
         }
         if (SetSlTpAtOpen) {
            if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
            else g_price_1280 = NormalizeDouble(Ask - gi_1252 * Point, Digits);
            if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
            else g_price_1288 = NormalizeDouble(Ask + gi_1248 * Point, Digits);
         } else {
            g_price_1280 = 0;
            g_price_1288 = 0;
         }
         OrderSend(Symbol(), OP_BUY, g_lots_1344, Ask, slippage, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1236, 0, Blue);
         gd_1392 = 0;
         g_price_1424 = 0;
      } else {
         if (!gi_1444 && !gi_1452) {
            if (g_magic_1240 < g_magic_1236 + 9) InitParam(g_magic_1240 + 1);
            else InitParam(g_magic_1236 + 9);
            if (gd_1376 == 0.0) g_lots_1344 = gd_1384;
            else g_lots_1344 = g_ord_lots_1368 * gd_1376;
            if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
            else {
               if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
               else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
            }
            g_price_1320 = NormalizeDouble(g_ord_open_price_1352 - gi_1260 * Point, Digits);
            if (Ask - gi_1232 * Point >= g_price_1320 && !TradeByMarketOrders && gd_1392 == 0.0 || gd_1392 < g_price_1320) {
               if (SetSlTpAtOpen) {
                  if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
                  else g_price_1280 = NormalizeDouble(g_price_1320 - gi_1252 * Point, Digits);
                  if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
                  else g_price_1288 = NormalizeDouble(g_price_1320 + gi_1248 * Point, Digits);
               } else {
                  g_price_1280 = 0;
                  g_price_1288 = 0;
               }
               OrderSend(Symbol(), OP_BUYLIMIT, g_lots_1344, g_price_1320, 0, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1244, 0, Blue);
            } else {
               if (g_ord_open_price_1352 - Ask >= gi_1260 * Point && gd_1392 == 0.0 || gd_1392 < Ask) {
                  if (SetSlTpAtOpen) {
                     if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
                     else g_price_1280 = NormalizeDouble(Ask - gi_1252 * Point, Digits);
                     if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
                     else g_price_1288 = NormalizeDouble(Ask + gi_1248 * Point, Digits);
                  } else {
                     g_price_1280 = 0;
                     g_price_1288 = 0;
                  }
                  OrderSend(Symbol(), OP_BUY, g_lots_1344, Ask, slippage, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1244, 0, Blue);
               }
            }
            g_ord_open_price_1352 = 0;
         }
      }
      if (!gi_1448 && !gi_1452 && g_count_1212 == 1 && NeedReverse) {
         InitParam(g_magic_1236 + 10);
         g_lots_1344 = gd_1384;
         if (g_lots_1344 < g_minlot_1304) g_lots_1344 = g_minlot_1304;
         else {
            if (g_lots_1344 > g_maxlot_1296) g_lots_1344 = g_maxlot_1296;
            else g_lots_1344 = NormalizeDouble(g_lots_1344 / g_lotstep_1312, 0) * g_lotstep_1312;
         }
         g_price_1328 = NormalizeDouble(g_ord_open_price_1360 - gi_1260 * Point, Digits);
         gd_1392 = NormalizeDouble(g_price_1328 + gi_1264 * Point, Digits);
         if (SetSlTpAtOpen) {
            if (gi_1252 < gi_1232 + gi_1264) g_price_1280 = 0;
            else g_price_1280 = NormalizeDouble(g_price_1328 + gi_1252 * Point, Digits);
            if (gi_1248 < gi_1232 - gi_1264 || gi_1248 == 0) g_price_1288 = 0;
            else g_price_1288 = NormalizeDouble(g_price_1328 - gi_1248 * Point, Digits);
         } else {
            g_price_1280 = 0;
            g_price_1288 = 0;
         }
         OrderSend(Symbol(), OP_SELLSTOP, g_lots_1344, g_price_1328, 0, g_price_1280, g_price_1288, "DTv.12.10 IN Multi#" + MAGIC, g_magic_1236 + 10, 0, Red);
         g_price_1432 = 0;
      }
   }
   return (0);
}

void CloseAll() {
   for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
      OrderSelect(g_pos_1216, SELECT_BY_POS);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10) continue;
      if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue);
      else {
         if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Red);
         else OrderDelete(OrderTicket());
      }
   }
}

double CurrentRealBalance() {
   double ld_0 = 0;
   for (g_pos_1216 = OrdersTotal() - 1; g_pos_1216 >= 0; g_pos_1216--) {
      OrderSelect(g_pos_1216, SELECT_BY_POS);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() < g_magic_1236 || OrderMagicNumber() > g_magic_1236 + 10 || OrderType() > OP_SELL) continue;
      ld_0 += OrderProfit() + OrderSwap();
   }
   return (AccountBalance() + ld_0);
}

void InitParam(int a_magic_0) {
   if (a_magic_0 == g_magic_1236 + 10) {
      gi_1260 = Pipsr;
      gd_1384 = Lotsr;
      gi_1248 = TakeProfitr;
      gi_1252 = StopLossr;
      gi_1256 = TrailingStopr;
      g_magic_1244 = g_magic_1236 + 10;
      return;
   }
   if (!NeedDiffParameters) {
      gi_1260 = Pips;
      gd_1384 = Lots;
      gd_1376 = Doble;
      gi_1248 = TakeProfit1;
      gi_1252 = StopLoss1;
      gi_1256 = TrailingStop1;
      g_magic_1244 = g_magic_1236;
      return;
   }
   if (a_magic_0 == g_magic_1236) {
      gi_1248 = TakeProfit1;
      gd_1384 = Lots;
      gi_1252 = StopLoss1;
      gi_1256 = TrailingStop1;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 1) {
      gi_1260 = Pips2;
      gd_1384 = Lots2;
      gd_1376 = Doble2;
      gi_1248 = TakeProfit2;
      gi_1252 = StopLoss2;
      gi_1256 = TrailingStop2;
      g_magic_1244 = g_magic_1236 + 1;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 2) {
      gi_1260 = Pips3;
      gd_1384 = Lots3;
      gd_1376 = Doble3;
      gi_1248 = TakeProfit3;
      gi_1252 = StopLoss3;
      gi_1256 = TrailingStop3;
      g_magic_1244 = g_magic_1236 + 2;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 3) {
      gi_1260 = Pips4;
      gd_1384 = Lots4;
      gd_1376 = Doble4;
      gi_1248 = TakeProfit4;
      gi_1252 = StopLoss4;
      gi_1256 = TrailingStop4;
      g_magic_1244 = g_magic_1236 + 3;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 4) {
      gi_1260 = Pips5;
      gd_1384 = Lots5;
      gd_1376 = Doble5;
      gi_1248 = TakeProfit5;
      gi_1252 = StopLoss5;
      gi_1256 = TrailingStop5;
      g_magic_1244 = g_magic_1236 + 4;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 5) {
      gi_1260 = Pips6;
      gd_1384 = Lots6;
      gd_1376 = Doble6;
      gi_1248 = TakeProfit6;
      gi_1252 = StopLoss6;
      gi_1256 = TrailingStop6;
      g_magic_1244 = g_magic_1236 + 5;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 6) {
      gi_1260 = Pips7;
      gd_1384 = Lots7;
      gd_1376 = Doble7;
      gi_1248 = TakeProfit7;
      gi_1252 = StopLoss7;
      gi_1256 = TrailingStop7;
      g_magic_1244 = g_magic_1236 + 6;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 7) {
      gi_1260 = Pips8;
      gd_1384 = Lots8;
      gd_1376 = Doble8;
      gi_1248 = TakeProfit8;
      gi_1252 = StopLoss8;
      gi_1256 = TrailingStop8;
      g_magic_1244 = g_magic_1236 + 7;
      return;
   }
   if (a_magic_0 == g_magic_1236 + 8) {
      gi_1260 = Pips9;
      gd_1384 = Lots9;
      gd_1376 = Doble9;
      gi_1248 = TakeProfit9;
      gi_1252 = StopLoss9;
      gi_1256 = TrailingStop9;
      g_magic_1244 = g_magic_1236 + 8;
      return;
   }
   gi_1260 = Pips10;
   gd_1384 = Lots10;
   gd_1376 = Doble10;
   gi_1248 = TakeProfit10;
   gi_1252 = StopLoss10;
   gi_1256 = TrailingStop10;
   g_magic_1244 = g_magic_1236 + 9;
}

double ReverseBZB(double ad_0, int ai_8) {
   if (Pipsr2 == 0) return (0);
   for (int l_pos_12 = 0; l_pos_12 < OrdersHistoryTotal(); l_pos_12++) {
      OrderSelect(l_pos_12, SELECT_BY_POS, MODE_HISTORY);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != g_magic_1236 + 10 || OrderOpenTime() < ai_8) continue;
      Print("*** ClosePrice=", DoubleToStr(OrderClosePrice(), Digits), " Level=", ad_0);
      if (NormalizeDouble(OrderClosePrice(), Digits) == ad_0) {
         if (OrderType() == OP_BUY) return (NormalizeDouble(ad_0 + Pipsr2 * Point, Digits));
         if (OrderType() == OP_SELL) return (NormalizeDouble(ad_0 - Pipsr2 * Point, Digits));
      }
   }
   return (0);
}

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_1224 = 2;
   if (l_icustom_0 < l_icustom_8 && l_icustom_16 < l_icustom_24 && l_imacd_32 < l_imacd_40) gi_1224 = 1;
   return (gi_1224);
}

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_1224 = 2;
   if (l_icustom_0 < l_icustom_8) gi_1224 = 1;
   return (gi_1224);
}

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_1224 = 2;
   if (l_istochastic_0 < l_istochastic_8) gi_1224 = 1;
   return (gi_1224);
}

int AnaliseIndicator21() {
   double ld_0 = (High[1] + Low[1] + Close[1] + Open[0]) / 4.0;
   double ld_8 = (High[0] + Low[0] + Close[0]) / 3.0;
   double ld_16 = 10000.0 * MathAbs(ld_0 - ld_8);
   if (Bid < ld_0 && Bid < ld_8 && ld_16 >= 7.0) return (1);
   if (Bid > ld_0 && Bid > ld_8 && ld_16 >= 7.0) return (2);
   return (0);
}

int AnaliseIndicator22() {
   double l_ima_0 = iMA(NULL, 0, periodMa1, 0, PRICE1, MODE1, 1);
   double l_ima_8 = iMA(NULL, 0, periodMa2, 0, PRICE2, MODE2, 1);
   if (l_ima_0 > l_ima_8) gi_1224 = 2;
   if (l_ima_0 < l_ima_8) gi_1224 = 1;
   return (gi_1224);
}