//+------------------------------------------------------------------+
//|                                                     +info_M+.mq4 |
//|                                        Copyright © 2008, masemus |
//|                                    Gresik - EastJAVA - Indonesia |
//+------------------------------------------------------------------+
#property copyright "masemus"
#property link      "masemus@yahoo.com"

#property indicator_chart_window
//---- Pos!
extern int window        = 0;
extern int corner        = 2;
extern int y_offset      = 0;
extern int x_offset      = 125;
extern string Fonts      = "Trebucet Bold";
extern int FontSZ        = 24;
extern color xCandle_clr = Yellow;
extern color Time_clr    = RosyBrown;
extern color Pivot_clr   = Magenta;
extern color Label_clr   = SlateGray;
extern color BGFront_clr = White;
extern color BGBack_clr  = Silver;

#import "kernel32.dll"
void GetLocalTime(int& TimeArray[]);
void GetSystemTime(int& TimeArray[]);
int  GetTimeZoneInformation(int& TZInfoArray[]);
#import

string TimeToString( datetime when ) {
   int hour = TimeHour( when );
   int minute = TimeMinute( when );
   
   string timeStr;
   timeStr = DoubleToStr( hour, 0 ) + ":";
   if ( minute < 10 )
      timeStr = timeStr + "0";
   timeStr = timeStr + DoubleToStr( minute, 0 );
   
   return (timeStr);
}


//+------------------------------------------------------------------+
//| Custom indicator interation function                              |
//+------------------------------------------------------------------+
int start()
  {    
  if ( !IsDllsAllowed() ) {
      Alert( "Clock : DLLs are disabled.  To enable tick the checkbox in the Common Tab of indicator" );
      return;
  }
   int    counted_bars=IndicatorCounted();
//----
      
   int    TimeArray[4];
   int    TZInfoArray[43];
   int    nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;
   string sMilliSec;
   
   GetLocalTime(TimeArray);
//---- parse date and time from array
   nYear=TimeArray[0]&0x0000FFFF;
   nMonth=TimeArray[0]>>16;
   nDay=TimeArray[1]>>16;
   nHour=TimeArray[2]&0x0000FFFF;
   nMin=TimeArray[2]>>16;
   nSec=TimeArray[3]&0x0000FFFF;
   nMilliSec=TimeArray[3]>>16;
   string LocalTimeS = FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec);
   datetime localTime = StrToTime( LocalTimeS );


   int gmt_shift=0;
   int dst=GetTimeZoneInformation(TZInfoArray);
   if(dst!=0) gmt_shift=TZInfoArray[0];
   if(dst==2) gmt_shift+=TZInfoArray[42];

   datetime brokerTime = CurTime();
   datetime WIB = localTime + gmt_shift * 60;
   
   //Print( brokerTime, " ", WIB, " " );
   string WIBs = TimeToString( WIB );
   string brokers = TimeToString( CurTime() );
   
