//+-----------------------------------------------------------------------------------------------------------+
//|                                                      HistoryInfo_v8_mod, SMShev (last changed 02-02-2013) |
//|                 http://ruforum.mt5.com/threads/6429-indikator-orderbalans.-vizualizatsiya-torgovli/page18 |
//|                                                                       Copyright © 2012, Sergey Shevchenko |
//|Based on source code of "HistoryInfo_v8" by Vladimir Hlystov (cmillion@narod.ru, http://cmillion.narod.ru) |
//+-----------------------------------------------------------------------------------------------------------+

//      В этой версии отображение информации о результатах торговли за "последние 10 дней", "по мэджикам", общая статистика
//      и бонусы отображаются после перетаскивания мышью соответсвующей мигающей "кнопочки"-надписи (т.е. надо выделить
//      объект-надпись на экране и сдвинуть ее на произвольное расстояние)

//Внешние параметры индикатора ---------------------------------------
static string date_of_mod = "02-02-2013";
#property copyright "SMShev"
#property indicator_separate_window
extern string     MagiсsList            = "";             //Magic-номера советников через запятую, если "" или "0", то обрабатываются все магики
extern string     SymbolsInfo           = "";             //Торговые инструменты через запятую, если "" то все инструменты
extern datetime   DateInfoStart         = D'01.01.2008';  //сканировать историю сделок начинать с даты (если ScanFromToday = false)
extern datetime   DateInfoEnd           = D'01.01.2030';  //сканировать историю сделок заканчивая датой (если ScanFromToday = false)
extern bool       ScanFromToday         = true;           //сканировать историю сделок от текущей даты временной период, определяемы параметрами DaysToScan, ScanCurrentWeek и ScanCurrentMonth (если они оба False, то отображается информация только за количесво дней, указанное в параметре DaysToScan)
extern int        DaysToScan            = 1;              //сколько дней сканировать от текущей даты в прошлое для режима ScanFromToday=True и ScanCurrentWeek=False и ScanCurrentMonth=False (если <=1, то только текущий день)
extern bool       ScanCurrentWeek       = true;           //сканировать с начала текущей недели для режима ScanFromToday=True (имеет приоритет над DaysToScan, т.е. если True, то отображается информация за текущую неделю, а не за количесво дней, указанное в параметре DaysToScan)
extern bool       ScanCurrentMonth      = false;          //сканировать с начала текущего месяца для режима ScanFromToday=True (имеет приоритет над ScanCurrentWeek, т.е. если True, то отображается информация за месяц, а не за неделю при любом значении ScanCurrentWeek и DaysToScan)
extern bool       ShowCurrent           = true;           //показывать текущие открытые торговые сделки
extern bool       ShowHistory           = true;           //показывать результаты закрытых сделок за выбранный период
extern bool       ShowMagics            = true;           //показывать результаты по MAgic-номерам (также автоматически отключается при ShowHistory = false)
extern bool       ShowLast10Days        = true;           //показывать суммарные результаты торговли отдельно по последним 10 дням (также автоматически отключается при ShowHistory = false)
extern bool       ShowProfitByStopLoss  = true;           //показывать потенциальный результат открытых сделок в случае срабатывания их StopLoss-ов (если установлены)
extern bool       LogInfoToFile         = true;           //сохранять информацию в файл CSV (в папке <терминал>\experts\files) с именем "HI-<ГОД>-<ТФ>.csv"
extern int        ShowInfoDuration      = 5;              //Продолджительность времени отображения дополнительной информации (включаемой по перетаскиванию "кнопок") в минутах (должно быть не менее 1)
extern int        ColorShemeType        = 1;              //цветовая схемы раскраски результатов (0 - двухцветная, 1 - многоцветная)
extern int        MinFontSize           = 8;              //минимальный кегль надписей, используемых в индикаторе для отображения информации
extern int        MaxMagiksSymbosInRow  = 0;              //количество столбцов для отображения информации по мэджикам/торговым инструментам, если =0, то все будут в 1 строку, для случаев когда их много и не все влезают на экран по ширине можно установить значение (подобрать удобное для отображения)
extern int        ColumnShift           = 80;             //ширина между столбцами для отображения данных по инструментам/магик-номерам (для "пятизначных" ДЦ рекомендуется увеличить, например, до 100)
extern int        WorkingWindow         = 0;              //номер рабочего подокна индикатора (для установки нескольких копий индикатора на один график, если 0, то будет работать только в одном подокне - в первом, в котором будет найден данный индикатор или будет создано новое подокно если это первая установка индикатора на график)
//Подстроечные параметры индикатора ----------------------------------
static color  MainColor             = Snow,           //цвет отображения общей информации
              HeaderColor           = CornflowerBlue, //цвет отображения заголовков
              NullColor0_0          = LightSlateGray, //для цветовой схемы 0
              PositiveColor0        = LimeGreen,
              NegativeColor0        = Tomato,
              NullColor1_0          = LightSlateGray, //для цветовой схемы 1
              PositiveColor1_3      = Green,          //для цветовой схемы 1
              NegativeColor1_3      = Red,
              PositiveColor1_2      = LimeGreen,
              NegativeColor1_2      = OrangeRed,
              PositiveColor1_1      = SpringGreen,
              NegativeColor1_1      = Tomato,
              PositiveColor1_0      = LightGreen,
              NegativeColor1_0      = Coral;
static int    ColorShemeTreshold1_3 = 50,             //диапазоны значений результатов торговли для выбора цвета световой схемы 1
              ColorShemeTreshold1_2 = 20,
              ColorShemeTreshold1_1 = 10,
              CurrStartRowBase      = 15,             //"базовые" значения "якорных" координат размещения информационных блоков
              CurrRowHight          = 80,
              HistStartRowBase      = 95,
              HistRowHight          = 90,
              MagStartRowBase       = 185,
              MagRowHight           = 128,
              LtenStartRowBase      = 15,
              InfoStartRowBase      = 20,
              ButtonStartRowBase    = 162;
static bool   СalcStartDep          = true,           //вычислять депозит на начало периода (используется для расчета % результативности торговли)
              ShowMagicsDetails     = true,           //показывать подробную информацию по Magic-номерам (также отключается при ShowHistory = false и/или ShowMagics = false)
              Last10DaysAutoPlace   = true;           //автоматическое размещение истории за 10 дней рядом со статистикой по советникам, если в торговле уччаствует много валютных пар и значительно меньше magic-номеров
static string AccLeverageSymbol     = "EURUSD";       //обозначения символа для корректного расчета торгового плеча (зависит от базовой валюты счета, в некоторых ДЦ обозначения торговых инструментов имеют дополнительные префиксы)
//--------------------------------------------------------------------
string Magiks, Symbl[2][100], BTags[2][100], NameInd = "HistoryInfo_v8_mod", Font = "Tahoma", txt, TimeSkan, FileName;

double Today[3][10], HistoryOrders[15][10000], Orders[6][10000], SymbolProfit[2][100], SymbolHistoryProfit[3][100], MagikProfit[11][100], HistoryLot[2][100], TekLot[2][100], Bonuses[4][100], Summary[6][6],
       StartDep = 0.0, AccWithdrawal = 0.0, AccStartDep = 0.0, TS, ProfitAll, CurSumDD, MaxSumDD, MaxSumDD1, AccEquity, AccProfit, AccBalance, FreeMar, MinFreeMar;

int RealWrkWnd, PrevWndCount, FntSz8, FntSz9, FntSz10, InfoColumnShift = 5, StartColumnShift = 200,
    RowShift, RowShift2, ColumnShift2, RowShift3,
    HistStartRow, CurrStartRow, MagStartRow, LtenStartRow, InfoStartRow, ButtonStartRow,
    HistoryType[2][100], TekType[2][100], Magik[2, 100],
    dgts, hn, tn, HistOrdsTot, Nsymb = 0, Nmag = 0, Nbonuses = -1, n_oht = 0, n_oct = 0, LogFileHandle = -1;

datetime PrevTickDate, PrevTickDateReal, IndStartTime, TCurr, OOT, BonusShowTime = -1, DetailShowTime = -1, CandleTime = -1, LastLoggedCandle = -1;

bool SecondInstanceInOneWindow = false, LogEnable = false, isNewDay = false, isWEnd = false, WEndSumHide = false, 
     BonusNeedShow = false, HistNeedShow = true, MagNeedShow = false, L10NeedShow = false, SumNeedShow = false;
