//+------------------------------------------------------------------+
//|                                                    InfoPanel.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.01"
#property strict

#property indicator_chart_window

extern color price_color   = DimGray;
extern color priceup_color = Teal;
extern color pricedw_color = FireBrick;
extern color symbol_color  = DimGray;
extern color spread_color  = DimGray;
extern color time_color    = DimGray;
extern color background    = DarkGray;
extern int   corner        = 3;
extern int   xdistance     = 15;
extern int   ydistance     = 15;

double Price;
string Market_Price        = DoubleToStr(Bid, Digits);
string Symb                = Symbol();
int    TF                  = Period();
double Spread              = MarketInfo(Symbol(), MODE_SPREAD);
double PT                  = 1;
string Current_Time        = TimeToStr(TimeCurrent(), TIME_MINUTES);

//+------------------------------------------------------------------+
//| Indicator initialization function                                |
//+------------------------------------------------------------------+
int init()
  {
//---
   if (Digits == 5 || Digits == 3) PT = 10;
   Spread /= PT;
   
   ObjectCreate("Info_Back_1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Back_1", "g", 91, "Webdings", background);
   ObjectSet("Info_Back_1", OBJPROP_BACK, false);
   ObjectSet("Info_Back_1", OBJPROP_CORNER, corner);
   ObjectSet("Info_Back_1", OBJPROP_XDISTANCE, xdistance);
   ObjectSet("Info_Back_1", OBJPROP_YDISTANCE, ydistance);

   ObjectCreate("Info_Back_2", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Back_2", "g", 91, "Webdings", background);
   ObjectSet("Info_Back_2", OBJPROP_BACK, false);
   ObjectSet("Info_Back_2", OBJPROP_CORNER, corner);
   ObjectSet("Info_Back_2", OBJPROP_XDISTANCE, xdistance+48);
   ObjectSet("Info_Back_2", OBJPROP_YDISTANCE, ydistance);
   
   ObjectCreate("Info_Price", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Price", Market_Price, 22, "Arial Black", price_color);
   ObjectSet("Info_Price", OBJPROP_BACK, false);
   ObjectSet("Info_Price", OBJPROP_CORNER, corner);
   ObjectSet("Info_Price", OBJPROP_XDISTANCE, xdistance+15);
   ObjectSet("Info_Price", OBJPROP_YDISTANCE, ydistance+78);
   
   ObjectCreate("Info_Sep_1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Sep_1", "-----------------------", 14, "Arial Black", symbol_color);
   ObjectSet("Info_Sep_1", OBJPROP_BACK, false);
   ObjectSet("Info_Sep_1", OBJPROP_CORNER, corner);
   ObjectSet("Info_Sep_1", OBJPROP_XDISTANCE, xdistance+15);
   ObjectSet("Info_Sep_1", OBJPROP_YDISTANCE, ydistance+64);
   
   ObjectCreate("Info_Symbol", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Symbol", Symb+" "+TFToStr(TF), 14, "Arial Black", symbol_color);
   ObjectSet("Info_Symbol", OBJPROP_BACK, false);
   ObjectSet("Info_Symbol", OBJPROP_CORNER, corner);
   ObjectSet("Info_Symbol", OBJPROP_XDISTANCE, xdistance+15);
   ObjectSet("Info_Symbol", OBJPROP_YDISTANCE, ydistance+50);
   
   ObjectCreate("Info_Sep_2", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Sep_2", "-----------------------", 14, "Arial Black", symbol_color);
   ObjectSet("Info_Sep_2", OBJPROP_BACK, false);
   ObjectSet("Info_Sep_2", OBJPROP_CORNER, corner);
   ObjectSet("Info_Sep_2", OBJPROP_XDISTANCE, xdistance+15);
   ObjectSet("Info_Sep_2", OBJPROP_YDISTANCE, ydistance+39);
   
   ObjectCreate("Info_Spread", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Spread", "SPREAD "+DoubleToStr(Spread, 1), 10, "Arial Black", spread_color);
   ObjectSet("Info_Spread", OBJPROP_BACK, false);
   ObjectSet("Info_Spread", OBJPROP_CORNER, corner);
   ObjectSet("Info_Spread", OBJPROP_XDISTANCE, xdistance+15);
   ObjectSet("Info_Spread", OBJPROP_YDISTANCE, ydistance+25);
   
   ObjectCreate("Info_Time", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Info_Time", "TIME "+Current_Time, 10, "Arial Black", time_color);
   ObjectSet("Info_Time", OBJPROP_BACK, false);
   ObjectSet("Info_Time", OBJPROP_CORNER, corner);
   ObjectSet("Info_Time", OBJPROP_XDISTANCE, xdistance+15);
   ObjectSet("Info_Time", OBJPROP_YDISTANCE, ydistance+10);
   
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Indicator deinitialization function                              |
//+------------------------------------------------------------------+
int deinit()
  {
//---
   ObjectDelete("Info_Back_1");
   ObjectDelete("Info_Back_2");
   ObjectDelete("Info_Price");
   ObjectDelete("Info_Sep_1");
   ObjectDelete("Info_Symbol");
   ObjectDelete("Info_Sep_2");
   ObjectDelete("Info_Spread");
   ObjectDelete("Info_Time");
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Indicator main function                                          |
//+------------------------------------------------------------------+
int start()
  {
//---
   if (Market_Price != DoubleToStr(Bid, Digits)) {
      
      Market_Price = DoubleToStr(Bid, Digits);
      
      color current            = price_color;
      if (Bid > Price) current = priceup_color;
      if (Bid < Price) current = pricedw_color;
      Price = Bid;
      
      ObjectSetText("Info_Price", Market_Price, 22, "Arial Black", current);
   }
   
   if ((Symb != Symbol()) || (TF != Period())) {
      
      Symb = Symbol();
      TF = Period();
      ObjectSetText("Info_Symbol", Symb+" "+TFToStr(TF), 14, "Arial Black", symbol_color);
   }
   
   if (Spread != MarketInfo(Symbol(), MODE_SPREAD)) {
      
      Spread = MarketInfo(Symbol(), MODE_SPREAD);
      if (Digits == 5 || Digits == 3) PT = 10;
      Spread /= PT;
      ObjectSetText("Info_Spread", "SPREAD "+DoubleToStr(Spread, 1), 10, "Arial Black", spread_color);
   }
   
   if (Current_Time != TimeToStr(TimeCurrent(), TIME_MINUTES)) {
      
      Current_Time = TimeToStr(TimeCurrent(), TIME_MINUTES);
      ObjectSetText("Info_Time", "TIME "+Current_Time, 10, "Arial Black", time_color);
   }
   
   return(0);
  }

//+------------------------------------------------------------------+
string TFToStr(int t)
//+------------------------------------------------------------------+
// Converts a MT4-numeric timeframe to its descriptor string
// Usage:   string s=TFToStr(15) returns s="M15"
{
  switch (t)  {
    case     1 :  return("M1");
    case     5 :  return("M5");
    case    15 :  return("M15");
    case    30 :  return("M30");
    case    60 :  return("H1");
    case   240 :  return("H4");
    case  1440 :  return("D1");
    case 10080 :  return("W1");
    case 43200 :  return("MN");
  }  
  return("");
}