//----
   //Info
   string Teks="", Teks_Menit, Teks_Detik;
   double d_A, d_B;

   //Time for Next Candle
   d_B = (Time[4]-Time[5])-MathMod(CurTime(),Time[4]-Time[5]);
   d_A = d_B/60;
   d_B = (d_A-MathFloor(d_A))*60;
   d_A = MathFloor(d_A);
   Teks_Menit = DoubleToStr(d_A,0);
   Teks_Detik = DoubleToStr(d_B,0);
   Teks=Teks_Menit+":"+Teks_Detik;

   //Price
   double Price1 = iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0);   
    Teks=DoubleToStr(Price1,Digits);

   int R1=0,R5=0,R10=0,R20=0,RAvg=0,i=0;
   R1 =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
   for(i=1;i<=5;i++)
      R5    =    R5  +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=10;i++)
      R10   =    R10 +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
   for(i=1;i<=20;i++)
      R20   =    R20 +  (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

   R5 = R5/5;
   R10 = R10/10;
   R20 = R20/20;
   RAvg  =  (R1+R5+R10+R20)/4;    
   
   string HI="",LO="",SPREAD="",PIPS="",DAV="",HILO="",PRC,Pips="",Av="",
          AV_Yest="",OPEN="",Pivot="";
   color color_pip,color_av,color_op;
   double Open_Today = iOpen(NULL,1440,0);
   double CLOSE = iClose(NULL,1440,0);
   double SPRD = (Ask - Bid)/Point;
   double High_Today = iHigh(NULL,1440,0);
   double Low_Today = iLow(NULL,1440,0);
   PIPS =  DoubleToStr((CLOSE-Open_Today)/Point,0);
   SPREAD = (DoubleToStr(SPRD,Digits-4));
   DAV = (DoubleToStr(RAvg,Digits-4));
   AV_Yest =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
   HILO = DoubleToStr((High_Today-Low_Today)/Point,0);
   OPEN =  (DoubleToStr(Open_Today,Digits));
   HI =  (DoubleToStr(High_Today,Digits));
   LO =  (DoubleToStr(Low_Today,Digits));
  
   double D1P = (iHigh(NULL,PERIOD_D1,1) + iLow(NULL,PERIOD_D1,1) + iClose(NULL,PERIOD_D1,1))/3;
   Pivot = DoubleToStr(D1P,Digits);

     if (CLOSE >= Open_Today)
        {Pips= "-";color_pip = LimeGreen;color_op = DarkOrange; }
     if (CLOSE < Open_Today)
        {Pips= "-";color_pip = DarkOrange;color_op = LimeGreen; }
     if (DAV > AV_Yest)
        {Av= "-";color_av = LimeGreen; }
     if (DAV < AV_Yest)
        {Av= "-";color_av = DarkOrange; }

//----
   string MTF="";
   double cTF=Period();

               if (cTF==PERIOD_M1) { MTF="M1"; }
               if (cTF==PERIOD_M5) { MTF="M5"; }
               if (cTF==PERIOD_M15) { MTF="M15"; }
               if (cTF==PERIOD_M30) { MTF="M30"; }
               if (cTF==PERIOD_H1) { MTF="H1"; }
               if (cTF==PERIOD_H4) { MTF="H4"; }
               if (cTF==PERIOD_D1) { MTF="D1"; }
               if (cTF==PERIOD_W1) { MTF="W1"; }
               if (cTF==PERIOD_MN1) { MTF="MN1"; }

//----
   ObjectSetText( "BG01", "g", 88, "Webdings", BGBack_clr );
   ObjectSetText( "BG02", "g", 88, "Webdings", BGBack_clr );
   ObjectSetText( "BG03", "g", 88, "Webdings", BGBack_clr );
   ObjectSetText( "BG04", "g", 82, "Webdings", BGFront_clr );
   ObjectSetText( "BG05", "g", 82, "Webdings", BGFront_clr );

   ObjectSetText( "wibL", ":: Gresik", 7, "Arial", Label_clr );
   ObjectSetText( "wibT", ": "+WIBs+"", 9, "Arial", Time_clr );
   ObjectSetText( "broL", ":: Broker", 7, "Arial", Label_clr );
   ObjectSetText( "broT", ": "+brokers+"", 9, "Arial", Time_clr );
      
   ObjectSetText("mycandleTM", Teks_Menit+":"+Teks_Detik, FontSZ, Fonts, xCandle_clr);

   ObjectSetText("opD1L", "D1 Open", 7, "Arial", Label_clr);
   ObjectSetText("opD1T", ": "+OPEN+"", 9, "Arial", color_op);
   ObjectSetText("pvD1L", "D1 Pivot", 7, "Arial", Label_clr);
   ObjectSetText("pvD1T", ": "+Pivot+"", 9, "Arial", Pivot_clr);
   ObjectSetText("Pip2OpL", "Pips2OP", 7, "Arial",  Label_clr);
   ObjectSetText("Pip2OpT", ": "+PIPS+"", 9, "Arial",  color_pip);
   ObjectSetText("H2LL", "Hi2Lo", 7, "Arial",  Label_clr);
   ObjectSetText("H2LT", ": "+HILO+"", 9, "Arial",  Time_clr);
   ObjectSetText("DAvL", "Daily Av.", 7, "Arial",  Label_clr);
   ObjectSetText("DAvT", ": "+DAV+"", 9, "Arial",  color_av);
   ObjectSetText("SpreadL", "Spread", 7, "Arial",  Label_clr);
   ObjectSetText("SpreadT", ": "+SPREAD+"", 9, "Arial",  Time_clr);
   ObjectSetText("PriceT", Teks, 24, Fonts,  BGBack_clr);
   ObjectSetText("PairT", Symbol(), 14, "Arial Narrow Bold",  BGFront_clr);
   ObjectSetText("PeriodT", MTF, 14, "Arial Narrow Bold",  xCandle_clr);
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int CreateOL( string n, int xoff, int yoff ) {
   ObjectCreate( n, OBJ_LABEL, window, 0, 0 );
   ObjectSet( n, OBJPROP_CORNER, corner );
   ObjectSet( n, OBJPROP_XDISTANCE, xoff );
   ObjectSet( n, OBJPROP_YDISTANCE, yoff );
   ObjectSet( n, OBJPROP_BACK, false );
}

string FormatDateTime(int nYear,int nMonth,int nDay,int nHour,int nMin,int nSec)
  {
   string sMonth,sDay,sHour,sMin,sSec;
//----
   sMonth=100+nMonth;
   sMonth=StringSubstr(sMonth,1);
   sDay=100+nDay;
   sDay=StringSubstr(sDay,1);
   sHour=100+nHour;
   sHour=StringSubstr(sHour,1);
   sMin=100+nMin;
   sMin=StringSubstr(sMin,1);
   sSec=100+nSec;
   sSec=StringSubstr(sSec,1);
//----
   return(StringConcatenate(nYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec));
  }

int init()
  {

//---- 
   IndicatorShortName("");  
//---- indicators
   CreateOL( "BG01", x_offset+3, y_offset+3 );
   CreateOL( "BG02", x_offset+3, y_offset+73 );
   CreateOL( "BG03", x_offset+3, y_offset+122 );
   CreateOL( "BG04", x_offset+7, y_offset+42 );
   CreateOL( "BG05", x_offset+7, y_offset+100 );
//----
   CreateOL( "broL", x_offset+12, y_offset+49 );
   CreateOL( "broT", x_offset+64, y_offset+49 );
   CreateOL( "wibL", x_offset+12, y_offset+64 );
   CreateOL( "wibT", x_offset+64, y_offset+64 );
   CreateOL( "mycandleTM", x_offset+11, y_offset+5 );
//----
   CreateOL( "pvD1L", x_offset+12, y_offset+79 );
   CreateOL( "pvD1T", x_offset+64, y_offset+79 );
   CreateOL( "opD1L", x_offset+12, y_offset+94 );
   CreateOL( "opD1T", x_offset+64, y_offset+94 );
   CreateOL( "Pip2OpL", x_offset+12, y_offset+109 );
   CreateOL( "Pip2OpT", x_offset+64, y_offset+109 );
   CreateOL( "H2LL", x_offset+12, y_offset+124 );
   CreateOL( "H2LT", x_offset+64, y_offset+124 );
   CreateOL( "DAvL", x_offset+12, y_offset+139 );
   CreateOL( "DAvT", x_offset+64, y_offset+139 );
   CreateOL( "SpreadL", x_offset+12, y_offset+154 );
   CreateOL( "SpreadT", x_offset+64, y_offset+154 );
   CreateOL( "PriceT", x_offset+11, y_offset+169 );
   CreateOL( "PairT", x_offset+11, y_offset+212 );
   CreateOL( "PeriodT", x_offset+79, y_offset+212 );
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("BG01");      ObjectDelete("BG02");
   ObjectDelete("BG03");      ObjectDelete("BG04");
   ObjectDelete("BG05");      ObjectDelete("mycandleTM");
   ObjectDelete("wibL");      ObjectDelete("wibT");
   ObjectDelete("broL");      ObjectDelete("broT");
//----
   ObjectDelete("opD1L");     ObjectDelete("opD1T");
   ObjectDelete("pvD1L");     ObjectDelete("pvD1T");
   ObjectDelete("Pip2OpL");   ObjectDelete("Pip2OpT");
   ObjectDelete("H2LL");      ObjectDelete("H2LT");
   ObjectDelete("DAvL");      ObjectDelete("DAvT");
   ObjectDelete("SpreadL");   ObjectDelete("SpreadT");
   ObjectDelete("PriceT");    ObjectDelete("PairT");
   ObjectDelete("PeriodT");    
//----
   return(0);
  }
//+------------------------------------------------------------------+