//--------------------------------------------------------------------
int deinit()
{
   LogFileDeInit();
   if(!SecondInstanceInOneWindow) {ObjectsDeleteAll(RealWrkWnd);}
   return(true);
}
//--------------------------------------------------------------------
int init()
{
  IndStartTime = TimeCurrent();
  if(IsTesting() && !IsVisualMode()) {Print(NameInd, " is disabled in testing/optimization mode"); return(false);}

  TCurr = TimeCurrent();
  if(ScanFromToday) {DateInfoEnd = STT(DTS(TimeYear(TCurr), 0) + "." + DTS(TimeMonth(TCurr), 0) + "." + DTS(TimeDay(TCurr), 0) + " 23:59:59");}
  else
  {
    if(DateInfoEnd > TCurr)  {DateInfoEnd = STT(DTS(TimeYear(TCurr), 0) + "." + DTS(TimeMonth(TCurr), 0) + "." + DTS(TimeDay(TCurr), 0) + " 23:59:59");}
    else   {DateInfoEnd = STT(DTS(TimeYear(DateInfoEnd), 0) + "." + DTS(TimeMonth(DateInfoEnd), 0) + "." + DTS(TimeDay(DateInfoEnd), 0) + " 23:59:59");}
  }

  BTags[0][0] = "IR";                        //Начисление ДЦ % на остаток свободных средств на торговом счете пользователей (за месяц)
  BTags[1][0] = "0";
  BTags[0][1] = "BONUS FOR POST";
  BTags[1][1] = "0";
  BTags[0][2] = "WELCOME BONUS";
  BTags[1][2] = "0";
  BTags[0][3] = "CLUB BONUS";
  BTags[1][3] = "0";
  BTags[0][4] = "Rebate: OMEGA_FINMARKET";
  BTags[1][4] = "0";
  BTags[0][5] = "Rebate: InstaRebate";
  BTags[1][5] = "0";
  BTags[0][6] = "INSTAREBATE AFFILIATE";
  BTags[1][6] = "1";                           //признак дополнительной детализации по номерам счетов реферралов
  BTags[0][7] = "бонус за первый депозит";
  BTags[1][7] = "0";
  BTags[0][8] = "бонус  за переход из дц";
  BTags[1][8] = "0";

  CurrStartRow = CurrStartRowBase;
  HistStartRow = HistStartRowBase + RowShift;
  MagStartRow = MagStartRowBase + RowShift;
  LtenStartRow = LtenStartRowBase;
  InfoStartRow = InfoStartRowBase;
  ButtonStartRow = ButtonStartRowBase;

  FntSz8 = MinFontSize;
  FntSz9 = MinFontSize + 1;
  FntSz10 = MinFontSize + 2;

  if(DaysToScan < 1)  {DaysToScan = 1;}
  if(ScanCurrentMonth)  {ScanCurrentWeek = false;}
  if(ScanFromToday)  {ShowCurrent = true; ShowHistory = true; MagNeedShow = false; L10NeedShow = false;}
  if(!ShowHistory && !ShowCurrent) {ShowCurrent = true;}
  if(!ShowHistory) {ShowMagics = false; ShowLast10Days = false;}
  if(ShowHistory && ShowCurrent) {RowShift = 0;}
  if(ShowHistory && !ShowCurrent) {RowShift += -80;}
  if(!ShowHistory && ShowCurrent) {RowShift += -80;}
  if(LogInfoToFile)  {LogEnable = true;}
  if(IsTesting() || IsOptimization() || !IsConnected()) {LogEnable = false;}
  if(ShowInfoDuration < 1) {ShowInfoDuration = 1;}
  if(ColorShemeType < 0 || ColorShemeType > 1)  {ColorShemeType = 0;}

  if(
    StringLen(TRIM(StringConcatenate(MagiсsList, ""))) == 0
    ||
    STD(StringSubstr(TRIM(StringConcatenate(MagiсsList, "")), 0, 1)) <= 0
   ) {Magiks = "";}
  else {Magiks = TRIM(MagiсsList);}

  if(StringLen(TRIM(StringConcatenate(SymbolsInfo, ""))) == 0) {SymbolsInfo = "";}
  else {SymbolsInfo = TRIM(SymbolsInfo);}

  PrevWndCount = WindowsTotal();
  SecondInstanceInOneWindow = false;
  if(RealWrkWnd != WindowFind(NameInd) || RealWrkWnd != ObjectFind("hi8_copyright_mod" + RealWrkWnd))  {RealWrkWnd = 0;}
  if(WorkingWindow == 0 && RealWrkWnd == 0)
  {
    RealWrkWnd = WindowFind(NameInd);
  }
  else
  {
    RealWrkWnd = WorkingWindow;
  }
  if(ObjectFind("hi8_copyright_mod" + RealWrkWnd) >= 0) {SecondInstanceInOneWindow = true;}
  if(!SecondInstanceInOneWindow) {ObjectsDeleteAll(RealWrkWnd);}

  LogFileInit();

  AccBalance = AccountBalance();
  MinFreeMar = AccBalance;
  FreeMar = AccBalance;
  Today[2][0] = AccBalance;
  isNewDay = true;
  HistOrdsTot = 0;
  hn = HistoryOrders();
  PrevTickDate = -1;
  PrevTickDateReal = -1;
  CandleTime = Time[0];
  dgts = Digits;
  return(0);
}   
//--------------------------------------------------------------------
int start()                                  
{
  if(IsStopped()) {deinit();}
  if(IsTesting() && !IsVisualMode()) {Print(NameInd, " is disabled in testing/optimization mode"); return(true);}

  if(IsConnected()) 
  {
    if(LogInfoToFile && !LogEnable)
    {
      LogEnable = true;
      PrevTickDate = -1;
      LogFileInit();
    }
    RefreshRates();
  }
  else
  {
    LogEnable = false;
    Print(NameInd, " ", Symbol(), " ", Period(), " No cconnection with trade server!");
    return(0);
  }

  int i, j, k, i2, r2;
  string _tmptxt;
      
  if(PrevWndCount - WindowsTotal() == 1)
  {
    i = ObjectFind("hi8_copyright_mod" + RealWrkWnd);
    if(i > 0 && i != RealWrkWnd)
    {
      ObjectsDeleteAll(i);
      RealWrkWnd = i;
      isNewDay = true;
      PrevTickDate = -1;
      HistOrdsTot = 0;
      hn = HistoryOrders();
    }
  }
  if(WorkingWindow == 0 && WindowOnDropped() > 0 && RealWrkWnd <= 0) {RealWrkWnd = WindowOnDropped();}
  if(SecondInstanceInOneWindow)
  {
    Print(NameInd, " ", Symbol(), " ", Period(), " - Detected another running instance of the indicator in the same  window! Remove one of the copies or assign a different number of working window!");
    return(0);
  }
  if(RealWrkWnd <= 0)
  {
    RealWrkWnd = WindowFind(NameInd);
  }
  if(RealWrkWnd > (WindowsTotal() - 1) && (WindowsTotal() - 1) >= PrevWndCount)
  {
    Alert(NameInd, " ", Symbol(), " ", Period(), " - Specified in the settings of the indicator operating subwindow has been found! ", "Specified subwindow number: ", WorkingWindow, ", subwindow founded:", WindowsTotal() - 1);
    return(0);
  }
  if((WindowFind(NameInd) >= 0 && RealWrkWnd < 0 && ObjectFind("hi8_copyright_mod" + WindowFind(NameInd)) >= 0) || (RealWrkWnd > (WindowsTotal() - 1)))
  {
    Print(NameInd, " ", Symbol(), " ", Period(), " - Specified in the settings of the indicator operating subwindow has been found!!! ", "Specified subwindow number: ", WorkingWindow, ", subwindow founded:", WindowsTotal() - 1);
    return(0);
  }
  PrevWndCount = WindowsTotal();

  n_oht = OrdersHistoryTotal();
  TCurr = TimeCurrent();
  if(ScanFromToday) {DateInfoEnd = STT(DTS(TimeYear(TCurr), 0) + "." + DTS(TimeMonth(TCurr), 0) + "." + DTS(TimeDay(TCurr), 0) + " 23:59:59");}
  else
  {
    if(DateInfoEnd > TCurr)  {DateInfoEnd = STT(DTS(TimeYear(TCurr), 0) + "." + DTS(TimeMonth(TCurr), 0) + "." + DTS(TimeDay(TCurr), 0) + " 23:59:59");}
    else   {DateInfoEnd = STT(DTS(TimeYear(DateInfoEnd), 0) + "." + DTS(TimeMonth(DateInfoEnd), 0) + "." + DTS(TimeDay(DateInfoEnd), 0) + " 23:59:59");}
  }

  if(WEndSumHide && (TCurr - DetailShowTime) / 60 >= ShowInfoDuration) {WEndSumHide = false;}
  {
    if((TimeHour(TCurr) > 19 || (TimeDayOfWeek(TCurr) == 5 && TimeHour(TCurr) > 14) || TimeDayOfWeek(TCurr) > 5) && !WEndSumHide) {isWEnd = true;}  //19 5 14 5
    else 
    {
      if(isWEnd)  {SumNeedShow = false; MagNeedShow = false; L10NeedShow = false; PrevTickDate = -1; DetailShowTime = -1; BonusShowTime = -1;}
      isWEnd = false;
    }
    if(ShowHistory && isWEnd && !SumNeedShow && !BonusNeedShow)
    {
      SumNeedShow = true; MagNeedShow = true; L10NeedShow = true; BonusNeedShow = false; PrevTickDate = -1; BonusShowTime = -1; DetailShowTime = TCurr;
    }
  }

  if(Nbonuses >= 0)
  {
    int BonusId, BonusShift = 0;
    string BonusRef;
    if(!BonusNeedShow)  {Text(StringConcatenate("ShBonuses", RealWrkWnd), "Show bonuses", InfoColumnShift, ButtonStartRow + 45, HeaderColor, FntSz10, RealWrkWnd);}
    else
    {
      if(ScanFromToday && (TCurr - BonusShowTime) / 60 >= ShowInfoDuration) {Text(StringConcatenate("ShBonuses", RealWrkWnd), "Show main info", InfoColumnShift, ButtonStartRow + 46, HeaderColor, FntSz10, RealWrkWnd);}
      else {Text(StringConcatenate("ShBonuses", RealWrkWnd), "Show main info", InfoColumnShift, ButtonStartRow + 45, HeaderColor, FntSz10, RealWrkWnd);}
      double BonusTot = 0.0, BonusTotP = 0.0;
      Text(StringConcatenate("BonusesT1", RealWrkWnd), "Bonus:", StartColumnShift, BonusShift + CurrStartRow, HeaderColor, FntSz10, RealWrkWnd);
      Text(StringConcatenate("BonusesT2", RealWrkWnd), "Total:", StartColumnShift + 3.5 * ColumnShift, BonusShift + CurrStartRow, HeaderColor, FntSz10, RealWrkWnd);
      Text(StringConcatenate("BonusesP", RealWrkWnd), "In selected  period:", StartColumnShift + 4.5 * ColumnShift, BonusShift + CurrStartRow, HeaderColor, FntSz10, RealWrkWnd);
      for(i = 0; i <= Nbonuses; i++)
      {
        BonusShift = i * 13;
        if(Bonuses[1][i] != EMPTY_VALUE) {BonusRef = DTS(Bonuses[1][i], 0);}
        else {BonusRef = "";}

        BonusId = MathRound(Bonuses[0][i]);
        Text(StringConcatenate("BonusesN", i, RealWrkWnd), StringConcatenate(BTags[0][BonusId], "   ", BonusRef), StartColumnShift, 15 + BonusShift + CurrStartRow, MainColor, FntSz10, RealWrkWnd);
        Text(StringConcatenate("BonusesV", i, RealWrkWnd), DTS(Bonuses[2][i], 2), StartColumnShift + 3.5 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(Bonuses[2][i]), FntSz10, RealWrkWnd);
        Text(StringConcatenate("BonusesPV", i, RealWrkWnd), DTS(Bonuses[3][i], 2), StartColumnShift + 4.5 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(Bonuses[2][i]), FntSz10, RealWrkWnd);

        if(Bonuses[2][i] > 0)
        {
          BonusTot += Bonuses[2][i];
          BonusTotP += Bonuses[3][i];
          Text(StringConcatenate("BonusesPV%", i, RealWrkWnd), StringConcatenate(DTS(100 * (Bonuses[3][i] / Bonuses[2][i]), 2), "%"), StartColumnShift + 5.4 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(Bonuses[2][i]), FntSz10, RealWrkWnd);
        }
        else  {Text(StringConcatenate("BonusesPV%", i, RealWrkWnd), "", StartColumnShift + 5.4 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(Bonuses[2][i]), FntSz10, RealWrkWnd);}
      }

      if(BonusTot > 0.0)
      {
        BonusShift = i * 13;
        Text(StringConcatenate("BonusesTN", i, RealWrkWnd), "Total:", StartColumnShift, 15 + BonusShift + CurrStartRow, MainColor, FntSz10, RealWrkWnd);
        Text(StringConcatenate("BonusesTV", i, RealWrkWnd), DTS(BonusTot, 2), StartColumnShift + 3.5 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(BonusTot), FntSz10, RealWrkWnd);
        Text(StringConcatenate("BonusesTPV", i, RealWrkWnd), DTS(BonusTotP, 2), StartColumnShift + 4.5 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(BonusTot), FntSz10, RealWrkWnd);
        Text(StringConcatenate("BonusesTPV%", i, RealWrkWnd), StringConcatenate(DTS(100 * (BonusTotP / BonusTot), 2), "%"), StartColumnShift + 5.4 * ColumnShift, 15 + BonusShift + CurrStartRow, Color(BonusTot), FntSz10, RealWrkWnd);
      }
    }
  }

  if(
     TimeDay(TCurr) > TimeDay(PrevTickDate)
     ||
     TimeMonth(TCurr) > TimeMonth(PrevTickDate)
     ||
     TimeYear(TCurr) > TimeYear(PrevTickDate)
    )
  {
    ObjectsDeleteAll(RealWrkWnd);
    if(TimeYear(DateInfoEnd) > TimeYear(PrevTickDateReal))
    {
      LogFileDeInit("HI_Deinit_NewYear=");
      LogFileInit();
    }

    if(
       TimeDay(TCurr) > TimeDay(PrevTickDateReal)
       ||
       TimeMonth(TCurr) > TimeMonth(PrevTickDateReal)
       ||
       TimeYear(TCurr) > TimeYear(PrevTickDateReal)
      )
    {
      MaxSumDD1 = ProfitAll;
      CurSumDD = ProfitAll;
      FreeMar = AccountBalance();
      MinFreeMar = FreeMar;
      Today[1][0] = ProfitAll;
      Today[2][0] = FreeMar;
    }

    isNewDay = true;
    PrevTickDate = TCurr;
    PrevTickDateReal = TCurr;
    hn = HistoryOrders();
    if(
//       !isNewDay &&
       (
        (((TCurr - IndStartTime) / 60) > 20 && ((TCurr - IndStartTime) / 60) < 50)
        ||
        DateInfoStart < STT("1971.31.12")
        ||
        (ScanFromToday &&
         (
          (!ScanCurrentWeek && !ScanCurrentMonth && TS > DaysToScan)
          ||
          (ScanCurrentWeek && !ScanCurrentMonth && TS > 7)
          ||
          (ScanCurrentMonth && TS > 31)
         )
        )
       )
      )
    {
      isNewDay = true;
      PrevTickDate = -1;
      PrevTickDateReal = -1;
      HistOrdsTot = 0;
      return(0);
    }

    if(ObjectFind(StringConcatenate("hi8_mod_date", RealWrkWnd)) <= 0) {ObjectCreate(StringConcatenate("hi8_mod_date", RealWrkWnd), OBJ_LABEL, RealWrkWnd, 0, 0);}
    ObjectSet(StringConcatenate("hi8_mod_date", RealWrkWnd), OBJPROP_CORNER, 2);
    ObjectSet(StringConcatenate("hi8_mod_date", RealWrkWnd), OBJPROP_YDISTANCE, 20);
    ObjectSet(StringConcatenate("hi8_mod_date", RealWrkWnd), OBJPROP_XDISTANCE, 2);
    ObjectSetText(StringConcatenate("hi8_mod_date", RealWrkWnd), StringConcatenate("Last modified on ", date_of_mod), FntSz8 - 1, Font, MainColor);
    if(ObjectFind(StringConcatenate("hi8_copyright_mod", RealWrkWnd)) <= 0) {ObjectCreate(StringConcatenate("hi8_copyright_mod", RealWrkWnd), OBJ_LABEL, RealWrkWnd, 0, 0);}
    ObjectSet(StringConcatenate("hi8_copyright_mod", RealWrkWnd), OBJPROP_CORNER, 2);
    ObjectSet(StringConcatenate("hi8_copyright_mod", RealWrkWnd), OBJPROP_YDISTANCE, 11);
    ObjectSet(StringConcatenate("hi8_copyright_mod", RealWrkWnd), OBJPROP_XDISTANCE, 2);
    ObjectSetText(StringConcatenate("hi8_copyright_mod", RealWrkWnd), "Copyright © 2012 shew-sergey@yandex.ru", FntSz8 - 1, Font, MainColor);
    if(ObjectFind(StringConcatenate("hi8_mod_base", RealWrkWnd)) <= 0) {ObjectCreate(StringConcatenate("hi8_mod_base", RealWrkWnd), OBJ_LABEL, RealWrkWnd, 0, 0);}
    ObjectSet(StringConcatenate("hi8_mod_base", RealWrkWnd), OBJPROP_CORNER, 2);
    ObjectSet(StringConcatenate("hi8_mod_base", RealWrkWnd), OBJPROP_YDISTANCE, 2);
    ObjectSet(StringConcatenate("hi8_mod_base", RealWrkWnd), OBJPROP_XDISTANCE, 2);
    ObjectSetText(StringConcatenate("hi8_mod_base", RealWrkWnd), StringConcatenate("Based on HistoryInfo_v8", " by cmillion@narod.ru"), FntSz8 - 1, Font, MainColor);
    Text(StringConcatenate("DateInfo", RealWrkWnd), StringConcatenate("The range of dates from ", TTS(DateInfoStart + 1, TIME_DATE), " to ", TTS(DateInfoEnd, TIME_DATE), TimeSkan), 430, 2, MainColor, FntSz8, RealWrkWnd);

    Text(StringConcatenate("i0", RealWrkWnd), StringConcatenate("Information on the account ", AccountNumber(), " / ", AccountCompany()), 100, 2, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i1H", RealWrkWnd), "Summary account info:", InfoColumnShift, InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i3H", RealWrkWnd), "Equity", InfoColumnShift, 20 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i4H", RealWrkWnd), "Balance", InfoColumnShift, 30 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    if(СalcStartDep)  {Text(StringConcatenate("i5H", RealWrkWnd), StringConcatenate("Balance on  ", TTS(DateInfoStart + 1, TIME_DATE), "  ", DTS(StartDep, 2)), InfoColumnShift, 40 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);}
    Text(StringConcatenate("i6H", RealWrkWnd), "FreeMargin", InfoColumnShift, 50 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i7H", RealWrkWnd), "Deposit", InfoColumnShift, 60 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i8H", RealWrkWnd), "Withdrawal", InfoColumnShift, 70 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i9H", RealWrkWnd), "Profit", InfoColumnShift, 80 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i10H", RealWrkWnd), "Leverage", InfoColumnShift, 90 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i11H", RealWrkWnd), "Currency", InfoColumnShift, 100 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i12H", RealWrkWnd), "Type", InfoColumnShift, 110 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);

    Text(StringConcatenate("i3", RealWrkWnd), " ", InfoColumnShift + 0.75 * ColumnShift, 20 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i4", RealWrkWnd), " ", InfoColumnShift + 0.75 * ColumnShift, 30 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i6", RealWrkWnd), " ", InfoColumnShift + 0.75 * ColumnShift, 50 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i7", RealWrkWnd), DTS(AccStartDep, 2), InfoColumnShift + 0.75 * ColumnShift, 60 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    if(AccWithdrawal < 0.0)  {Text(StringConcatenate("i8", RealWrkWnd), DTS(-1 * AccWithdrawal, 2), InfoColumnShift + 0.75 * ColumnShift, 70 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);}
                       else  {Text(StringConcatenate("i8", RealWrkWnd), DTS(AccWithdrawal, 2), InfoColumnShift + 0.75 * ColumnShift, 70 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);}
    Text(StringConcatenate("i11", RealWrkWnd), AccountCurrency(), InfoColumnShift + 0.75 * ColumnShift, 100 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    if(IsDemo() || IsTesting())   {_tmptxt = "Demo account";}  else  {_tmptxt = "Real account";}
    Text(StringConcatenate("i12", RealWrkWnd),  _tmptxt, InfoColumnShift + 0.75 * ColumnShift, 110 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
         
    if(!BonusNeedShow)
    {
      if(Magiks == "") txt = "Magiс-numbers - Any";
      else  txt = StringConcatenate("Magiс-numbers - ", Magiks);
      Text(StringConcatenate("Magik", RealWrkWnd), txt, 780, 2, MainColor, FntSz8, RealWrkWnd);

      if(ShowCurrent)
      {
         Text(StringConcatenate("Current", RealWrkWnd), "Current:", 10 + StartColumnShift - ColumnShift, CurrStartRow, HeaderColor, FntSz10, RealWrkWnd);
         Text(StringConcatenate("Ordersf", RealWrkWnd), " ", 10 + StartColumnShift - ColumnShift, 15 + CurrStartRow, MainColor, FntSz8, RealWrkWnd);
         Text(StringConcatenate("Ordersfv", RealWrkWnd), " ", 10 + StartColumnShift - ColumnShift, 25 + CurrStartRow, MainColor, FntSz8, RealWrkWnd);
      }

      if(ShowHistory && HistNeedShow)
      {
         Text(StringConcatenate("History", RealWrkWnd), "History:", 10 + StartColumnShift - ColumnShift, HistStartRow, HeaderColor, FntSz10, RealWrkWnd);
         Text(StringConcatenate("Ordersh", RealWrkWnd), " ", 10 + StartColumnShift - ColumnShift, 15 + HistStartRow, MainColor, FntSz8, RealWrkWnd);
         Text(StringConcatenate("Ordershv", RealWrkWnd), " ", 10 + StartColumnShift - ColumnShift, 25 + HistStartRow, MainColor, FntSz8, RealWrkWnd);
      }

    }
  }

  if(!BonusNeedShow)
  {
    double ProfitAll = 0.0, ProfitAllSL = 0.0, SumBLot = 0.0, SumSLot = 0.0;
    int SumB = 0, SumS = 0, SumBp = 0, SumBl = 0, SumSp = 0, SumSl = 0,
        SumpB = 0, SumpS = 0, SumpBp = 0, SumpBl = 0, SumpSp = 0, SumpSl = 0;

//==================
//--- текущие ордера
//==================
    if(ShowCurrent)
    {
      tn = TekOrders();
      if(tn > 10000) {Alert("Buffers overflow", n_oct); 
      return(0);
      }
      ArrayInitialize(TekType, 0.0);
      ArrayInitialize(TekLot, 0.0);
      for(i = 0; i <= Nsymb; i++)
      {
        SymbolProfit[0][i] = 0.0;
        SymbolProfit[1][i] = 0.0;
        for(j = 0; j < tn; j++)
        {
          if(i == Orders[0][j])//Symbol
          {
            SymbolProfit[0][i] += Orders[2][j];//профит
            SymbolProfit[1][i] += Orders[5][j];//профит по StopLoss-у
            if(Orders[1][j] == OP_BUY)  {TekType[0][i]++; TekLot[0][i] += Orders[3][j];}
            if(Orders[1][j] == OP_SELL) {TekType[1][i]++; TekLot[1][i] += Orders[3][j];}
          }
        }
      }

      ProfitAll = 0.0;
      ProfitAllSL = 0.0;
      SumBLot = 0.0;
      SumSLot = 0.0;
      SumB = 0;
      SumS = 0;
      r2 = 1;
      i2 = -1;

      for(i = 0; i <= Nsymb; i++)
      {
        for(k = 0; k <= Nsymb; k++) {if(STI(Symbl[1][k]) == i)  {break;}}
        i2 ++;
        if(MaxMagiksSymbosInRow > 0 && i2 == MaxMagiksSymbosInRow) {i2 = 0; r2 ++;}
        if(StringLen(Symbl[0][k]) < 2) continue;
        Text(StringConcatenate(Symbl[0][k], "T",       RealWrkWnd), Symbl[0][k],                                                     StartColumnShift + ColumnShift * i2, CurrStartRow + (r2 - 1) * CurrRowHight, HeaderColor, FntSz10, RealWrkWnd);//символ
        Text(StringConcatenate(Symbl[0][k], "profitT", RealWrkWnd), DTS(SymbolProfit[0][k], 2),                                      StartColumnShift + ColumnShift * i2, 14 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(SymbolProfit[0][k]), FntSz10, RealWrkWnd);//профит
        if(ShowProfitByStopLoss)                //профит по текущему StopLoss
        {
          if(SymbolProfit[1][k] != 0.0) {Text(StringConcatenate(Symbl[0][k], "profitSLT", RealWrkWnd),   DTS(SymbolProfit[1][k], 2), StartColumnShift + ColumnShift * i2, 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(SymbolProfit[1][k]), FntSz10, RealWrkWnd);}
          else {Text(StringConcatenate(Symbl[0][k], "profitSLT", RealWrkWnd),   " ",                                                 StartColumnShift + ColumnShift * i2, 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(SymbolProfit[1][k]), FntSz10, RealWrkWnd);}
        }
        Text(StringConcatenate(Symbl[0][k], "Tlot", RealWrkWnd), "Type  Lot ",                                                       StartColumnShift + ColumnShift * i2, 40 + CurrStartRow + (r2 - 1) * CurrRowHight, HeaderColor, FntSz8, RealWrkWnd);
        Text(StringConcatenate(Symbl[0][k], "bT",  RealWrkWnd), StringConcatenate("B ", TekType[0][k], "    ", DTS(TekLot[0][k],2)), StartColumnShift + ColumnShift * i2, 52 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(SymbolProfit[0][k]), FntSz8, RealWrkWnd);//всего Buy
        Text(StringConcatenate(Symbl[0][k], "sT",  RealWrkWnd), StringConcatenate("S ", TekType[1][k], "    ", DTS(TekLot[1][k],2)), StartColumnShift + ColumnShift * i2, 62 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(SymbolProfit[0][k]), FntSz8, RealWrkWnd);//всего Sell
        ProfitAll   += SymbolProfit[0][k];
        ProfitAllSL += SymbolProfit[1][k];
        SumB += TekType[0][k];
        SumS += TekType[1][k];
        SumBLot += TekLot[0][k];
        SumSLot += TekLot[1][k];
         
        SymbolHistoryProfit[1][k] = MathMin(SymbolHistoryProfit[1][k], SymbolProfit[0][k]);
        if(SymbolHistoryProfit[2][k] > 0)  {SymbolHistoryProfit[2][k] = 0.0;}
        MaxSumDD = MathMin(MaxSumDD, MathMin(SymbolHistoryProfit[1][k], ProfitAll));
        if(MaxSumDD > 0.0)  {MaxSumDD = 0.0;}
        MaxSumDD1 = MathMin(MaxSumDD1, ProfitAll);
        if(MaxSumDD1 > 0.0)  {MaxSumDD1 = 0.0;}
        Today[1][0] = MathMin(MaxSumDD1, Today[1][0]);
        FreeMar = STD(DTS(AccountFreeMargin(), 2));
        MinFreeMar = MathMin(FreeMar, MinFreeMar);
        Today[2][0] = MathMin(FreeMar, Today[2][0]);
        if(Today[2][0] == 0.0)
        {
          MinFreeMar = AccBalance;
          FreeMar = AccBalance;
          Today[2][0] = AccBalance;
        }

        SymbolHistoryProfit[2][k] = SymbolProfit[0][k];
        if(SymbolHistoryProfit[2][k] > 0.0)  {SymbolHistoryProfit[2][k] = 0.0;}
        CurSumDD = MathMin(ProfitAll, CurSumDD);
        if(CurSumDD > 0.0)  {CurSumDD = 0.0;}
      }
      
      i2 ++;
      Text("TotalCurr"   + RealWrkWnd, "Total:", StartColumnShift + ColumnShift * i2, CurrStartRow + (r2 - 1) * CurrRowHight, HeaderColor, FntSz10, RealWrkWnd);
      if((tn + hn) > 0 || (SumBLot + SumSLot) > 0.0)
      {
        Text("profitAllT"  + RealWrkWnd, DTS(ProfitAll, 2), StartColumnShift + ColumnShift * i2, 14 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz10, RealWrkWnd);//общий профит
        if(StartDep != 0) {Text("profitAllT%" + RealWrkWnd, StringConcatenate(DTS(100 * ProfitAll/StartDep, 2), "%"), StartColumnShift + ColumnShift * (i2 + 0.9), 14 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz10, RealWrkWnd);}//общий профит%

        Text("TSumLot"     + RealWrkWnd, "Type  Lot ",                                                              StartColumnShift + ColumnShift * i2, 40 + CurrStartRow + (r2 - 1) * CurrRowHight, HeaderColor, FntSz8, RealWrkWnd);//всего Buy
        Text("TSumBLot"    + RealWrkWnd, StringConcatenate("B ", SumB, "    ", DTS(SumBLot, 2)),            StartColumnShift + ColumnShift * i2, 52 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);
        Text("TSumSLot"    + RealWrkWnd, StringConcatenate("S ", SumS, "    ", DTS(SumSLot, 2)),            StartColumnShift + ColumnShift * i2, 62 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);
        if(SumB + SumS > 0)  {Text("TSumLotT"    + RealWrkWnd, StringConcatenate(SumB + SumS, "    ", DTS(SumBLot + SumSLot, 2)), StartColumnShift + ColumnShift * (i2 + 0.9), 56 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);}
        if(ShowProfitByStopLoss)//общий профит по StopLoss-ам
        {
          if(ProfitAllSL != 0.0)
          {
            Text("profitAllSLT" + RealWrkWnd, DTS(ProfitAllSL, 2), StartColumnShift + ColumnShift * i2, 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAllSL), FntSz10, RealWrkWnd);
            if(StartDep != 0.0) {Text("profitAllSLT%" + RealWrkWnd, StringConcatenate(DTS(100 * ProfitAllSL / StartDep, 2), "%"), StartColumnShift + ColumnShift * (i2 + 0.9), 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAllSL), FntSz10, RealWrkWnd);}
          }
          else
          {
            Text("profitAllSLT"  + RealWrkWnd, " ", StartColumnShift + ColumnShift * i2, 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAllSL), FntSz10, RealWrkWnd);
            Text("profitAllSLT%" + RealWrkWnd, " ", StartColumnShift + ColumnShift * (i2 + 0.9), 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAllSL), FntSz10, RealWrkWnd);
          }
        }
      }
      else
      {
        Text("profitAllT%"   + RealWrkWnd, " ", StartColumnShift + ColumnShift * i2, 14 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz10, RealWrkWnd);//общий профит
        Text("profitAllSLT"  + RealWrkWnd, " ", StartColumnShift + ColumnShift * i2, 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAllSL), FntSz10, RealWrkWnd);
        Text("profitAllSLT%" + RealWrkWnd, " ", StartColumnShift + ColumnShift * (i2 + 0.9), 26 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAllSL), FntSz10, RealWrkWnd);
        Text("TSumLotT"      + RealWrkWnd, " ", StartColumnShift + ColumnShift * (i2 + 0.9), 56 + CurrStartRow + (r2 - 1) * CurrRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);
      }

      if((n_oct - tn) > 0)
      {
        ObjectSetText("Ordersf" + RealWrkWnd, StringConcatenate("Orders ", tn, "+", n_oct - tn), FntSz8, Font, MainColor);
        ObjectSetText("Ordersfv" + RealWrkWnd, StringConcatenate("Lots ", DTS(SumBLot + SumSLot, 2)), FntSz8, Font, MainColor);
      }
      else
      {
        ObjectSetText("Ordersf" + RealWrkWnd, StringConcatenate("Orders ", tn), FntSz8, Font, MainColor);
        ObjectSetText("Ordersfv" + RealWrkWnd, StringConcatenate("Lots ", DTS(SumBLot + SumSLot, 2)), FntSz8, Font, MainColor);
      }
    }

