//+------------------------------------------------------------------+
//|                                                       BalansInfo |
//|                               Copyright © 2010, Vladimir Hlystov |
//|                                         http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Хлыстов Владимир"
#property link      "cmillion@narod.ru"
#property indicator_separate_window
extern int        MagikInfo   = 0;  //если 0 то все магики
extern int        Shift       = 70;  //ширина между столбцами
extern string     SybmolInfo  = "";  //если "" то все инструменты
extern datetime   DateInfo    = D'01.01.2004';  //начинать с даты
extern color      WhiteColor  = White;//цвет вывода информации
//--------------------------------------------------------------------
string Symbl[100];
double Orders[3][10000],SymbolProfit[100];
int Symboltype[2][100];
int Nsymb,Win,Ords;
//--------------------------------------------------------------------
int deinit()
{
   ObjectDelete("с");
   ObjectDelete("i");
   ObjectDelete("0");
   ObjectDelete("1");
   ObjectDelete("2");
   ObjectDelete("3");
   ObjectDelete("4");
   for (int i=0; i<Nsymb+1; i++)
   {  
      ObjectDelete(Symbl[i]);
      ObjectDelete(StringConcatenate(Symbl[i],"profit"));
      ObjectDelete(StringConcatenate(Symbl[i],"b"));
      ObjectDelete(StringConcatenate(Symbl[i],"s"));
   }
}
//--------------------------------------------------------------------
int init()
{
   Win = WindowFind("HistoryInfo_v1");
   string txt = StringConcatenate("Сканирование счета с ",TimeToStr(DateInfo,TIME_DATE)," / ");
   if (MagikInfo==0) txt = StringConcatenate(txt,"Magik номера - ВСЕ");
   else  txt = StringConcatenate(txt,"Magik номер - ",MagikInfo);
   ObjectCreate("i", OBJ_LABEL, Win, 0, 0);
   ObjectSet("i", OBJPROP_CORNER, 0);
   ObjectSet("i", OBJPROP_YDISTANCE, 2);
   ObjectSet("i", OBJPROP_XDISTANCE, 500);
   ObjectSetText("i", txt, 8, "Tahoma", WhiteColor);
   ObjectCreate("c", OBJ_LABEL, Win, 0, 0);
   ObjectSet("c", OBJPROP_CORNER, 2);
   ObjectSet("c", OBJPROP_YDISTANCE, 5);
   ObjectSet("c", OBJPROP_XDISTANCE, 5);
    ObjectSetText("c", "Copyright © 2010 cmillion@narod.ru", 8, "Tahoma", WhiteColor);
   ObjectCreate("0", OBJ_LABEL, Win, 0, 0);
   ObjectSet("0", OBJPROP_CORNER, 0);
   ObjectSet("0", OBJPROP_YDISTANCE, 2);
   ObjectSet("0", OBJPROP_XDISTANCE, 100);
    ObjectSetText("0", "Информация по счету "+AccountNumber()+" / "+AccountCompany()+" / 1:"+AccountLeverage()  , 8, "Tahoma", WhiteColor);
   ObjectCreate("1", OBJ_LABEL, Win, 0, 0);
   ObjectSet("1", OBJPROP_CORNER, 0);
   ObjectSet("1", OBJPROP_YDISTANCE, 20);
   ObjectSet("1", OBJPROP_XDISTANCE, 5);
   ObjectCreate("2", OBJ_LABEL, Win, 0, 0);
   ObjectSet("2", OBJPROP_CORNER, 0);
   ObjectSet("2", OBJPROP_YDISTANCE, 30);
   ObjectSet("2", OBJPROP_XDISTANCE, 5);
   ObjectCreate("3", OBJ_LABEL, Win, 0, 0);
   ObjectSet("3", OBJPROP_CORNER, 0);
   ObjectSet("3", OBJPROP_YDISTANCE, 40);
   ObjectSet("3", OBJPROP_XDISTANCE, 5);
   ObjectCreate("4", OBJ_LABEL, Win, 0, 0);
   ObjectSet("4", OBJPROP_CORNER, 0);
   ObjectSet("4", OBJPROP_YDISTANCE, 50);
   ObjectSet("4", OBJPROP_XDISTANCE, 5);
return;
}   
//-------------------------------------------------------------------------------
int start()                                  
{
   if (OrdersTotal()<Ords || Ords==0)
   {
      int n=startHistory();
      if (n>10000) {Alert("Переполнение буфера",OrdersHistoryTotal());return;}
      double Profit;
      for (int i=0; i<Nsymb+1; i++)
      {                                               
         SymbolProfit[i]=0;
         for (int j=0; j<n; j++)
         {
            if (i == Orders[0][j])//Symbol
            {
               SymbolProfit[i]+=Orders[2][j];//профит 
               if (Orders[1][j]==OP_BUY) Symboltype[0][i]++;
               if (Orders[1][j]==OP_SELL) Symboltype[1][i]++;
            }
         }
      }
      string name;
      for (i=0; i<Nsymb+1; i++)
      {  
         ObjectCreate(Symbl[i], OBJ_LABEL, Win, 0, 0);
         ObjectSet(Symbl[i], OBJPROP_CORNER, 0);
         ObjectSet(Symbl[i], OBJPROP_YDISTANCE, 20);
         ObjectSet(Symbl[i], OBJPROP_XDISTANCE, 100+Shift*i);
         ObjectSetText(Symbl[i], Symbl[i], 8, "Tahoma", WhiteColor);
         name = StringConcatenate(Symbl[i],"profit");
         ObjectCreate(name, OBJ_LABEL, Win, 0, 0);
         ObjectSet(name, OBJPROP_CORNER, 0);
         ObjectSet(name, OBJPROP_YDISTANCE, 30);
         ObjectSet(name, OBJPROP_XDISTANCE, 100+Shift*i);
         ObjectSetText(name, DoubleToStr(SymbolProfit[i],2), 8, "Tahoma", WhiteColor);
         name = StringConcatenate(Symbl[i],"b");
         ObjectCreate(name, OBJ_LABEL, Win, 0, 0);
         ObjectSet(name, OBJPROP_CORNER, 0);
         ObjectSet(name, OBJPROP_YDISTANCE, 40);
         ObjectSet(name, OBJPROP_XDISTANCE, 100+Shift*i);
         ObjectSetText(name, StringConcatenate("B ",Symboltype[0][i]), 8, "Tahoma", WhiteColor);
         name = StringConcatenate(Symbl[i],"s");
         ObjectCreate(name, OBJ_LABEL, Win, 0, 0);
         ObjectSet(name, OBJPROP_CORNER, 0);
         ObjectSet(name, OBJPROP_YDISTANCE, 50);
         ObjectSet(name, OBJPROP_XDISTANCE, 100+Shift*i);
         ObjectSetText(name, StringConcatenate("S ",Symboltype[1][i]), 8, "Tahoma", WhiteColor);
      }
      ObjectSetText("1",StringConcatenate("Orders    ",n), 8, "Tahoma", WhiteColor);
      ObjectSetText("2",StringConcatenate("Symbols  ",Nsymb+1), 8, "Tahoma", WhiteColor);
      ObjectSetText("3",StringConcatenate("Equity     ",DoubleToStr(AccountEquity(),2)), 8, "Tahoma", WhiteColor);
      ObjectSetText("4",StringConcatenate("Balance   ",DoubleToStr(AccountBalance(),2)), 8, "Tahoma", WhiteColor);
   }
   Ords=OrdersTotal();
}
//--------------------------------------------------------------------
int SymbolNum(string Symb)
{
   for (int i=0; i<100; i++)
   {                                               
      if (Symb==Symbl[i]) return(i);
      if (StringLen(Symbl[i])==0) break;
   }
   Symbl[i]=Symb;
   Nsymb=i;
   return(i);
}
//--------------------------------------------------------------------
int startHistory()                                  
{
   int n;
   string Symb;
   for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {                                               
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
      {
         Symb = OrderSymbol();
         if (OrderSymbol()!=SybmolInfo && SybmolInfo!="") continue;
         if (MagikInfo!=OrderMagicNumber() && MagikInfo!=0) continue;
         if (DateInfo>OrderOpenTime()) continue;
         if (OrderType()==OP_BUY)
         {
            Orders[0][n]=SymbolNum(Symb);
            Orders[1][n]=OP_BUY;
            Orders[2][n]=OrderProfit()+OrderSwap()+OrderCommission();
            n++;
         }
         if (OrderType()==OP_SELL)
         {
            Orders[0][n]=SymbolNum(Symb);
            Orders[1][n]=OP_SELL;
            Orders[2][n]=OrderProfit()+OrderSwap()+OrderCommission();
            n++;
         }
      }   
      if (n>10000) {Comment("Переполнение буфера",OrdersHistoryTotal());return(n);}
   }
   return(n);
}
//--------------------------------------------------------------------

