//+------------------------------------------------------------------+
//|                                                  AccauntInfo.mq4 |
//|                                                 TradeLikeaPro.ru |
//|                                          http://TradeLikeaPro.ru |
//+------------------------------------------------------------------+
#property copyright "TradeLikeaPro.ru"
#property link      "http://TradeLikeaPro.ru"

#property indicator_separate_window
extern string MagikInfo     = 0;              //если 0 то все магики
extern string SybmolInfo    = "";             //если "" то все инструменты

extern int Months = 12;
extern int Weeks  = 12;
extern int Days  = 12;

extern color clr_Head1 = clrGoldenrod;
extern color clr_Head2 = SteelBlue;
extern color clr_Good = Green;
extern color clr_Bad  = Red;
extern color clr_00  = Gray;

extern int Fonts = 9;
//extern bool English = false;

int win;

string shu = " [1.01] (c) TradeLikeaPro [http://TradeLikeaPro.ru]";
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
   Print(WindowExpertName() + shu);

return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int i;
   double d,dP;
   datetime dt;
   string s,txt,txt2;
   
   if (MagikInfo==0) txt = "Magiks - ALL";
      else  txt = StringConcatenate("Magik - ",MagikInfo);
      string Symb = SybmolInfo;
      Symb = StringTrimRight(Symb);
      Symb = StringTrimLeft(Symb);
   if (Symb=="") txt2 = "Symbols - ALL";
      else  txt2 = StringConcatenate("Symbol - ",SybmolInfo);

   IndicatorShortName_shu("Accaunt Info");   
   ccc(win, "");
   ccc(win, "TradeLikeaPro.ru", clr_Head1,0,615,20,20);
   ccc(win, "Account: "   + ns0(AccountNumber()),  clr_Head1, 0, 20, 20, 20);
   ccc(win, "Balance: " + ns2(AccountBalance()), clr_Good);
   ccc(win, "Equity: " + ns2(AccountEquity()),  clr_Good);
   
   d = Result(0, TimeCurrent() + 1);
   dP = ResultP(0, TimeCurrent() + 1);
   s = "Total: " + ns1(dP)+ "  (" + ns2(d) + " USD)";
   if(d == 0) ccc(win, s, clr_00);
   if(d > 0) ccc(win, s, clr_Good);
   if(d < 0) ccc(win, s, clr_Bad);
   //ccc(win, s, ((d >= 0) ? clr_Good : clr_Bad));    
   
   ccc(win, "Months ("+Months+"):", clr_Head2, 0, 210, 40, 0);
   
   for (i = 0; i > -Months; i--) {
      dt = StartMonth(TimeCurrent(), i);   
      d = Result(dt, StartMonth(dt, 1) - 1);
      dP = ResultP(dt, StartMonth(dt, 1) - 1);
      s = MonthTxt(TimeMonth(dt)) + ":  " + ns1(dP)+ "  (" + ns2(d) + " USD)";
      if(d == 0) ccc(win, s, clr_00);
      if(d > 0)  ccc(win, s, clr_Good);
      if(d < 0)  ccc(win, s, clr_Bad);
      //ccc(win, s, ((d >= 0) ? clr_Good : clr_Bad));      
   }

   ccc(win, "Weeks ("+Months+"):", clr_Head2, 0, 390, 40, 0);
   
   for (i = 0; i > -Weeks; i--) {
      dt = StartWeek(TimeCurrent(), i);   
      d = Result(dt, StartWeek(dt, 1) - 1);
      dP = ResultP(dt, StartWeek(dt, 1) - 1);
      s = TimeToStr(dt, TIME_DATE) + ":   " + ns1(dP)+ "  (" + ns2(d) + " USD)";
      if(d == 0) ccc(win, s, clr_00);
      if(d > 0)  ccc(win, s, clr_Good);
      if(d < 0)  ccc(win, s, clr_Bad);
      //ccc(win, s, ((d > 0) ? clr_Good : clr_Bad));    
   }
   
   ccc(win, "Days ("+Days+"):", clr_Head2, 0, 616, 40, 0);
   
   for (i = 0; i > -Days; i--) {
      dt = StartDay(TimeCurrent(), i);   
      d = Result(dt, StartDay(dt, 1) - 1);
      dP = ResultP(dt, StartDay(dt, 1) - 1);
      s = TimeToStr(dt, TIME_DATE) + "  "+DayTxt(TimeDayOfWeek(dt))+":  " + ns1(dP)+ "  (" + ns2(d) + " USD)";
      if(d == 0) ccc(win, s, clr_00);
      if(d > 0)  ccc(win, s, clr_Good);
      if(d < 0)  ccc(win, s, clr_Bad);
      //ccc(win, s, ((d > 0) ? clr_Good : clr_Bad));    
   }
   
  ccc(win, (""+txt+"   "+ txt2), clr_Head1, 0, 210, 20, 0);