//==================
//--- история
//==================
    ProfitAll = 0.0; ProfitAllSL = 0.0; SumBLot = 0.0; SumSLot = 0.0;
    SumB = 0; SumS = 0; SumBp = 0; SumBl = 0; SumSp = 0; SumSl = 0;
    SumpB = 0; SumpS = 0; SumpBp = 0; SumpBl = 0; SumpSp = 0; SumpSl = 0;
    r2 = 1;
    i2 = -1;

    if(ShowHistory)
    {
      if(HistNeedShow)
      {
        hn = HistoryOrders();
        if(hn > 10000) {Alert("Buffers overflow", n_oht); 
        return(0);
        }
        ArrayInitialize(HistoryType, 0.0);
        ArrayInitialize(HistoryLot, 0.0);
        for(i = 0; i <= Nsymb; i++)
        {                                               
          SymbolHistoryProfit[0][i] = 0;
          for(j = 0; j < hn; j++)
          {
            if(i == HistoryOrders[0][j])//Symbol
            {
              SymbolHistoryProfit[0][i] += HistoryOrders[2][j];//профит 
              if(HistoryOrders[1][j] == OP_BUY)  {HistoryType[0][i]++; HistoryLot[0][i] += HistoryOrders[3][j];}
              if(HistoryOrders[1][j] == OP_SELL) {HistoryType[1][i]++; HistoryLot[1][i] += HistoryOrders[3][j];}
            }
          }
        }

        for(i = 0; i <= Nsymb; i++)
        {  
          for(k = 0; k <= Nsymb; k++) {if(STI(Symbl[1][k]) == i)  {break;}}
          i2 ++;
          if(MaxMagiksSymbosInRow > 0 && i2 == MaxMagiksSymbosInRow) {i2 = 0; r2 ++;}
          ProfitAll += SymbolHistoryProfit[0][k];
          SumB += HistoryType[0][k];
          SumS += HistoryType[1][k];
          SumBLot += HistoryLot[0][k];
          SumSLot += HistoryLot[1][k];

          if (StringLen(Symbl[0][k]) < 2) continue;
          Text(Symbl[0][k] + RealWrkWnd, Symbl[0][k],                                                                                                          StartColumnShift + ColumnShift * i2, HistStartRow + (r2 - 1) * HistRowHight, HeaderColor, FntSz10, RealWrkWnd);//символ
          Text(StringConcatenate(Symbl[0][k], "Hprofit", RealWrkWnd), DTS(SymbolHistoryProfit[0][k], 2),                                            StartColumnShift + ColumnShift * i2, 15 + HistStartRow + (r2 - 1) * HistRowHight, Color(SymbolHistoryProfit[0][k]), FntSz9, RealWrkWnd);//профит
          Text(StringConcatenate(Symbl[0][k], "Hlot",    RealWrkWnd), "Type  Lot ",                                                                         StartColumnShift + ColumnShift * i2, 28 + HistStartRow + (r2 - 1) * HistRowHight, HeaderColor, FntSz8, RealWrkWnd);
          Text(StringConcatenate(Symbl[0][k], "Hb",      RealWrkWnd), StringConcatenate("B ", HistoryType[0][k], "    ", DTS(HistoryLot[0][k], 2)), StartColumnShift + ColumnShift * i2, 40 + HistStartRow + (r2 - 1) * HistRowHight, Color(SymbolHistoryProfit[0][k]), FntSz8, RealWrkWnd);//всего Buy
          Text(StringConcatenate(Symbl[0][k], "Hs",      RealWrkWnd), StringConcatenate("S ", HistoryType[1][k], "    ", DTS(HistoryLot[1][k], 2)), StartColumnShift + ColumnShift * i2, 50 + HistStartRow + (r2 - 1) * HistRowHight, Color(SymbolHistoryProfit[0][k]), FntSz8, RealWrkWnd);//всего Sell

          if(LogInfoToFile)
          {
            Text(StringConcatenate(Symbl[0][k], "HMDD",    RealWrkWnd), "Max drawdown",                                                                    StartColumnShift + ColumnShift * i2, 62 + HistStartRow + (r2 - 1) * HistRowHight, HeaderColor, FntSz8, RealWrkWnd);
            Text(StringConcatenate(Symbl[0][k], "HMDDp",   RealWrkWnd), DTS(SymbolHistoryProfit[1][k], 2),                                         StartColumnShift + ColumnShift * i2, 74 + HistStartRow + (r2 - 1) * HistRowHight, Color(SymbolHistoryProfit[0][k]), FntSz8, RealWrkWnd);
          }
        }

        i2 ++;
        Text("symbolAll"  + RealWrkWnd, "Total:",                                                                                         StartColumnShift + ColumnShift * i2, HistStartRow + (r2 - 1) * HistRowHight, HeaderColor, FntSz10, RealWrkWnd);//шапка
        if((hn + tn) > 0)
        {
          Text("profitAll"  + RealWrkWnd, DTS(ProfitAll, 2),                                                                        StartColumnShift + ColumnShift * i2, 15 + HistStartRow + (r2 - 1) * HistRowHight, Color(ProfitAll), FntSz10, RealWrkWnd);//общий профит
          if(StartDep != 0.0 && (SumB + SumS > 0)) {Text("profitAll%" + RealWrkWnd, StringConcatenate(DTS(100 * ProfitAll / StartDep, 2), "%"),          StartColumnShift + ColumnShift * (i2 + 0.9), 15 + HistStartRow + (r2 - 1) * HistRowHight, Color(ProfitAll), FntSz10, RealWrkWnd);}//общий профит
          Text("SumLot"     + RealWrkWnd, "Type  Lot ",                                                                                     StartColumnShift + ColumnShift * i2, 28 + HistStartRow + (r2 - 1) * HistRowHight, HeaderColor, FntSz8, RealWrkWnd);//всего Buy
          Text("SumBLot"    + RealWrkWnd, StringConcatenate("B ", SumB, "    ", DTS(SumBLot, 2)),                                   StartColumnShift + ColumnShift * i2, 40 + HistStartRow + (r2 - 1) * HistRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);
          Text("SumSLot"    + RealWrkWnd, StringConcatenate("S ", SumS, "    ", DTS(SumSLot, 2)),                                   StartColumnShift + ColumnShift * i2, 50 + HistStartRow + (r2 - 1) * HistRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);
          if(SumB + SumS > 0)  {Text("SumLotT"    + RealWrkWnd, StringConcatenate(SumB + SumS, "    ", DTS(SumBLot + SumSLot, 2)), StartColumnShift + ColumnShift * (i2 + 0.9), 45 + HistStartRow + (r2 - 1) * HistRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);}
          if(LogInfoToFile)
          {
            Text(StringConcatenate("HMDDsum",    RealWrkWnd), "Max drawdown",                                                    StartColumnShift + ColumnShift * i2, 62 + HistStartRow + (r2 - 1) * HistRowHight, HeaderColor, FntSz8, RealWrkWnd);
            Text(StringConcatenate("HMDDpsum",   RealWrkWnd), DTS(MaxSumDD, 2),                                          StartColumnShift + ColumnShift * i2, 74 + HistStartRow + (r2 - 1) * HistRowHight, Color(ProfitAll), FntSz8, RealWrkWnd);
          }
        }
        ObjectSetText("Ordersh" + RealWrkWnd, StringConcatenate("Orders ", hn), FntSz8, Font, MainColor);
        ObjectSetText("Ordershv" + RealWrkWnd, StringConcatenate("Lots ", DTS(SumBLot + SumSLot, 2)), FntSz8, Font, MainColor);

        RowShift3 = 0;
        if(!SumNeedShow)
        {
          Text(StringConcatenate("ShSum", RealWrkWnd), "Show summary info", InfoColumnShift, ButtonStartRow + 30, HeaderColor, FntSz10, RealWrkWnd);
        }
        else
        {
          if((TCurr - DetailShowTime) / 60 >= ShowInfoDuration) {Text(StringConcatenate("ShSum", RealWrkWnd), "Hide summary info", InfoColumnShift, ButtonStartRow + 31, HeaderColor, FntSz10, RealWrkWnd);}
          else {Text(StringConcatenate("ShSum", RealWrkWnd), "Hide summary info", InfoColumnShift, ButtonStartRow + 30, HeaderColor, FntSz10, RealWrkWnd);}
          Text(StringConcatenate("SSumm", RealWrkWnd), "Summary:", 10 + StartColumnShift - ColumnShift, MagStartRow, HeaderColor, FntSz10, RealWrkWnd);

          Text(StringConcatenate("SumH0", RealWrkWnd), "From date", StartColumnShift, MagStartRow, HeaderColor, FntSz10, RealWrkWnd);
          Text(StringConcatenate("SumH1", RealWrkWnd), "Orders", StartColumnShift + 1 * ColumnShift, MagStartRow, HeaderColor, FntSz10, RealWrkWnd);
          Text(StringConcatenate("SumH2", RealWrkWnd), "Pips", StartColumnShift + 2 * ColumnShift, MagStartRow, HeaderColor, FntSz10, RealWrkWnd);
          Text(StringConcatenate("SumH3", RealWrkWnd), "Lots", StartColumnShift + 3 * ColumnShift, MagStartRow, HeaderColor, FntSz10, RealWrkWnd);
          Text(StringConcatenate("SumH4", RealWrkWnd), "Profit/Loss", StartColumnShift + 4 * ColumnShift, MagStartRow, HeaderColor, FntSz10, RealWrkWnd);

          j = -1;
          for(i = 0; i <= 5; i++)
          {
            if(Summary[i][0] != 0.0 && Summary[i][0] >= Summary[5][0])
            {
              j ++;
              Text(StringConcatenate("SumV", i, "0", RealWrkWnd), TTS(Summary[i][0], TIME_DATE), StartColumnShift, MagStartRow + (j + 1) * 13, Color(Summary[i][4]), FntSz10, RealWrkWnd);
              Text(StringConcatenate("SumV", i, "1", RealWrkWnd), DTS(Summary[i][1], 0), StartColumnShift + 1 * ColumnShift, MagStartRow + (j + 1) * 13, Color(Summary[i][4]), FntSz10, RealWrkWnd);
              Text(StringConcatenate("SumV", i, "2", RealWrkWnd), DTS(Summary[i][2], 0), StartColumnShift + 2 * ColumnShift, MagStartRow + (j + 1) * 13, Color(Summary[i][4]), FntSz10, RealWrkWnd);
              Text(StringConcatenate("SumV", i, "3", RealWrkWnd), DTS(Summary[i][3], 2), StartColumnShift + 3 * ColumnShift, MagStartRow + (j + 1) * 13, Color(Summary[i][4]), FntSz10, RealWrkWnd);
              Text(StringConcatenate("SumV", i, "4", RealWrkWnd), DTS(Summary[i][4], 2), StartColumnShift + 4 * ColumnShift, MagStartRow + (j + 1) * 13, Color(Summary[i][4]), FntSz10, RealWrkWnd);
              Text(StringConcatenate("SumV", i, "5", RealWrkWnd), DTS(100 * (Summary[i][4] / Summary[i][5]), 2) + "%", StartColumnShift + 5 * ColumnShift, MagStartRow + (j + 1) * 13, Color(Summary[i][4]), FntSz10, RealWrkWnd);
            }
          }
          RowShift3 = (j + 2) * 13 + 5;
        }
            
        if(ShowMagics && (hn + tn) > 0)
        {
          if(!MagNeedShow)
          {
           Text(StringConcatenate("ShMag", RealWrkWnd), "Show magics info", InfoColumnShift, ButtonStartRow + 15, MainColor, FntSz10, RealWrkWnd);
          }
          else
          {
            if(ScanFromToday && (TCurr - DetailShowTime) / 60 >= ShowInfoDuration) {Text(StringConcatenate("ShMag", RealWrkWnd), "Hide magics info", InfoColumnShift, ButtonStartRow + 16, MainColor, FntSz10, RealWrkWnd);}
            else {Text(StringConcatenate("ShMag", RealWrkWnd), "Hide magics info", InfoColumnShift, ButtonStartRow + 15, MainColor, FntSz10, RealWrkWnd);}
            Text(StringConcatenate("MagikP", RealWrkWnd), "Magic №:", 10 + StartColumnShift - ColumnShift, MagStartRow + RowShift3, HeaderColor, FntSz10, RealWrkWnd);
            ProfitAll = 0;
            SumBLot = 0.0;
            SumSLot = 0.0;
            SumB = 0;
            SumS = 0;
            SumpB = 0;
            SumpS = 0;
            r2 = 1;
            i2 = -1;

            for(i = 0; i <= Nmag; i++)
            {
              for(k = 0; k <= Nsymb; k++) {if(Magik[1][k] == i)  {break;}}
              if(Magik[0, k] < 0) {continue;}
              i2 ++;
              if(MaxMagiksSymbosInRow > 0 && i2 == MaxMagiksSymbosInRow) {i2 = 0; r2 ++;}
              Text(StringConcatenate(Magik[0, k], "M",       RealWrkWnd), DTS(Magik[0, k], 0),       StartColumnShift + ColumnShift * i2, MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz10, RealWrkWnd);//символ
              Text(StringConcatenate(Magik[0, k], "profitM", RealWrkWnd), DTS(MagikProfit[0][k], 2), StartColumnShift + ColumnShift * i2, 12 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz10, RealWrkWnd);//профит
              ProfitAll += MagikProfit[0][k];

              if(ShowMagicsDetails)
              {
                SumBp += MagikProfit[1][k];
                SumBl += MagikProfit[2][k];
                SumSp += MagikProfit[3][k];
                SumSl += MagikProfit[4][k];
                SumB += (MagikProfit[1][k] + MagikProfit[2][k]);
                SumS += (MagikProfit[3][k] + MagikProfit[4][k]);
                SumpBp += MagikProfit[5][k];
                SumpBl += MagikProfit[6][k];
                SumpSp += MagikProfit[7][k];
                SumpSl += MagikProfit[8][k];
                SumBLot += MagikProfit[9][k];
                SumSLot += MagikProfit[10][k];
                SumpB += (MagikProfit[5][k] + MagikProfit[6][k]);
                SumpS += (MagikProfit[7][k] + MagikProfit[8][k]);
                Text(StringConcatenate(Magik[0, k], "Mlot",    RealWrkWnd), "Type  Lot ",                                                                                                                                   StartColumnShift + ColumnShift * i2, 25  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz8, RealWrkWnd);
                Text(StringConcatenate(Magik[0, k], "Mb",      RealWrkWnd), StringConcatenate("B ", MagikProfit[1][k] + MagikProfit[2][k], "    ", DTS(MagikProfit[9][k], 2)),                                              StartColumnShift + ColumnShift * i2, 37  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz8, RealWrkWnd);//всего Buy
                Text(StringConcatenate(Magik[0, k], "Ms",      RealWrkWnd), StringConcatenate("S ", MagikProfit[3][k] + MagikProfit[4][k], "    ", DTS(MagikProfit[10][k], 2)),                                             StartColumnShift + ColumnShift * i2, 47  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz8, RealWrkWnd);//всего Sell
                Text(StringConcatenate(Magik[0, k], "Mdeto",   RealWrkWnd), "Orders (P/L)",                                                                                                                                 StartColumnShift + ColumnShift * i2, 59  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz8, RealWrkWnd);
                Text(StringConcatenate(Magik[0, k], "Mdetocb", RealWrkWnd), StringConcatenate("B ", DTS(MagikProfit[1][k] + MagikProfit[2][k], 0), "   (", DTS(MagikProfit[1][k], 0), "/", DTS(MagikProfit[2][k], 0),")"),  StartColumnShift + ColumnShift * i2, 71  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz8, RealWrkWnd);
                Text(StringConcatenate(Magik[0, k], "Mdetocs", RealWrkWnd), StringConcatenate("S ", DTS(MagikProfit[3][k] + MagikProfit[4][k], 0), "   (", DTS(MagikProfit[3][k], 0), "/", DTS(MagikProfit[4][k], 0),")"),  StartColumnShift + ColumnShift * i2, 81  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz8, RealWrkWnd);
                Text(StringConcatenate(Magik[0, k], "Mdetp",   RealWrkWnd), "Pips (P/L)",                                                                                                                                   StartColumnShift + ColumnShift * i2, 93  + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz8, RealWrkWnd);
                Text(StringConcatenate(Magik[0, k], "Mdetpcb", RealWrkWnd), StringConcatenate("B ", DTS(MagikProfit[5][k] + MagikProfit[6][k], 0), " (", DTS(MagikProfit[5][k], 0), "/", DTS(MagikProfit[6][k], 0),")"),    StartColumnShift + ColumnShift * i2, 105 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz8, RealWrkWnd);
                Text(StringConcatenate(Magik[0, k], "Mdetpcs", RealWrkWnd), StringConcatenate("S ", DTS(MagikProfit[7][k] + MagikProfit[8][k], 0), " (", DTS(MagikProfit[7][k], 0), "/", DTS(MagikProfit[8][k], 0),")"),    StartColumnShift + ColumnShift * i2, 115 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(MagikProfit[0][k]), FntSz8, RealWrkWnd);
              }
            }

            i2 ++;
            Text("magAll" +                                 RealWrkWnd, "Total:",                                                                                                                                                                            StartColumnShift + ColumnShift * i2, MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz10, RealWrkWnd);//шапка
            Text("profitAllM" +                             RealWrkWnd, DTS(ProfitAll, 2),                                                                                                                                                                   StartColumnShift + ColumnShift * i2, 12 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz10, RealWrkWnd);//общий профит
            if(StartDep != 0.0) {Text("profitAllM%" + RealWrkWnd, StringConcatenate(DTS(100 * ProfitAll / StartDep, 2), "%"),                                                                                                                                StartColumnShift + ColumnShift * (i2 + 1), 12 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz10, RealWrkWnd);}//общий профит
            if(ShowMagicsDetails)
            {
              Text(StringConcatenate(Magik[0, k], "Mdetlall",   RealWrkWnd), "Type  Lot ",                                                                                                                                                                   StartColumnShift + ColumnShift * i2, 25 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz8, RealWrkWnd);
              Text(StringConcatenate("MITdetlcb", RealWrkWnd), StringConcatenate("B ", DTS(SumB, 0), "    ", DTS(SumBLot, 2)),                                                                                                                               StartColumnShift + ColumnShift * i2, 37 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);
              Text(StringConcatenate("MITdetlcs", RealWrkWnd), StringConcatenate("S ", DTS(SumS, 0), "    ", DTS(SumSLot, 2)),                                                                                                                               StartColumnShift + ColumnShift * i2, 47 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);
              if(SumB + SumS > 0)  {Text(StringConcatenate("MITdetlc",  RealWrkWnd), StringConcatenate(SumB + SumS, "    ", DTS(SumBLot + SumSLot, 2)),                                                                                                      StartColumnShift + ColumnShift * (i2 + 1), 42 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
              Text(StringConcatenate(Magik[0, k], "Mdetall",   RealWrkWnd), "Orders (P/L)",                                                                                                                                                                  StartColumnShift + ColumnShift * i2, 59 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz8, RealWrkWnd);
              Text(StringConcatenate("MITdetocb", RealWrkWnd), StringConcatenate("B ", DTS(SumB, 0), "   (", SumBp, "/", SumBl, ")"),                                                                                                                        StartColumnShift + ColumnShift * i2, 71 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);
              Text(StringConcatenate("MITdetocs", RealWrkWnd), StringConcatenate("S ", DTS(SumS, 0), "   (", SumSp, "/", SumSl, ")"),                                                                                                                        StartColumnShift + ColumnShift * i2, 81 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);
              if(SumB != 0.0) {Text(StringConcatenate("MITdetocb%", RealWrkWnd), StringConcatenate("", DTS(MathRound(10000 * SumBp / SumB) / 100, 2), "%"),                                                                                                  StartColumnShift + ColumnShift * (i2 + 1), 71 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
                         else {Text(StringConcatenate("MITdetocb%", RealWrkWnd), StringConcatenate("", "   0.00", "%"),                                                                                                                                      StartColumnShift + ColumnShift * (i2 + 1), 71 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
              if(SumS != 0.0) {Text(StringConcatenate("MITdetocs%", RealWrkWnd), StringConcatenate("", DTS(MathRound(10000 * SumSp / SumS) / 100, 2), "%"),                                                                                                  StartColumnShift + ColumnShift * (i2 + 1), 81 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
                         else {Text(StringConcatenate("MITdetocs%", RealWrkWnd), StringConcatenate("", "   0.00", "%"),                                                                                                                                      StartColumnShift + ColumnShift * (i2 + 1), 81 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
              if((SumB + SumS) != 0.0) {Text(StringConcatenate("MITdetocall", RealWrkWnd), StringConcatenate(DTS(SumB + SumS, 0), " (", SumBp + SumSp, "/", SumBl + SumSl, ") ", DTS(MathRound(10000 * (SumBp + SumSp) / (SumB + SumS)) / 100, 2), "%"),     StartColumnShift + ColumnShift * (i2 + 1.6), 75 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
                                  else {Text(StringConcatenate("MITdetocall", RealWrkWnd), StringConcatenate("", "   0.00", "%"),                                                                                                                            StartColumnShift + ColumnShift * (i2 + 1.6), 75 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
              Text(StringConcatenate(Magik[0, k], "Mdetpall",   RealWrkWnd), "Pips (P/L)",                                                                                                                                                                      StartColumnShift + ColumnShift * i2, 93 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, HeaderColor, FntSz8, RealWrkWnd);
              Text(StringConcatenate("MITdetpcb", RealWrkWnd), StringConcatenate("B ", DTS(SumpB, 0), " (", SumpBp, "/", SumpBl, ")"),                                                                                                                       StartColumnShift + ColumnShift * i2, 105 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);
              Text(StringConcatenate("MITdetpcs", RealWrkWnd), StringConcatenate("S ", DTS(SumpS, 0), " (", SumpSp, "/", SumpSl, ")"),                                                                                                                       StartColumnShift + ColumnShift * i2, 115 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);
              if((SumpB + SumpS) != 0.0) {Text(StringConcatenate("MITdetpcAll", RealWrkWnd), StringConcatenate(DTS(SumpB + SumpS, 0), " (", SumpBp + SumpSp, "/", SumpBl + SumpSl, ") "),                                                                    StartColumnShift + ColumnShift * (i2 + 1), 110 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
                                    else {Text(StringConcatenate("MITdetpcAll", RealWrkWnd), StringConcatenate("", ""),                                                                                                                                      StartColumnShift + ColumnShift * (i2 + 1), 110 + MagStartRow + (r2 - 1) * MagRowHight + RowShift3, Color(ProfitAll), FntSz8, RealWrkWnd);}
            }
          }
        }

        if(ShowLast10Days)
        {
          if(!L10NeedShow)
          {
           Text(StringConcatenate("ShL10", RealWrkWnd), "Show last 10 trade days", InfoColumnShift, ButtonStartRow, HeaderColor, FntSz10, RealWrkWnd);
          }
          else
          {
            if(ScanFromToday && (TCurr - DetailShowTime) / 60 >= ShowInfoDuration) {Text(StringConcatenate("ShL10", RealWrkWnd), "Hide last 10 trade days", InfoColumnShift, ButtonStartRow + 1, HeaderColor, FntSz10, RealWrkWnd);}
            else {Text(StringConcatenate("ShL10", RealWrkWnd), "Hide last 10 trade days", InfoColumnShift, ButtonStartRow, HeaderColor, FntSz10, RealWrkWnd);}

            RowShift2 = 0;
            ColumnShift2 = 0;
            if(Nsymb > 3 && (Nsymb - Nmag) > 2 && Last10DaysAutoPlace && ShowMagicsDetails)
            {
              if(ShowMagics && MagNeedShow) {i = Nmag + 3; ColumnShift2 = 0.4 * ColumnShift;}
              else  {i = -1; ColumnShift2 = 0.4 * ColumnShift;}
              if(ShowCurrent) {RowShift2 = (MagStartRow + RowShift3) - CurrStartRow + RowShift;}
              else  {RowShift2 = MagStartRow - CurrStartRow;}
            }
            else  {i = Nsymb + 2; ColumnShift2 = 0.4 * ColumnShift;}

            LtenStartRow = CurrStartRow + RowShift2;

            Text("YesterdaysT" + RealWrkWnd, "Last 10 days   Profit/Loss", StartColumnShift + ColumnShift2 + ColumnShift * (i + 0.6), LtenStartRow, HeaderColor, FntSz10, RealWrkWnd);
            if(LogInfoToFile)
            {
              Text("YesterdaysDD" + RealWrkWnd, "Max drawdown", StartColumnShift + ColumnShift2 + ColumnShift * (i + 3.5), LtenStartRow, HeaderColor, FntSz10, RealWrkWnd);
              Text("YesterdaysFM" + RealWrkWnd, "Min freemar.", StartColumnShift + ColumnShift2 + ColumnShift * (i + 5.5), LtenStartRow, HeaderColor, FntSz10, RealWrkWnd);
            }
            for(j = 0; j < 10; j++)
            { 
              Text("Yesterday"    + RealWrkWnd + j, StringConcatenate(TTS(iTime(NULL, PERIOD_D1, j),TIME_DATE), "     ", DTS(Today[0][j], 2)), StartColumnShift + ColumnShift2 + ColumnShift * (i + 0.6), 12 * (j + 1) + LtenStartRow, Color(Today[0][j]), FntSz10, RealWrkWnd);
              if(StartDep != 0.0) {Text("Yesterday%" + RealWrkWnd + j, StringConcatenate(DTS(100 * Today[0][j] / StartDep, 1), "%"), StartColumnShift + ColumnShift2 + ColumnShift * (i + 1) + 140, 12 * (j + 1) + LtenStartRow, Color(Today[0][j]), FntSz10, RealWrkWnd);}
              if(LogInfoToFile)
              {
                Text("YesterdayDD"  + RealWrkWnd + j, StringConcatenate("", DTS(Today[1][j], 2)), StartColumnShift + ColumnShift2 + ColumnShift * (i + 3.5), 12 * (j + 1) + LtenStartRow, Color(Today[0][j]), FntSz10, RealWrkWnd);
                if(StartDep != 0.0) {Text("YesterdayDD%" + RealWrkWnd + j, StringConcatenate(DTS(100 * Today[1][j] / StartDep, 1), "%"), StartColumnShift + ColumnShift2 + ColumnShift * (i + 3.5) + 70, 12 * (j + 1) + LtenStartRow, Color(Today[0][j]), FntSz10, RealWrkWnd);}
                Text("YesterdayFM"  + RealWrkWnd + j, StringConcatenate("", DTS(Today[2][j], 2)), StartColumnShift + ColumnShift2 + ColumnShift * (i + 5.5), 12 * (j + 1) + LtenStartRow, Color(Today[0][j]), FntSz10, RealWrkWnd);
              }
            }
          }
        }
      }
    }
  }

//---
  AccEquity = AccountEquity();
  AccProfit = AccountBalance() - AccStartDep - AccWithdrawal;
  AccBalance = AccountBalance();
  
  Text(StringConcatenate("i10", RealWrkWnd), StringConcatenate("1:", DTS(10 * MathRound(MarketInfo(AccLeverageSymbol, MODE_LOTSIZE) * (MarketInfo(AccLeverageSymbol, MODE_ASK) / MarketInfo(AccLeverageSymbol, MODE_MARGINREQUIRED)) / 10), 0)), InfoColumnShift + 0.75 * ColumnShift, 90 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
  if(tn > 0)
  {
    Text(StringConcatenate("i2H", RealWrkWnd), "Symbols", InfoColumnShift, 10 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i2", RealWrkWnd), DTS(Nsymb + 1, 0), InfoColumnShift + 0.75 * ColumnShift, 10 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
  }        
  else
  {
    Text(StringConcatenate("i2H", RealWrkWnd), "No open orders found", InfoColumnShift, 10 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
    Text(StringConcatenate("i2", RealWrkWnd), " ", InfoColumnShift + 0.75 * ColumnShift, 10 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);
  }        
  ObjectSetText("i3" + RealWrkWnd, DTS(AccEquity, 2), FntSz8, Font, MainColor);
  ObjectSetText("i4" + RealWrkWnd, DTS(AccBalance, 2), FntSz8, Font, MainColor);
  if(AccountMargin() != 0.0) {ObjectSetText("i6" + RealWrkWnd, StringConcatenate(DTS(FreeMar, 2), " (", DTS(100 * AccEquity / AccountMargin(), 2), "%)"), FntSz8, Font, MainColor);}
                        else {ObjectSetText("i6" + RealWrkWnd, DTS(AccEquity, 2), FntSz8, Font, MainColor);}
  Text(StringConcatenate("i9", RealWrkWnd), DTS(AccProfit, 2), InfoColumnShift + 0.75 * ColumnShift, 80 + InfoStartRow, MainColor, FntSz8, RealWrkWnd);

  if(LogInfoToFile && LogEnable && LogFileHandle > 0)
  {
    if(CandleTime < Time[0] && LastLoggedCandle < Time[0])
    {
      for(i = 0; i <= Nsymb; i++)
      {
        string SimbMaxDD = StringConcatenate(Symbl[0][i], ";", DTS(SymbolHistoryProfit[1][i], 2));
        if(i < Nsymb) {SimbMaxDD = StringConcatenate(SimbMaxDD, ";");}
      }
      for(i = 0; i <= Nsymb; i++)
      {
        string SimbDD = StringConcatenate("c", Symbl[0][i], ";", DTS(SymbolHistoryProfit[2][i], 2));
        if(i < Nsymb) {SimbDD = StringConcatenate(SimbDD, ";");}
      }
      if(FreeMar > 0) {FileWrite(LogFileHandle, "Time", TTS(Time[1]), "AccN", AccountNumber(), "AccBal", AccBalance, "AccEq", AccEquity, "AccPr", AccProfit, SimbMaxDD, SimbDD, "MaxDD", MaxSumDD, "MaxDayDD", MaxSumDD1, "CurDD", CurSumDD, "FMar", FreeMar, "HI_NewCandle");}
      else   {FileWrite(LogFileHandle, "Time", TTS(Time[1]), "AccN", AccountNumber(), "AccBal", AccBalance, "AccEq", AccEquity, "AccPr", AccProfit, SimbMaxDD, SimbDD, "MaxDD", MaxSumDD, "MaxDayDD", MaxSumDD1, "CurDD", CurSumDD, "HI_NewCandle");}
      FileFlush(LogFileHandle); 

      CandleTime = Time[0];
      LastLoggedCandle = Time[0];
    }
  }

  return(0);
}
//--------------------------------------------------------------------
int SymbolNum(string Symb)
{
  for(int i = 0; i < 100; i++)
  {                                               
    if(Symb == Symbl[0][i]) return(i);
    if(StringLen(Symbl[0][i]) < 2) break;
  }
  Symbl[0][i] = Symb;
  Nsymb = i;
  if(i == 0)  {Symbl[1][i] = 0;}
  else
  {
    int j, srt = 0, mx;
    for(j = 0; j <= Nsymb; j ++)  {Symbl[1][j] = "-1";}
    while(srt <= Nsymb)
    {
      for(j = 0; j <= Nsymb; j ++)
      {
        if(StringLen(Symbl[0][j]) >= 2 && Symbl[1][j] == "-1")
        {
          mx = j;
          break;
        }
      }

      for(j = 0; j <= Nsymb; j ++)
      {
        if(mx != j && Symbl[1][j] == "-1" && StringLen(Symbl[0][j]) >= 2)
        {
          if(Symbl[0][j] < Symbl[0][mx]) {mx = j;}    //раньше по алфавиту
        }
      }
      Symbl[1][mx] = srt;
      srt ++;
    }
  }

  if(MaxMagiksSymbosInRow > 0) 
  {
    if(MathFloor(Nsymb / MaxMagiksSymbosInRow) > 0.0)
    {
      HistStartRow = HistStartRowBase + RowShift + MathFloor(Nsymb / MaxMagiksSymbosInRow) * CurrRowHight;
      MagStartRow = MagStartRowBase + RowShift + MathFloor(Nsymb / MaxMagiksSymbosInRow) * (CurrRowHight + HistRowHight);
    }
  }

  if(LogInfoToFile && LogEnable && LogFileHandle > 0)
  {
    if(FileSize(LogFileHandle) > 0)
    {
      int InitFilePos = MathRound(FileTell(LogFileHandle));
      FileSeek(LogFileHandle, 0, SEEK_SET);
      double SymbMDD = 0.0;
      string TmpLoggedStr;

      while(!FileIsEnding(LogFileHandle))
      {
        if(FileReadString(LogFileHandle) == Symb)
        {
          SymbMDD = STD(FileReadString(LogFileHandle));
          if(SymbolHistoryProfit[1][i] > SymbMDD && SymbMDD < 0) {SymbolHistoryProfit[1][i] = SymbMDD;}
        }
      }         
      FileSeek(LogFileHandle, InitFilePos, SEEK_SET);
    }
  }
  return(i);
}
//--------------------------------------------------------------------
int MagikNum(int Magic)
{
  for(int i = 0; i < 100; i++)
  {                                               
    if(Magic == Magik[0, i]) {return(i);}
    if(Magik[0, i] < 0) {break;}
  }
  Magik[0, i] = Magic;
  Nmag = i;

  if(i == 0)  {Magik[1][i] = 0;}
  else
  {
    int j, srt = 0, mx;
    for(j = 0; j <= Nmag; j ++)  {Magik[1][j] = -1;}
    while(srt <= Nmag)
    {
      for(j = 0; j <= Nmag; j ++)
      {
        if(Magik[0][j] >= 0 && Magik[1][j] < 0)
        {
          mx = j;
          break;
        }
      }

      for(j = 0; j <= Nmag; j ++)
      {
        if(mx != j && Magik[1][j] < 0 && Magik[0][j] >= 0)
        {
          if(Magik[0][j] < Magik[0][mx]) {mx = j;}    //раньше по алфавиту
        }
      }
      Magik[1][mx] = srt;
      srt ++;
    }
  }

  return(i);
}
//--------------------------------------------------------------------
int BonusNum(string CheckBonus)
{
  int i, BonusTypeFnd = -1, BonusTypeFndExt = 0;
  for(i = 0; i < 100; i++)
  {                                               
    if(StringLen(BTags[0][i]) == 0)  {break;}
    if(StringFind(CheckBonus, BTags[0][i], 0) >= 0)
    {
      BonusTypeFnd = i;
      BonusTypeFndExt = MathRound(STD(BTags[1][i]));
      break;
    }
  }
  if(BonusTypeFnd >= 0)
  {
    for(i = 0; i < 100; i++)
    {                                               
      if(Bonuses[0][i] == BonusTypeFnd)
      {
        if(                        
           BonusTypeFndExt == 0
           ||
           (BonusTypeFndExt == 1 && Bonuses[1][i] == STD(TRIM(StringSubstr(CheckBonus, 22, 0))))
          ) {return(i);}
      }
      if(Bonuses[0][i] == -1 * EMPTY_VALUE) {break;}
    }
    Bonuses[0][i] = BonusTypeFnd;
    Bonuses[1][i] = 0.0;
    Bonuses[2][i] = 0.0;
    Bonuses[3][i] = 0.0;
    if(BonusTypeFndExt == 1)   
    {
      Bonuses[1][i] = STD(TRIM(StringSubstr(CheckBonus, 22, 0)));
    }
    else {Bonuses[1][i] = EMPTY_VALUE;}
    Nbonuses = i;
    return(i);
  }
  else {return(-1);}
}
//--------------------------------------------------------------------
int HistoryOrders()                                  
{
  if(ScanFromToday)
  {
    DateInfoStart = DateInfoEnd;
    if(!ScanCurrentWeek && !ScanCurrentMonth)
    {
      DateInfoStart = iTime(NULL, PERIOD_D1, (DaysToScan - 1));
    }
    if(ScanCurrentWeek)
    {
      DateInfoStart = iTime(NULL, PERIOD_W1, 0) + 86402;
      if(MathCeil((DateInfoEnd - DateInfoStart) / 86400) > 7) {PrevTickDate = -1;}
    }
    if(ScanCurrentMonth)
    {
      DateInfoStart = iTime(NULL, PERIOD_MN1, 0);
      if(MathCeil((DateInfoEnd - DateInfoStart) / 86400) > 31) {PrevTickDate = -1;}
    }
    TS = MathCeil((DateInfoEnd - DateInfoStart) / 86400);   //время сканирования в часах
    if(TS > 0) {TimeSkan = StringConcatenate(" total ", TS + 1, " days");}
    else {TimeSkan = " total 1 day";}
  }
   
  if(!isNewDay && HistOrdsTot == n_oht)  {return(hn);}
  HistOrdsTot = n_oht;

  int i, n, OMN, nr, BonusId;
  string Symb;
  datetime StartInfo = DateInfoEnd, EndInfo = 0;
  double Profit = 0.0;

  StartDep = AccountBalance();
  ArrayInitialize(Today, 0.0);
  ArrayInitialize(HistoryOrders, 0.0);
  ArrayInitialize(Magik, -1);
  ArrayInitialize(MagikProfit, 0.0);
  ArrayInitialize(Bonuses, -1 * EMPTY_VALUE);
  ArrayInitialize(Summary, 0.0);
  Summary[0][0] = iTime(NULL, PERIOD_W1, 0) + 86401;
  Summary[1][0] = STT(DTS(TimeYear(DateInfoEnd), 0) + "." + DTS(TimeMonth(DateInfoEnd), 0) + "." + DTS(1, 0) + " 00:00:01");
  if(TimeMonth(DateInfoEnd) == 1) {nr = 10;}
  if(TimeMonth(DateInfoEnd) >= 2 && TimeMonth(DateInfoEnd) <= 3) {nr = 1;}
  if(TimeMonth(DateInfoEnd) >= 4 && TimeMonth(DateInfoEnd) <= 6) {nr = 4;}
  if(TimeMonth(DateInfoEnd) >= 7 && TimeMonth(DateInfoEnd) <= 9) {nr = 7;}
  if(TimeMonth(DateInfoEnd) >= 10 && TimeMonth(DateInfoEnd) <= 12) {nr = 10;}
  if(TimeMonth(DateInfoEnd) != 1) {Summary[2][0] = STT(DTS(TimeYear(DateInfoEnd), 0) + "." + DTS(nr, 0) + "." + DTS(1, 0) + " 00:00:01");}
                             else {Summary[2][0] = STT(DTS(TimeYear(DateInfoEnd) - 1, 0) + "." + DTS(nr, 0) + "." + DTS(1, 0) + " 00:00:01");}
  if(TimeMonth(DateInfoEnd) >= 4 && TimeMonth(DateInfoEnd) <= 6) {nr = 1;}
  if((TimeMonth(DateInfoEnd) < 4) || (TimeMonth(DateInfoEnd) >= 7 && TimeMonth(DateInfoEnd) <= 12)) {nr = 7;}
  if(TimeMonth(DateInfoEnd) >= 4) {Summary[3][0] = STT(DTS(TimeYear(DateInfoEnd), 0) + "." + DTS(nr, 0) + "." + DTS(1, 0) + " 00:00:01");}
                             else {Summary[3][0] = STT(DTS(TimeYear(DateInfoEnd) - 1, 0) + "." + DTS(nr, 0) + "." + DTS(1, 0) + " 00:00:01");}
  if(TimeMonth(DateInfoEnd) >= 7) {Summary[4][0] = STT(DTS(TimeYear(DateInfoEnd), 0) + "." + DTS(1, 0) + "." + DTS(1, 0) + " 00:00:01");}
  else {Summary[4][0] = STT(DTS(TimeYear(DateInfoEnd) - 1, 0) + "." + DTS(1, 0) + "." + DTS(1, 0) + " 00:00:01");}
  Summary[0][5] = StartDep;
  Summary[1][5] = StartDep;
  Summary[2][5] = StartDep;
  Summary[3][5] = StartDep;
  Summary[4][5] = StartDep;
  i = 0;
  while(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
  {
    if(OrderType() == 6 && OrderProfit() > 0)
    {
      OOT = OrderCloseTime();
      Summary[5][0] = STT(DTS(TimeYear(OOT), 0) + "." + DTS(TimeMonth(OOT), 0) + "." + DTS(TimeDay(OOT), 0) + " 00:00:01");
      Summary[5][5] = OrderProfit();
      StartInfo = Summary[5][0] - 2;
      break;
    }
    i ++;
  }

  AccStartDep = 0.0;
  AccWithdrawal = 0.0;
  HistOrdsTot = n_oht;

  for(i = n_oht - 1; i >= 0; i--)
  {                                   
    BonusId = -1;
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
    {
      OOT = OrderCloseTime();
      Symb = TRIM(OrderSymbol());
      if(Symb == "" || OrderType() > 1)
      {
        if(OrderType() == 6)
        {
          BonusId = BonusNum(TRIM(OrderComment()));
          if(BonusId >= 0)
          {
            Bonuses[2][BonusId] += ND(OrderProfit(), 2);
            if(OOT >= DateInfoStart && OOT < DateInfoEnd)
            {
              Bonuses[3][BonusId] += ND(OrderProfit(), 2);
            }
          }
          if(OrderProfit() > 0 && OrderProfit() != EMPTY_VALUE) {AccStartDep += ND(OrderProfit(), 2);}
          if(OrderProfit() < 0 && OrderProfit() != EMPTY_VALUE && BonusId < 0) {AccWithdrawal += ND(OrderProfit(), 2);}

          if(СalcStartDep)
          {
            if(OOT >= DateInfoStart && OOT < DateInfoEnd) {StartDep -= ND(OrderProfit(), 2);}
            if(OOT >= Summary[0][0] - 2)  {Summary[0][5] -= ND(OrderProfit(), 2);}
            if(OOT >= Summary[1][0] - 2)  {Summary[1][5] -= ND(OrderProfit(), 2);}
            if(OOT >= Summary[2][0] - 2)  {Summary[2][5] -= ND(OrderProfit(), 2);}
            if(OOT >= Summary[3][0] - 2)  {Summary[3][5] -= ND(OrderProfit(), 2);}
            if(OOT >= Summary[4][0] - 2)  {Summary[4][5] -= ND(OrderProfit(), 2);}
          }
        }
        continue;
      }

      if(СalcStartDep && (OrderProfit() + OrderSwap() + OrderCommission()) != 0.0)
      {
        if(OOT >= DateInfoStart && OOT < DateInfoEnd) {StartDep -= ND(OrderProfit() + OrderSwap() + OrderCommission(), 2);}
        if(OOT >= Summary[0][0] - 2)  {Summary[0][5] -= ND(OrderProfit() + OrderSwap() + OrderCommission(), 2);}
        if(OOT >= Summary[1][0] - 2)  {Summary[1][5] -= ND(OrderProfit() + OrderSwap() + OrderCommission(), 2);}
        if(OOT >= Summary[2][0] - 2)  {Summary[2][5] -= ND(OrderProfit() + OrderSwap() + OrderCommission(), 2);}
        if(OOT >= Summary[3][0] - 2)  {Summary[3][5] -= ND(OrderProfit() + OrderSwap() + OrderCommission(), 2);}
        if(OOT >= Summary[4][0] - 2)  {Summary[4][5] -= ND(OrderProfit() + OrderSwap() + OrderCommission(), 2);}
      }
      if(SymbolsInfo != "" && StringFind(SymbolsInfo, Symb, 0) < 0) {continue;}
      OMN = OrderMagicNumber();
      if(Magiks != "" && StringFind(Magiks, DTS(OMN, 0), 0) < 0) {continue;}
      Profit = OrderProfit() + OrderSwap() + OrderCommission();
      if(Profit != 0.0)
      {
        nr = MarketInfo(Symb, MODE_DIGITS);
        if(OOT >= iTime(NULL, PERIOD_D1, 0)) Today[0][0] += Profit;

        if(OrderType() <= 1)
        {
          for(int j = 1; j < 10; j++)
          {
            if(OOT >= iTime(NULL, PERIOD_D1, j) && OOT < iTime(NULL, PERIOD_D1, j - 1)) {Today[0][j] += Profit;}
          }
          
          if(SumNeedShow)
          {
            for(j = 0; j <= 5; j++)
            {
              if(/*Summary[j][0] != 0.0 &&*/ OOT >= Summary[j][0] - 2)               //Summary месяц, год, с начала счета 
              {
                Summary[j][1] ++; 
                if(Profit < 0.0) {Summary[j][2] -= MathRound(MathAbs(ND(OrderOpenPrice(), dgts) - ND(OrderClosePrice(), dgts)) * MathPow(10, nr));}
                if(Profit > 0.0) {Summary[j][2] += MathRound(MathAbs(ND(OrderOpenPrice(), dgts) - ND(OrderClosePrice(), dgts)) * MathPow(10, nr));}
                Summary[j][3] += ND(OrderLots(), 2);
                Summary[j][4] += ND(Profit, 2);
              }
            }
          }
         
          if(OOT >= DateInfoStart && OOT < DateInfoEnd)
          {
            if(StartInfo > OOT) {StartInfo = OOT;}
            if(EndInfo < OOT) {EndInfo = OOT;}
            HistoryOrders[0][n] = SymbolNum(Symb);
            HistoryOrders[2][n] = ND(Profit, 2);
            HistoryOrders[3][n] = ND(OrderLots(), 2);
            HistoryOrders[4][n] = MagikNum(OMN);

            if(OrderType() == OP_BUY)
            {
              HistoryOrders[1][n] = OP_BUY;
              HistoryOrders[13][n] = HistoryOrders[3][n];
              if(Profit < 0.0)
              {
                HistoryOrders[6][n]++;
                HistoryOrders[10][n] -= MathRound(MathAbs(ND(OrderOpenPrice(), dgts) - ND(OrderClosePrice(), dgts)) * MathPow(10, nr));
              }
              if(Profit > 0.0)
              {
               HistoryOrders[5][n]++;
               HistoryOrders[9][n] += MathRound(MathAbs(ND(OrderClosePrice(), dgts) - ND(OrderOpenPrice(), dgts)) * MathPow(10, nr));
              }
            }

            if(OrderType() == OP_SELL)
            {
              HistoryOrders[1][n] = OP_SELL;
              HistoryOrders[14][n] = HistoryOrders[3][n];
              if(Profit < 0.0)
              {
                HistoryOrders[8][n]++;
                HistoryOrders[12][n] -= MathRound(MathAbs(ND(OrderClosePrice(), nr) - ND(OrderOpenPrice(), nr)) * MathPow(10, nr));
              }
              if(Profit > 0.0)
              {
                HistoryOrders[7][n]++;
                HistoryOrders[11][n] += MathRound(MathAbs(ND(OrderOpenPrice(), nr) - ND(OrderClosePrice(), nr)) * MathPow(10, nr));
              }
            }
            n++;
          }
        }
      }
    }   
    if(n > 10000) {Comment("Buffers overflow", n_oht); return(n);}
  }

  if(MagNeedShow)
  {
    for(i = 0; i <= Nmag; i++)
    {                                               
      for(j = 0; j <= n; j++)
      {
        if(i == HistoryOrders[4][j])//Magik
        {
           MagikProfit[0][i] += HistoryOrders[2][j];//профит 
           MagikProfit[1][i] += HistoryOrders[5][j];//кол-во прибыльных сделок BUY
           MagikProfit[2][i] += HistoryOrders[6][j];//кол-во убыточных сделок BUY
           MagikProfit[3][i] += HistoryOrders[7][j];//кол-во прибыльных сделок SELL
           MagikProfit[4][i] += HistoryOrders[8][j];//кол-во убыточных сделок SELL
           MagikProfit[5][i] += HistoryOrders[9][j];//кол-во прибыльных пипсов BUY
           MagikProfit[6][i] += HistoryOrders[10][j];//кол-во убыточных пипсов BUY
           MagikProfit[7][i] += HistoryOrders[11][j];//кол-во прибыльных пипсов SELL
           MagikProfit[8][i] += HistoryOrders[12][j];//кол-во убыточных пипсов SELL
           MagikProfit[9][i] += HistoryOrders[13][j];//сумма объемов BUY
           MagikProfit[10][i] += HistoryOrders[14][j];//сумма объемов SELL
        }
      }
    }
  }

  if(ShowLast10Days && LogInfoToFile && LogEnable && LogFileHandle > 0 && L10NeedShow)
  {
    if(FileSize(LogFileHandle) > 0)
    {
      int InitFilePos = MathRound(FileTell(LogFileHandle));
      double SumMDD = 0.0, MFM;
      string TmpLoggedStr;

      for(j = 0; j < 10; j++)
      {
        Today[2][j] = EMPTY_VALUE;
        FileSeek(LogFileHandle, 0, SEEK_SET);
        while(!FileIsEnding(LogFileHandle))
        {
          if(FileReadString(LogFileHandle) == "Time")
          {
            TmpLoggedStr = FileReadString(LogFileHandle);
            if(
               (j == 0 && STT(TmpLoggedStr) >= iTime(NULL, PERIOD_D1, j))
               ||
               (j > 0 && STT(TmpLoggedStr) >= iTime(NULL, PERIOD_D1, j) && STT(TmpLoggedStr) < iTime(NULL, PERIOD_D1, j - 1))
              )
            {
              while(!FileIsLineEnding(LogFileHandle))
              {
                if(FileReadString(LogFileHandle) == "MaxDayDD") {Today[1][j] = MathMin(Today[1][j], STD(FileReadString(LogFileHandle)));}
                if(FileReadString(LogFileHandle) == "FMar") {Today[2][j] = MathMin(Today[2][j], STD(FileReadString(LogFileHandle)));}
              }
            }
          }
        }

        if(Today[2][j] == EMPTY_VALUE) 
        {
          if(j == 0) {Today[2][j] = AccBalance;}
          else {Today[2][j] = 0.0;}
        }
      }
      FileSeek(LogFileHandle, InitFilePos, SEEK_SET);
      MaxSumDD1 = MathMin(MaxSumDD1, Today[1][0]);
    }
  }

  if(!ScanFromToday)
  {
    TS = MathCeil((EndInfo - StartInfo) / 86400);   //время сканирования в часах
    if(DateInfoStart < StartInfo) {DateInfoStart = StartInfo;}
    if(TS >= 0)
    {
      if(TS > 0) 
      {
        TimeSkan = StringConcatenate(" total ", TS + 1, " days ");
      }
      if(TS == 0) TimeSkan = " total 1 day";
    }
    if(TS == 0) {TimeSkan = " was not any trades";}
  }
  if(StartDep < 0.0)  {StartDep = 0.0;}
  if(AccStartDep <= 0.0) {AccStartDep = StartDep;}
  isNewDay = false;
  return(n);
}
//--------------------------------------------------------------------
int TekOrders()                                  
{
  int n = 0, OMN;
  string Symb;
  ArrayInitialize(Orders, 0.0);
  n_oct = OrdersTotal();

  for(int i = n_oct - 1; i >= 0; i--)
  {                                               
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
      if(OrderSymbol() == "" || OrderType() > 1) {continue;}

      Symb = OrderSymbol();
      if (SymbolsInfo != "" && StringFind(SymbolsInfo, Symb, 0) < 0) {continue;}
      OMN = OrderMagicNumber();
      if (Magiks != "" && StringFind(Magiks, DTS(OMN, 0), 0) < 0) continue;
      OOT = OrderOpenTime();
      if (DateInfoEnd < OOT) continue;

      Orders[0][n] = SymbolNum(Symb);
      Orders[2][n] = OrderProfit() + OrderSwap() + OrderCommission();
      Orders[3][n] = OrderLots();
      Orders[4][n] = MagikNum(OMN);

      if (OrderType() == OP_BUY)
      {
        Orders[1][n] = OP_BUY;
        if(OrderStopLoss() > 0) {Orders[5][n] = (MarketInfo(OrderSymbol(), MODE_TICKVALUE) * OrderLots() * (OrderStopLoss() - OrderOpenPrice()) / MarketInfo(OrderSymbol(), MODE_POINT)) + OrderSwap() + OrderCommission();}
      }
      if (OrderType() == OP_SELL)
      {
        Orders[1][n] = OP_SELL;
        if(OrderStopLoss() > 0) {Orders[5][n] = (MarketInfo(OrderSymbol(), MODE_TICKVALUE) * OrderLots() * (OrderOpenPrice() - OrderStopLoss()) / MarketInfo(OrderSymbol(), MODE_POINT)) + OrderSwap() + OrderCommission();}
      }
      n++;
    }   
    if(n > 10000) {Comment("Buffers overflow!!!", n_oht); return(n);}
  }
  return(n);
}
//--------------------------------------------------------------------
color Color(double x)
{
  switch(ColorShemeType)
  {
    case 0:
    {
      if(x == 0.0)  {return(NullColor1_0);}
      if(x < 0.0) {return(NegativeColor0);}
      if(x > 0.0) {return(PositiveColor0);}
      return(MainColor);
    }
    case 1:
    {
      if(x == 0.0)  {return(NullColor1_0);}
      if(x < -ColorShemeTreshold1_3) {return(NegativeColor1_3);}
      if(x > ColorShemeTreshold1_3) {return(PositiveColor1_3);}
      if(x >= -ColorShemeTreshold1_3 && x < -ColorShemeTreshold1_2) {return(NegativeColor1_2);}
      if(x <= ColorShemeTreshold1_3 && x > ColorShemeTreshold1_2) {return(PositiveColor1_2);}
      if(x >= -ColorShemeTreshold1_2 && x < -ColorShemeTreshold1_1) {return(NegativeColor1_1);}
      if(x <= ColorShemeTreshold1_2 && x > ColorShemeTreshold1_1) {return(PositiveColor1_1);}
      if(x >= -ColorShemeTreshold1_1 && x < 0) {return(NegativeColor1_0);}
      if(x <= ColorShemeTreshold1_1 && x > 0) {return(PositiveColor1_0);}
      return(MainColor);
    }
  }
}
//--------------------------------------------------------------------
color Text(string name, string txt, int x, int y, color C, int w, int Win)
{  
  if(!ObjectFind(name) >= 0) {ObjectCreate(name, OBJ_LABEL, Win, 0, 0);}
  else
  {
    if(name == StringConcatenate("ShBonuses", Win))
    {   
      if(ObjectGet(name, OBJPROP_COLOR) == HeaderColor)   {C = MainColor;}
      else  {C = HeaderColor;}
      if(ObjectGet(name, OBJPROP_XDISTANCE) != x || ObjectGet(name, OBJPROP_YDISTANCE) != y)
      {
        if(!BonusNeedShow)  {BonusNeedShow = true; L10NeedShow = false; MagNeedShow = false; PrevTickDate = -1; DetailShowTime = -1; BonusShowTime = TCurr;}
        else  {BonusNeedShow = false; BonusShowTime = -1; PrevTickDate = -1;}
      }
    }
    if(name == StringConcatenate("ShL10", Win))
    {   
      if(ObjectGet(name, OBJPROP_COLOR) == HeaderColor)   {C = MainColor;}
      else  {C = HeaderColor;}
      if(ObjectGet(name, OBJPROP_XDISTANCE) != x || ObjectGet(name, OBJPROP_YDISTANCE) != y)
      {
        if(!L10NeedShow)  {L10NeedShow = true; /*SumNeedShow = false;*/ PrevTickDate = -1; BonusShowTime = -1; DetailShowTime = TCurr;}
        else  {L10NeedShow = false; DetailShowTime = -1; PrevTickDate = -1;}
      }
    }
    if(name == StringConcatenate("ShMag", Win))
    {   
      if(ObjectGet(name, OBJPROP_COLOR) == HeaderColor)   {C = MainColor;}
      else  {C = HeaderColor;}
      if(ObjectGet(name, OBJPROP_XDISTANCE) != x || ObjectGet(name, OBJPROP_YDISTANCE) != y)
      {
        if(!MagNeedShow)  {MagNeedShow = true; /*SumNeedShow = false;*/ PrevTickDate = -1; BonusShowTime = -1; DetailShowTime = TCurr;}
        else  {MagNeedShow = false; DetailShowTime = -1; PrevTickDate = -1;}
      }
    }
    if(name == StringConcatenate("ShSum", Win))
    {
      if(ObjectGet(name, OBJPROP_COLOR) == HeaderColor)   {C = MainColor;}
      else  {C = HeaderColor;}
      if(ObjectGet(name, OBJPROP_XDISTANCE) != x || ObjectGet(name, OBJPROP_YDISTANCE) != y)
      {
        if(!isWEnd)
        {
          if(!SumNeedShow)  {SumNeedShow = true; PrevTickDate = -1; BonusShowTime = -1; DetailShowTime = TCurr;}
          else  {SumNeedShow = false; DetailShowTime = -1; PrevTickDate = -1;}
        }
        else
        {
          if(!SumNeedShow)  {SumNeedShow = true; PrevTickDate = -1; BonusShowTime = -1; DetailShowTime = TCurr;}
          else  {WEndSumHide = true; isWEnd = false; SumNeedShow = false; DetailShowTime = TCurr; PrevTickDate = -1;}
        }
      }
      else  {if(isWEnd) {DetailShowTime = TCurr;}}
    }
  }
  ObjectSet(name, OBJPROP_CORNER, 0);
  ObjectSet(name, OBJPROP_YDISTANCE, y);
  ObjectSet(name, OBJPROP_XDISTANCE, x);
  ObjectSetText(name, txt, w, Font, C);
  return(true);
}
//--------------------------------------------------------------------
bool LogFileInit()
{
  if(AccountNumber() <= 0) {LogEnable = false;}
  if(LogInfoToFile && LogEnable)
  {
    FileName = StringConcatenate("HI-", DTS(Year(), 0), "-", DTS(Period(), 0), ".csv");
    LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_READ|FILE_WRITE,";");
    if(LogFileHandle < 0)   //файл не найден или занят
    {
      LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_WRITE,";");
      if(LogFileHandle > 0)
      {
        FileClose(LogFileHandle);
        LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_READ|FILE_WRITE,";");
        if(LogFileHandle > 0)
        {
          Print(NameInd, " ", Symbol(), " ", Period(), "Warning!! Unable to open LOG-file - ", FileName, " (ERROR - ", GetLastError(), "). Empty file was created.");
          LogEnable = false;
        }
        else
        {
          Print(NameInd, " ", Symbol(), " ", Period(), "Error!! Unable to create LOG-file - ", FileName, ". ERROR - ", GetLastError());
          LogEnable = false;
        }
      }
      else   //не удалось создать файл
      {
        Print(NameInd, " ", Symbol(), " ", Period(), "Error!! Unable to create LOG-file - ", FileName, ". ERROR - ", GetLastError());
        LogEnable = false;
      }
    }

    bool accn_found = false;
    if(IsConnected() && LogEnable)
    {
      if(LogInfoToFile && LogEnable && LogFileHandle > 0)
      {
        while(!FileIsEnding(LogFileHandle))
        {
          if(FileReadString(LogFileHandle) == "AccN")
          {
            if(FileReadString(LogFileHandle) != DTS(AccountNumber(), 0))    //файл от другого торгового счета
            {
              FileClose(LogFileHandle);
              LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_WRITE,";");
              if(LogFileHandle > 0)
              {
                FileClose(LogFileHandle);
                LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_READ|FILE_WRITE,";");
                if(LogFileHandle < 0)   //не удалось создать файл
                {
                  Print(NameInd, " ", Symbol(), " ", Period(), "Error!! Unable to open LOG-file - ", FileName, ". Another account LOG-file found. File was recreated. ERROR - ", GetLastError());
                  LogEnable = false;
                }
                else  {accn_found = true;}
                break;
              }
              else
              {
                Print(NameInd, " ", Symbol(), " ", Period(), "Error!! Unable to create LOG-file - ", FileName, ". ERROR - ", GetLastError());
                LogEnable = false;
                break;
              }
            }
            else  {accn_found = true;}
            break;
          }
        }

        if(!accn_found && FileSize(LogFileHandle) > 0)  //в файле не найден номер торгового счета
        {
          FileClose(LogFileHandle);
          LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_WRITE,";");
          if(LogFileHandle > 0)
          {
            FileClose(LogFileHandle);
            LogFileHandle = FileOpen(FileName, FILE_CSV|FILE_READ|FILE_WRITE,";");
            if(LogFileHandle < 0)   //не удалось создать файл
            {
              Print(NameInd, " ", Symbol(), " ", Period(), "Error!! Unable to open LOG-file - ", FileName, ". Another account LOG-file found. File was recreated. ERROR - ", GetLastError());
              LogEnable = false;
            }
          }
          else
          {
            Print(NameInd, " ", Symbol(), " ", Period(), "Error!! Unable to create LOG-file - ", FileName, ". ERROR - ", GetLastError());
            LogEnable = false;
          }
        }

        if(LogInfoToFile && LogEnable && LogFileHandle > 0)
        {
          FileSeek(LogFileHandle, 0, SEEK_SET);
          double FmaxDD = 0.0, FminM;
          while(!FileIsEnding(LogFileHandle))
          {
            if(FileReadString(LogFileHandle) == "CurDD")
            {
              FmaxDD = STD(FileReadString(LogFileHandle));
              if(MaxSumDD > FmaxDD && FmaxDD < 0.0) {MaxSumDD = FmaxDD;}
            }
            if(FileReadString(LogFileHandle) == "FMar")
            {
              FminM = STD(FileReadString(LogFileHandle));
              if(MinFreeMar > FminM) {MinFreeMar = FminM;}
            }
          }         
          FileSeek(LogFileHandle, 0, SEEK_END);
        }
      }
    }
    return(true);
  }
  else {return(false);}
}
//--------------------------------------------------------------------
bool LogFileDeInit(string CommStr="HI_Deinit=")
{
  if(LogInfoToFile && LogEnable && LogFileHandle > 0 && AccEquity != 0.0 && Symbl[0][0] != "")
  {  
    int UR = UninitializeReason();
    for(int i = 0; i <= Nsymb; i++)
    {
      string SimbMaxDD = StringConcatenate(Symbl[0][i], ";", DTS(SymbolHistoryProfit[1][i], 2));
      if(i < Nsymb) {SimbMaxDD = StringConcatenate(SimbMaxDD, ";");}
    }

    for(i = 0; i <= Nsymb; i++)
    {
      string SimbDD = StringConcatenate("c", Symbl[0][i], ";", DTS(SymbolHistoryProfit[2][i], 2));
      if(i < Nsymb) {SimbDD = StringConcatenate(SimbDD, ";");}
    }
  
    if(FreeMar > 0) {FileWrite(LogFileHandle, "Time", TTS(Time[1]), "AccN", AccountNumber(), "AccBal", AccBalance, "AccEq", AccEquity, "AccPr", AccProfit, SimbMaxDD, SimbDD, "MaxDD", MaxSumDD, "MaxDayDD", MaxSumDD1, "CurDD", CurSumDD, "FMar", FreeMar, StringConcatenate(CommStr, UR));}
    else  {FileWrite(LogFileHandle, "Time", TTS(Time[1]), "AccN", AccountNumber(), "AccBal", AccBalance, "AccEq", AccEquity, "AccPr", AccProfit, SimbMaxDD, SimbDD, "MaxDD", MaxSumDD, "MaxDayDD", MaxSumDD1, "CurDD", CurSumDD, StringConcatenate(CommStr, UR));}
    FileFlush(LogFileHandle); 
    FileClose(LogFileHandle);
    return(true);
  }
  else {return(false);}
}
//--------------------------------------------------------------------
double ND(double InpDbl,int InpDgts=0){return(NormalizeDouble(InpDbl,InpDgts));}
string DTS(double InpDbl,int InpDgts=0){return(DoubleToStr(InpDbl,InpDgts));}
double STD(string InpStr){return(StrToDouble(InpStr));}
int STI(string InpStr){return(MathFloor(StrToDouble(InpStr)));}
string TRIM(string InpStr){return(StringTrimLeft(StringTrimRight(InpStr)));}
string TTS(datetime InpTm,int InpMode=TIME_DATE){return(TimeToStr(InpTm,InpMode));}
datetime STT(string InpStr){return(StrToTime(InpStr));}