return(0);
}
//+------------------------------------------------------------------+
void ccc(int wn = 0, string txt = "", color clr = Green, int cr = 0, int X = 0, int Y = 0, int stp = 16, string font = "Tahoma", int fs=9) {
   static int num = 0;
   static int x, y;
   static int step = 10;
   int i;
   int x0 = 0, y0 = 0;
   string on, n;

   on = "ccc" + "." + (string)wn;
   
   if (txt == "") {
      x = x0;
      y = y0;
      num = 0;
      for (i = ObjectsTotal() - 1; i >= 0 ; i--) {
         n = ObjectName(i);
         if (ObjectType(n) != OBJ_LABEL) continue;
         if (StringFind(n, on) != -1) ObjectDelete(n);
      }   
      return;
   }
   
   if (stp > 0) step = stp;
   
   if ((X <  0) || (Y <  0)) {x = x0; y = y0;} 
   if ((X >  0) || (Y >  0)) {x = X;  y = Y; } 
   
   on = on + "." + (string)num;
   
   ObjectCreate(on, OBJ_LABEL, wn, 0, 0);
   ObjectSet   (on, OBJPROP_CORNER, cr);
   ObjectSet   (on, OBJPROP_XDISTANCE, x);
   ObjectSet   (on, OBJPROP_YDISTANCE, y);
   ObjectSet   (on, OBJPROP_COLOR, clr);
   ObjectSetText(on, txt, Fonts, font, clr);
   
   num++;
   y = y + step;
   
return;
}
//+------------------------------------------------------------------+
string ns2(double Значение) {
   return(DoubleToStr(Значение, 2));
}
//+------------------------------------------------------------------+
string ns1(double Значение) {
   return(DoubleToStr(Значение, 1));
}
//+------------------------------------------------------------------+
string ns0(double Значение) {
   return(DoubleToStr(Значение, 0));
}
//+------------------------------------------------------------------+
void IndicatorShortName_shu(string s) {
   IndicatorShortName(s);
   win = WindowFind(s);
return; 
}
//+------------------------------------------------------------------+
string MonthTxt(int m) {
   string r;
   switch (m) {
      case  1:  r = "Янв";    break;
      case  2:  r = "Фев";   break;
      case  3:  r = "Мар";      break;
      case  4:  r = "Апр";    break;
      case  5:  r = "Май";       break;
      case  6:  r = "Июн";      break;
      case  7:  r = "Июл";      break;
      case  8:  r = "Авг";    break;
      case  9:  r = "Сен";  break;
      case 10:  r = "Окт";   break;
      case 11:  r = "Ноя";    break;
      case 12:  r = "Дек";   break;
      default:  r = "---";
   }
return(r);
}

string DayTxt(int m) {
   string r;
   switch (m) {
      case  0:  r = "Вс";    break;
      case  1:  r = "Пн";   break;
      case  2:  r = "Вт";      break;
      case  3:  r = "Ср";    break;
      case  4:  r = "Чт";       break;
      case  5:  r = "Пт";      break;
      case  6:  r = "Сб";      break;
      
      default:  r = "---";
   }
return(r);
}

//+------------------------------------------------------------------+
double Result(datetime dt1, datetime dt2) {
   int i;
   double r;
   int OMN;
   string Symb;
   
   r = 0;
   for (i = 0; i < OrdersHistoryTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      
         Symb = OrderSymbol();
         if (OrderSymbol()!=SybmolInfo && SybmolInfo!="") continue;
         OMN = OrderMagicNumber();
         if (MagikInfo!=OMN && MagikInfo!=0) continue;
         
         if (OrderClosePrice() == 0) continue;
         if ((OrderCloseTime() < dt1) || (OrderCloseTime() > dt2)) continue;
         r = r + OrderProfit() + OrderCommission() + OrderSwap();
      }
   }
return(r);   
}

//+------------------------------------------------------------------+
double ResultP(datetime dt1, datetime dt2) {
   int i;
   //double r;
   int OMN;
   string Symb;
   double p;
   string sy="";
   
   for (i = 0; i < OrdersHistoryTotal(); i++) {
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      
         Symb = OrderSymbol();
         if (OrderSymbol()!=SybmolInfo && SybmolInfo!="") continue;
         OMN = OrderMagicNumber();
         if (MagikInfo!=OMN && MagikInfo!=0) continue;
         
         if (OrderClosePrice() == 0) continue;
         if ((OrderCloseTime() < dt1) || (OrderCloseTime() > dt2)) continue;
         //***********
              if (OrderType()==OP_BUY) {
                 p+=(OrderClosePrice()-OrderOpenPrice())*10000;
              }
              if (OrderType()==OP_SELL) {
                p+=(OrderOpenPrice()-OrderClosePrice())*10000;
              }
         //***********
         //r = r + OrderProfit() + OrderCommission() + OrderSwap();
         
      }
   }
return(p);   
}
//+------------------------------------------------------------------+
datetime StartMonth(datetime dt = 0, int shift = 0) {
   int y, m;
   if (dt == 0) dt = TimeCurrent();
   
   y = TimeYear(dt);
   m = TimeMonth(dt);
   while (shift != 0) {
      if (shift > 0) {
         shift--;
         m++;
         if (m > 12) {
            m = 1;
            y++;
         }
      }
      if (shift < 0) {
         shift++;
         m--;
         if (m < 1) {
            m = 12;
            y--;
         }
      }
   }
   
   dt = StrToTime((string)y + "." + (string)m + ".1");
   
return(dt);   
}
//+------------------------------------------------------------------+
// * возвращаем время 
datetime StartWeek(datetime dt, int shift = 0) {
   datetime r;

   r = dt + shift * PERIOD_W1 * 60;
   
   r = r / (PERIOD_D1 * 60);
   r = r  * (PERIOD_D1 * 60);                       // - здесь получили время начала дня
   
   switch(TimeDayOfWeek(r)) {
      case 1:  break;
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
               r = r - (PERIOD_D1 * 60) * (TimeDayOfWeek(r) - 1);
               break;
      case 0:
               r = r - (PERIOD_D1 * 60) * 6;
               break;
   }
   
return(r);   
}

//+------------------------------------------------------------------+
// * возвращаем время 
datetime StartDay(datetime dt, int shift = 0) {
   datetime r;

   r = dt + shift * PERIOD_D1 * 60;
   
   r = r / (PERIOD_D1 * 60);
   r = r  * (PERIOD_D1 * 60);                       // - здесь получили время начала дня
   
   
   
return(r);   
}
//+------------------------------------------------------------------+

