#property copyright "Copyright @ 2014"
#property link      "email: none@none.com" 
#property indicator_chart_window
#include <stdlib.mqh>
#import "kernel32.dll"
void GetLocalTime(int &LocalTimeArray[]);
void GetSystemTime(int &systemTimeArray[]);
int  GetTimeZoneInformation(int &LocalTZInfoArray[]);
bool SystemTimeToTzSpecificLocalTime(int &targetTZinfoArray[],
                                     int &systemTimeArray[],int &targetTimeArray[]);
#import

/*
Session_Lines_On
Session_Labels_On
Show_Asian_Open
Show_Frankfurt_Open
Current_Session_Max_TF
Previous_Session_Max_TF
Amount_of_Previous_Sessions
Session_Lines                 Settings:
Lines_Color
Lines_Style_01234
Lines_Width_012345
Lines_sub_windows
Session_Labels                Settings:
Labels_Color
Labels_Font
Labels_FontSize

*/
extern bool   Session_Lines_On                       = true;
extern bool   Session_Labels_On                      = true;
extern bool   Show_Asian_Open            = false;
extern bool   Show_Frankfurt_Open            = false;
extern int    Current_Session_Max_TF        = 60;
extern int    Previous_Session_Max_TF         = 60;
extern int    Amount_of_Previous_Sessions        = 10;
extern string Lines_Settings="Session Lines Settings:";
extern color  Lines_Color                    = C'090,150,210';
extern int    Lines_Style_01234              = 2;
extern int    Lines_Width_12345              = 1;
extern bool   Lines_sub_windows          = false;
extern string Labels_Settings="Session Labels Settings:";
extern color  Labels_Color                   = C'025,115,165';
extern string Labels_Font                      = "Verdana";
extern int    Labels_FontSize                       = 7;



string TF_Choices                      = "1-5-15-30-60-240-1440-10080-43200";



//+-------------------------------------------------------------------------------------------+
//| Indicator Initialization                                                                  |                                                        
//+-------------------------------------------------------------------------------------------+      
int init()
  {
//With the first DLL call below, the program will exit (and stop) automatically after one alert. 
   if(!IsDllsAllowed())
     {
      Alert(Symbol()," ",Period(),": Access Panel: Allow DLL Imports"); return(false);
     }
//Determine the current chart scale (chart scale number should be 0-5)
   Chart_Scale=ChartScaleGet();

//Reset to Signal State of Non-deinitialization 
   Deinitialized=false;

//Panel - determine display of Market Price            
   if(Digits==5 || Digits==3) {Factor=10;}
   else {Factor=1;} //cater for 5 digits 

                    //Panel and Levels - Check for unconventional Point digits number. 
   Poin2=Point;
   if(Point==0.00001) {Poin=0.0001;} //5 digits     
   else
     {
      if(Point==0.001) {Poin=0.01;} //3 digits
      else {Poin=Point;}
     } //Normal 4 digits       
   if(StringSubstr(Symbol(),0,6)=="XAUUSD") {Poin=0.1;}
   else
     {
      if(StringSubstr(Symbol(),0,6)=="EURTRY") {Poin=0.001;}
      else
        {
         if(StringSubstr(Symbol(),0,6)=="USDTRY") {Poin=0.001;}
         else
           {
            if(StringSubstr(Symbol(),0,6)=="USDMXN") {Poin=0.001;}
            else {if(StringSubstr(Symbol(),0,6)=="USDCZK") {Poin=0.001;} }
           }
        }
     }

//Levels - set ranges for chart TFs 
   if(Period()==1) {NumberOfRanges=4;}
   else
     {
      if(Period()==5) {NumberOfRanges=7;}
      else
        {
         if(Period()==15) {NumberOfRanges=15;}
         else
           {
            if(Period()==30) {NumberOfRanges=15;}
            else
              {
               if(Period()==60) {NumberOfRanges=20;}
               else
                 {
                  if(Period()==240) {NumberOfRanges=30;}
                  else
                    {
                     if(Period()==1440) {NumberOfRanges=60;}
                     else
                       {
                        if(Period()==10080) {NumberOfRanges=70;}
                        else {if(Period()==43200) {NumberOfRanges=60;} }
                       }
                    }
                 }
              }
           }
        }
     }

//Import Time Zone Data  required for PivotsTZ and vLines      
   StaticBrokerDT=TimeCurrent();
   Get04TimeZoneInfo(SydneyTZInfoArray,BerlinTZInfoArray,
                     LondonTZInfoArray,NewYorkTZInfoArray);


   return(0);
  }
//+-------------------------------------------------------------------------------------------+
//| Indicator De-initialization                                                               |                                                        
//+-------------------------------------------------------------------------------------------+       
int deinit()
  {
   obj_total=ObjectsTotal();
   for(k=obj_total; k>=0; k--)
     {
      name=ObjectName(k);
      if(StringSubstr(name,0,5)=="[C2P2" || StringSubstr(name,1,5)=="[C2P2") {ObjectDelete(name);}
     }
//Comment("");
   return(0);
  }
//+-------------------------------------------------------------------------------------------+
//| Indicator Start                                                                           |                                                        
//+-------------------------------------------------------------------------------------------+         
int start()
  {
//If Indicator is "Off" deinitialize only once, not every tick-------------------------------  
   if(!Indicator_On)
     {
      if(!Deinitialized) {deinit(); Deinitialized=true;}
      return(0);
     }

//If indicator is "ON" delete all objects----------------------------------------------------
   obj_total=ObjectsTotal();
   for(k=obj_total; k>=0; k--)
     {
      name=ObjectName(k);
      if(StringSubstr(name,0,5)=="[C2P2" || StringSubstr(name,1,5)=="[C2P2") {ObjectDelete(name);}
     }


//Bid Line----------------------------------------------------------------------------------- 
   if(Bid_Line_On)
     {
      //Set T2                    
      T2=Time[0];
      //Set T1                     
      if(Chart_Scale==0) {T1=Time[0]+(Period()*60*8);}
      else
        {
         if(Chart_Scale==1) {T1=Time[0]+(Period()*60*4);}
         else
           {
            if(Chart_Scale==2) {T1=Time[0]+(Period()*60*2);}
            else
              {
               if(Chart_Scale==3) {T1=Time[0]+(Period()*60*1);}
               else
                 {
                  if(Chart_Scale==4) {T1=Time[0]+(Period()*60*1);}
                  else {if(Chart_Scale==5) {T1=Time[0]+(Period()*60*1);} }
                 }
              }
           }
        }
      if(Period()==43200) {T1=T1+(Period()*60*1);}
      //Bid line   
      ObjectCreate(item20,OBJ_TREND,0,T1,Bid,T2,Bid);
      ObjectSet(item20,OBJPROP_STYLE,Bid_Ray_LineStyle_01234);
      ObjectSet(item20,OBJPROP_COLOR,Bid_Ray_Color);
      ObjectSet(item20,OBJPROP_WIDTH,Bid_Ray_Thickness);
      //Bid dot                   
      ObjectCreate(item21,OBJ_TREND,0,T1,Bid,T1,Bid);
      ObjectSet(item21,OBJPROP_STYLE,0);
      ObjectSet(item21,OBJPROP_COLOR,Bid_Dot_Color);
      ObjectSet(item21,OBJPROP_WIDTH,Bid_Dot_Size);
     }//End Bid Line


//Clock, PivotsTZ and vLines-----------------------------------------------------------------
//Go to subroutine to get TZ info needed for Clock, PivotsTZ and vLines
   if( Session_Lines_On)
     {
      GetSystemTime(systemTimeArray);
      UTC=TimeArrayToTime(systemTimeArray);
      BrokerDT=TimeCurrent();
     }
   if(Session_Lines_On)
     {
      SystemTimeToTzSpecificLocalTime(SydneyTZInfoArray,systemTimeArray,SydneyTimeArray);
      SydneyDT=TimeArrayToTime(SydneyTimeArray);
      SystemTimeToTzSpecificLocalTime(BerlinTZInfoArray,systemTimeArray,BerlinTimeArray);
      BerlinDT=TimeArrayToTime(BerlinTimeArray);
      SystemTimeToTzSpecificLocalTime(LondonTZInfoArray,systemTimeArray,LondonTimeArray);
      LondonDT=TimeArrayToTime(LondonTimeArray);
      SystemTimeToTzSpecificLocalTime(NewYorkTZInfoArray,systemTimeArray,NewYorkTimeArray);
      NewYorkDT=TimeArrayToTime(NewYorkTimeArray);
     }
   if(Show_Clock_in_Panel && (Pivots_PVT_On || Pivots_SR_On))
     {
      pvtDT=UTC+Broker_GMT_Offset*3600;
     }

//PivotsTZ and vLines------------------------------------------------------------------------    
//With required time zone data imported, define parameters for PivotsTZ and vLines  
//if vLines is "on", then calculate GMT at Lo, Ny and Lc, and   
   if(Session_Lines_On && Period()<=Current_Session_Max_TF)
     {
      //Make 8am the "reference time" at GMT for London Open
      GMT_Ref_Time=8;

      //Find GMT At Ao (when Sydney is at 9am local)
      Sydney_GMT_Offset=(SydneyDT/3600-UTC/3600);
      GMT_At_Ao=GMT_Ref_Time-Sydney_GMT_Offset+1; //+1 because Syndey opens 9am local, not 8am
                                                  //if(GMT_At_Ao < 0) {GMT_At_Ao = GMT_At_Ao +24;}

      //Find GMT At Fo (when Berlin is at 8am local)             
      Berlin_GMT_Offset=BerlinDT/3600-UTC/3600;
      GMT_At_Fo=GMT_Ref_Time-Berlin_GMT_Offset;

      //Find GMT At Lo (when London is at 8am local)             
      London_GMT_Offset=LondonDT/3600-UTC/3600;
      GMT_At_Lo=GMT_Ref_Time-London_GMT_Offset;

      //Find GMT At Ny (when New York is at 8am local)
      NYC_GMT_Offset=NewYorkDT/3600-UTC/3600;
      GMT_At_NYo=GMT_Ref_Time-NYC_GMT_Offset;

      //Find GMT At Lc (nine hours after London Open)
      GMT_At_Lc=GMT_At_Lo+9;
     }

//if vLines is "on", or if PivotsTz is "on", then calculate "Broker_GMT_Offset".    
   if((Session_Lines_On && Period()<=Current_Session_Max_TF) )
     {
      //Compute "Broker_GMT_Offset" only when the data feed is live.  When the data feed 
      //is not live, then set "Apply_it_now" to "true" so that the manually input value
      //for "Broker_GMT_Offset" is used instead of computing it. 
      if(!Apply_it_now_because_feed_is_not_live)
        {
         Broker_GMT_Offset=BrokerDT/3600-UTC/3600;
        }
     }



//vLines-------------------------------------------------------------------------------------
   if(Session_Lines_On && Period()<=Current_Session_Max_TF)
     {
      //Calculate position for vline labels------------------------------------------------------
      if(Session_Labels_On)
        {
         if(vLabels_Dist_To_Border<1) {vLabels_Dist_To_Border=1;}
         top=WindowPriceMax();
         bottom= WindowPriceMin();
         scale = top-bottom;
         if(vLabels_Chart_Top)
           {
            YadjustTop = scale/(13000/FontSize);
            YadjustTop = YadjustTop + (vLabels_Dist_To_Border * YadjustTop);
            level=top-YadjustTop;
           }
         else if(!vLabels_Chart_Top)
           {
            vLabels_Dist_Above_Border=vLabels_Dist_To_Border+3;
            YadjustBot = scale/(500/FontSize);
            YadjustBot = YadjustBot + ((vLabels_Dist_Above_Border * YadjustBot)/20);
            level=bottom+YadjustBot;
           }
        }

      //Do vlines for current session------------------------------------------------------------       
      if(Broker_GMT_Offset==0 && DayOfWeek()==0)
        {
         if(Show_Asian_Open)
           {
            OpenToday(vLabels_Asian_Open,GMT_At_Ao+Broker_GMT_Offset,
                      Lines_Color,Lines_Style_01234,Lines_Width_12345,level);
           }
         //Calculate bars per session        
         if(Period()==1) {bps=1440;}
         else
           {
            if(Period()==5) {bps=288;}
            else
              {
               if(Period()==15){bps=96;}
               else
                 {
                  if(Period()==30){bps=48;}
                  else {if(Period()==60){bps=24;} }
                 }
              }
           }
         //Define bar starting prior sessions display      
         shift=iBarShift(NULL,NULL,iTime(NULL,PERIOD_D1,0));
         //Execute loop for bars per session X number of prior sessions to show    
         for(i=shift; i<=(shift+bps); i++)
           {
            h=TimeHour(Time[i]);
            m=TimeMinute(Time[i]);

            //London Open vLine
            if(GMT_At_Lo+Broker_GMT_Offset<0) {GMT_At_Lo=GMT_At_Lo+24;}
            MF=MathFloor(GMT_At_Lo);
            if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
              {
               OpenPrior(i,vLabels_London_Open,Lines_Color,Lines_Style_01234,
                         Lines_Width_12345,level);
              }
            else
              {
               if((GMT_At_Lo!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                 {
                  OpenPrior(i,vLabels_London_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Lo==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                    {
                     OpenPrior(i,vLabels_London_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                 }
              }

            //NewYork Open vLine             
            if(GMT_At_NYo+Broker_GMT_Offset<0) {GMT_At_NYo=GMT_At_NYo+24;}
            MF=MathFloor(GMT_At_NYo);
            if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
              {
               OpenPrior(i,vLabels_NewYork_Open,Lines_Color,Lines_Style_01234,
                         Lines_Width_12345,level);
              }
            else
              {
               if((GMT_At_NYo!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                 {
                  OpenPrior(i,vLabels_NewYork_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_NYo==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                    {
                     OpenPrior(i,vLabels_NewYork_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                 }
              }

            //London Close vLine           
            if(GMT_At_Lc+Broker_GMT_Offset<0) {GMT_At_Lc=GMT_At_Lc+24;}
            MF=MathFloor(GMT_At_Lc);
            if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
              {
               OpenPrior(i,vLabels_London_Close,Lines_Color,Lines_Style_01234,
                         Lines_Width_12345,level);
              }
            else
              {
               if((GMT_At_Lc!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                 {
                  OpenPrior(i,vLabels_London_Close,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Lc==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                    {
                     OpenPrior(i,vLabels_London_Close,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                 }
              }

            //Berlin Open vLine
            if(Show_Frankfurt_Open)
              {
               if(GMT_At_Fo+Broker_GMT_Offset<0) {GMT_At_Fo=GMT_At_Fo+24;}
               MF=MathFloor(GMT_At_Fo);
               if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
                 {
                  OpenPrior(i,vLabels_Berlin_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Fo!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                    {
                     OpenPrior(i,vLabels_Berlin_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                  else
                    {
                     if((GMT_At_Fo==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                       {
                        OpenPrior(i,vLabels_Berlin_Open,Lines_Color,Lines_Style_01234,
                                  Lines_Width_12345,level);
                       }
                    }
                 }
              }
           }//End prior sessions shift loop                                
        }//End Short Sunday loop for broker at GMT 

      else //for all brokers Monday thru Friday 
        {
         if(Show_Asian_Open)
           {
            OpenToday(vLabels_Asian_Open,GMT_At_Ao+Broker_GMT_Offset,
                      Lines_Color,Lines_Style_01234,Lines_Width_12345,level);
           }
         if(Show_Frankfurt_Open)
           {
            OpenToday(vLabels_Berlin_Open,GMT_At_Fo+Broker_GMT_Offset,
                      Lines_Color,Lines_Style_01234,Lines_Width_12345,level);
           }
         OpenToday(vLabels_London_Open,GMT_At_Lo+Broker_GMT_Offset,
                   Lines_Color,Lines_Style_01234,Lines_Width_12345,level);
         OpenToday(vLabels_NewYork_Open,GMT_At_NYo+Broker_GMT_Offset,
                   Lines_Color,Lines_Style_01234,Lines_Width_12345,level);
         OpenToday(vLabels_London_Close,GMT_At_Lc+Broker_GMT_Offset,
                   Lines_Color,Lines_Style_01234,Lines_Width_12345,level);
        }

      //Do vlines for previous sessions----------------------------------------------------------
      if(Amount_of_Previous_Sessions>0 && Period()<=Previous_Session_Max_TF)
        {
         //Calculate bars per session        
         if(Period()==1) {bps=1440;}
         else
           {
            if(Period()==5) {bps=288;}
            else
              {
               if(Period()==15){bps=96;}
               else
                 {
                  if(Period()==30){bps=48;}
                  else {if(Period()==60){bps=24;} }
                 }
              }
           }
         //Define bar starting prior sessions display      
         shift=iBarShift(NULL,NULL,iTime(NULL,PERIOD_D1,0));
         //Execute loop for bars per session X number of prior sessions to show    
         for(i=shift; i<=(shift+(bps*(Amount_of_Previous_Sessions))); i++)
           {
            h=TimeHour(Time[i]);
            m=TimeMinute(Time[i]);

            //London Open vLine
            if(GMT_At_Lo+Broker_GMT_Offset<0) {GMT_At_Lo=GMT_At_Lo+24;}
            MF=MathFloor(GMT_At_Lo);
            if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
              {
               OpenPrior(i,vLabels_London_Open,Lines_Color,Lines_Style_01234,
                         Lines_Width_12345,level);
              }
            else
              {
               if((GMT_At_Lo!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                 {
                  OpenPrior(i,vLabels_London_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Lo==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                    {
                     OpenPrior(i,vLabels_London_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                 }
              }

            //NewYork Open vLine             
            if(GMT_At_NYo+Broker_GMT_Offset<0) {GMT_At_NYo=GMT_At_NYo+24;}
            MF=MathFloor(GMT_At_NYo);
            if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
              {
               OpenPrior(i,vLabels_NewYork_Open,Lines_Color,Lines_Style_01234,
                         Lines_Width_12345,level);
              }
            else
              {
               if((GMT_At_NYo!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                 {
                  OpenPrior(i,vLabels_NewYork_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_NYo==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                    {
                     OpenPrior(i,vLabels_NewYork_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                 }
              }

            //London Close vLine           
            if(GMT_At_Lc+Broker_GMT_Offset<0) {GMT_At_Lc=GMT_At_Lc+24;}
            MF=MathFloor(GMT_At_Lc);
            if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
              {
               OpenPrior(i,vLabels_London_Close,Lines_Color,Lines_Style_01234,
                         Lines_Width_12345,level);
              }
            else
              {
               if((GMT_At_Lc!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                 {
                  OpenPrior(i,vLabels_London_Close,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Lc==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                    {
                     OpenPrior(i,vLabels_London_Close,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                 }
              }

            //Asian Open vLine
            if(Show_Asian_Open)
              {
               if(GMT_At_Ao+Broker_GMT_Offset<0) {GMT_At_Ao=GMT_At_Ao+24;}
               MF=MathFloor(GMT_At_Ao);
               if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
                 {
                  OpenPrior(i,vLabels_Asian_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Ao!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                    {
                     OpenPrior(i,vLabels_Asian_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                  else
                    {
                     if((GMT_At_Ao==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                       {
                        OpenPrior(i,vLabels_Asian_Open,Lines_Color,Lines_Style_01234,
                                  Lines_Width_12345,level);
                       }
                    }
                 }
              }

            //Berlin Open vLine
            if(Show_Frankfurt_Open)
              {
               if(GMT_At_Fo+Broker_GMT_Offset<0) {GMT_At_Fo=GMT_At_Fo+24;}
               MF=MathFloor(GMT_At_Fo);
               if((Period()>30) && (h==MF+Broker_GMT_Offset) && (m==0))
                 {
                  OpenPrior(i,vLabels_Berlin_Open,Lines_Color,Lines_Style_01234,
                            Lines_Width_12345,level);
                 }
               else
                 {
                  if((GMT_At_Fo!=MF) && (h==MF+Broker_GMT_Offset) && (m==30))
                    {
                     OpenPrior(i,vLabels_Berlin_Open,Lines_Color,Lines_Style_01234,
                               Lines_Width_12345,level);
                    }
                  else
                    {
                     if((GMT_At_Fo==MF) && (h==MF+Broker_GMT_Offset) && (m==0))
                       {
                        OpenPrior(i,vLabels_Berlin_Open,Lines_Color,Lines_Style_01234,
                                  Lines_Width_12345,level);
                       }
                    }
                 }
              }

           }//End prior sessions shift loop                            
        }//End prior sessions routine                        
     }//End vLines routine

//End of program computations---------------------------------------------------------------        
   return(0);
  }

//+-------------------------------------------------------------------------------------------+
//| Subroutine to Create Market Open Lines And Labels For Current Session                     |          
//+-------------------------------------------------------------------------------------------+   
void OpenToday(string text,int time1,color Clr,int style,int thickness,double Level)
  {
   a = style;
   b = thickness;
   c =1; if(a==0)c=b;

   vline  = "[C2P2 Draw]  " + StringTrimLeft(text) + " Current Session Line";
   vlabel = "[C2P2 Draw]  " + StringTrimLeft(text) + " Current Session Label";
   time2=time1;
   if(time2<0) {time2=time2+24;}
   time3=MathFloor(time2);
   dt=TimeYear(iTime(NULL,0,0))+"."+TimeMonth(iTime(NULL,0,0))+"."+
      TimeDay(iTime(NULL,PERIOD_D1,0))+"."+time3+":"+"0";
   time4=StrToTime(dt);
   if(time2!=time3) {time4=time4+1800;}  //add half hour  

                                         //Draw vLines                          
   if(!Lines_sub_windows) {ObjectCreate(vline,OBJ_TREND,0,time4,0,time4,100);}
   else {ObjectCreate(vline,OBJ_VLINE,0,time4,0);}
   ObjectSet(vline,OBJPROP_STYLE,a);
   ObjectSet(vline,OBJPROP_WIDTH,c);
   ObjectSet(vline,OBJPROP_COLOR,Clr);
   ObjectSet(vline,OBJPROP_BACK,true);

//Draw labels   
   if(Session_Labels_On)
     {
      ObjectCreate(vlabel,OBJ_TEXT,0,time4,Level);
      ObjectSetText(vlabel,text,Labels_FontSize,Labels_Font,Labels_Color);
      ObjectSet(vlabel,OBJPROP_BACK,true);
     }
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine to Create Market Open Lines And Labels For Prior Sessions                      |          
//+-------------------------------------------------------------------------------------------+   
void OpenPrior(int mi,string text,color Clr,int style,int thickness,double Level)
  {
   a = style;
   b = thickness;
   c =1; if(a==0)c=b;

   vline  = "[C2P2 Draw]  " + StringTrimLeft(text) + " Prior Session Line " + (mi-1);
   vlabel = "[C2P2 Draw]  " + StringTrimLeft(text) + " Prior Session Label " + (mi-1);

//Draw vLine                 
   if(!Lines_sub_windows) {ObjectCreate(vline,OBJ_TREND,0,Time[mi],0,Time[mi],100);}
   else {ObjectCreate(vline,OBJ_VLINE,0,Time[mi],0);}
   ObjectSet(vline,OBJPROP_STYLE,a);
   ObjectSet(vline,OBJPROP_WIDTH,c);
   ObjectSet(vline,OBJPROP_COLOR,Clr);
   ObjectSet(vline,OBJPROP_BACK,true);

//Draw labels  
   if(Session_Labels_On)
     {
      ObjectCreate(vlabel,OBJ_TEXT,0,Time[mi],Level);
      ObjectSetText(vlabel,text,Labels_FontSize,Labels_Font,Labels_Color);
      ObjectSet(vlabel,OBJPROP_BACK,true);
     }
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine to convert time to a string for time labels                                    |
//+-------------------------------------------------------------------------------------------+
string TimeToStrings(datetime when)
  {
   hour=TimeHour(when);
   if(!Show_AMPM_Time)
     {
      timeStr=(TimeToStr(when,TIME_MINUTES));
     }

// User wants 12HourTime format with "AM" or "PM".   
// FYI, if >12:00, subtract 12 hours in seconds which is 12*60*60=43200
   else
     {
      if(hour>12 || hour==0) timeStr=TimeToStr((when-43200),TIME_MINUTES);
      else timeStr=TimeToStr(when,TIME_MINUTES);
      if(hour>=12) timeStr=StringConcatenate(timeStr," PM");
      else timeStr=StringConcatenate(timeStr," AM");
     }
   return (timeStr);
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine to retrieve date and time from time array                                      |
//+-------------------------------------------------------------------------------------------+
datetime TimeArrayToTime(int &lLocalTimeArray[])
  {
   nYear=lLocalTimeArray[0]&0x0000FFFF;
   nMonth=lLocalTimeArray[0]>>16;
   nDay=lLocalTimeArray[1]>>16;
   nHour=lLocalTimeArray[2]&0x0000FFFF;
   nMin=lLocalTimeArray[2]>>16;
   nSec=lLocalTimeArray[3]&0x0000FFFF;
   nMilliSec=lLocalTimeArray[3]>>16;
   LocalTimeS = FormatDateTime(nYear,nMonth,nDay,nHour,nMin,nSec);
   Local_Time = StrToTime( LocalTimeS );
   return(Local_Time);
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine to format time labels                                                          |
//+-------------------------------------------------------------------------------------------+
string FormatDateTime(int lnYear,int lnMonth,int lnDay,int lnHour,int lnMin,int lnSec)
  {
   sMonth=100+lnMonth;
   sMonth=StringSubstr(sMonth,1);
   sDay=100+lnDay;
   sDay=StringSubstr(sDay,1);
   sHour=100+lnHour;
   sHour=StringSubstr(sHour,1);
   sMin=100+lnMin;
   sMin=StringSubstr(sMin,1);
   sSec=100+lnSec;
   sSec=StringSubstr(sSec,1);
   return(StringConcatenate(lnYear,".",sMonth,".",sDay," ",sHour,":",sMin,":",sSec));
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine to get time zone information for each city                                     |
//+-------------------------------------------------------------------------------------------+
void Get04TimeZoneInfo(int &lSydneyTZInfoArray[],int &lBerlinTZInfoArray[],
                       int &lLondonTZInfoArray[],int &lNewYorkTZInfoArray[])

  {
   lSydneyTZInfoArray[0]  = -600;
   lSydneyTZInfoArray[17] = 262144; //4<<16 == 262144  April
   lSydneyTZInfoArray[18] = 65536;  //1<<16 == 65536   1st Sunday
   lSydneyTZInfoArray[19] = 3;
   lSydneyTZInfoArray[20] = 0;
   lSydneyTZInfoArray[21] = 0;
   lSydneyTZInfoArray[38] = 655360; //10<<16 == 655360  October
   lSydneyTZInfoArray[39] = 65536;  //1<<16 == 65536    1st Sunday
   lSydneyTZInfoArray[40] = 2;
   lSydneyTZInfoArray[41] = 0;
   lSydneyTZInfoArray[42] = -60;

   lLondonTZInfoArray[0]  = 0;
   lLondonTZInfoArray[17] = 655360; //10<<16 == 655360  October
   lLondonTZInfoArray[18] = 327680; //5<<16 == 327680.  5th/Last Sunday. 
   lLondonTZInfoArray[19] = 2;
   lLondonTZInfoArray[20] = 0;
   lLondonTZInfoArray[21] = 0;
   lLondonTZInfoArray[38] = 196608; //3<<16 == 196608  March
   lLondonTZInfoArray[39] = 327680; //5<<16 == 327680  5th/Last Sunday
   lLondonTZInfoArray[40] = 1;
   lLondonTZInfoArray[41] = 0;
   lLondonTZInfoArray[42] = -60;

// FYI, Berlin = Belgrade, Brussels, Paris, Sarajevo
   ArrayCopy(lBerlinTZInfoArray,lLondonTZInfoArray);
   lBerlinTZInfoArray[0]=-60;

   lNewYorkTZInfoArray[0]  = 300;
   lNewYorkTZInfoArray[17] = 720896; //wYear = 0. wMonth = 11, and 11<<16 == 720896
   lNewYorkTZInfoArray[18] = 65536;  //wDOW = 0 = Sunday. nDay = 1 and 1<<16 == 65536 
   lNewYorkTZInfoArray[19] = 2;
   lNewYorkTZInfoArray[20] = 0;
   lNewYorkTZInfoArray[21] = 0;
   lNewYorkTZInfoArray[38] = 196608; //3<<16 == 196608  March
   lNewYorkTZInfoArray[39] = 131072; //2<<16 == 131072  2nd Sunday
   lNewYorkTZInfoArray[40] = 2;
   lNewYorkTZInfoArray[41] = 0;
   lNewYorkTZInfoArray[42] = -60;
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine to get time zone information for each city                                     |
//+-------------------------------------------------------------------------------------------+
void Get14TimeZoneInfo(int &lAucklandTZInfoArray[],int &lTokyoTZInfoArray[],
                       int &lChinaTZInfoArray[],int &lJakartaTZInfoArray[],int &lIndiaTZInfoArray[],
                       int &lDubaiTZInfoArray[],int &lMoscowTZInfoArray[],int &lIsraelTZInfoArray[],
                       int &lHelsinkiTZInfoArray[],int &lBrazilTZInfoArray[],int &lCentralTZInfoArray[],
                       int &lMexicoTZInfoArray[],int &lMountainTZInfoArray[],int &lPacificTZInfoArray[])

  {
   lAucklandTZInfoArray[0]  = -720;
   lAucklandTZInfoArray[17] = 262144; //4<<16 == 262144  April
   lAucklandTZInfoArray[18] = 65536;  //1<<16 == 65536   l1st Sunday
   lAucklandTZInfoArray[19] = 3;
   lAucklandTZInfoArray[20] = 0;
   lAucklandTZInfoArray[21] = 0;
   lAucklandTZInfoArray[38] = 589824; //9<<16 == 589824  September
   lAucklandTZInfoArray[39] = 327680; //5<<16 == 327680  5th/Last Sunday
   lAucklandTZInfoArray[40] = 2;
   lAucklandTZInfoArray[41] = 0;
   lAucklandTZInfoArray[42] = -60;

// FYI Tokyo = Seoul
   lTokyoTZInfoArray[0]  = -540;
   lTokyoTZInfoArray[17] = 0;
   lTokyoTZInfoArray[18] = 0;
   lTokyoTZInfoArray[19] = 0;
   lTokyoTZInfoArray[20] = 0;
   lTokyoTZInfoArray[21] = 0;
   lTokyoTZInfoArray[38] = 0;
   lTokyoTZInfoArray[39] = 0;
   lTokyoTZInfoArray[40] = 0;
   lTokyoTZInfoArray[41] = 0;
   lTokyoTZInfoArray[42] = 0;

// FYI, Beijing = Perth, Singapore, Taipei, Hong Kong
   ArrayCopy(lChinaTZInfoArray,lTokyoTZInfoArray);
   lChinaTZInfoArray[0]=-480;

// FYI, Jakarta = Bangkok
   ArrayCopy(lJakartaTZInfoArray,lTokyoTZInfoArray);
   lJakartaTZInfoArray[0]=-420;

   ArrayCopy(lIndiaTZInfoArray,lTokyoTZInfoArray);
   lIndiaTZInfoArray[0]=-330;  // NOTE! Top of the hour is 30 min off most world timezones.

   ArrayCopy(lDubaiTZInfoArray,lTokyoTZInfoArray);
   lDubaiTZInfoArray[0]=-240;

   lIsraelTZInfoArray[0]  = -120;
   lIsraelTZInfoArray[17] = 589824;  //9<<16 == 589824  September
   lIsraelTZInfoArray[18] = 131072;  //2<<16  = 131072
   lIsraelTZInfoArray[19] = 2;
   lIsraelTZInfoArray[20] = 0;
   lIsraelTZInfoArray[21] = 0;
   lIsraelTZInfoArray[38] = 196608; //3<<16 == 196608  March
   lIsraelTZInfoArray[39] = 327685; //5<<16  = 327680 AND "5" (*IF* Sunday is "0", is "5" Friday??)
   lIsraelTZInfoArray[40] = 2;
   lIsraelTZInfoArray[41] = 0;
   lIsraelTZInfoArray[42] = -60;

   ArrayCopy(lMoscowTZInfoArray,LondonTZInfoArray);
   lMoscowTZInfoArray[0]  = -180;
   lMoscowTZInfoArray[19] = 3;
   lMoscowTZInfoArray[40] = 2;

// FYI, Helsinki = Athens
   ArrayCopy(lHelsinkiTZInfoArray,LondonTZInfoArray);
   lHelsinkiTZInfoArray[0]  = -120;
   lHelsinkiTZInfoArray[19] = 4;
   lHelsinkiTZInfoArray[40] = 3;

// FYI, Berlin = Belgrade, Brussels, Paris, Sarajevo
//ArrayCopy(lBerlinTZInfoArray, lMoscowTZInfoArray);
//lBerlinTZInfoArray[0] = -60;

// NOTE! Brazil's ST/DST is likely a hardcoded date which will need updating EVERY YEAR!
   lBrazilTZInfoArray[0]  = 180;
   lBrazilTZInfoArray[17] = 131072;   //2<<16  = 131072
   lBrazilTZInfoArray[18] = 196614;   //3<<16 == 196608 AND 6, so, Saturday?? or Mar 6?
   lBrazilTZInfoArray[19] = 3866647;
   lBrazilTZInfoArray[20] = 65470523;
   lBrazilTZInfoArray[21] = 0;
   lBrazilTZInfoArray[38]=655360;   //10<<16 == 655360
   lBrazilTZInfoArray[39] = 196614;
   lBrazilTZInfoArray[40] = 3866647;
   lBrazilTZInfoArray[41] = 65470523;
   lBrazilTZInfoArray[42] = -60;

//ArrayCopy(BuenasAriesTZInfoArray, BuenasAriesTZInfoArray);
//BuenasAriesTZInfoArray[0] = 180;

   ArrayCopy(lCentralTZInfoArray,NewYorkTZInfoArray);
   lCentralTZInfoArray[0]=360;

   lMexicoTZInfoArray[0]  = 360;
   lMexicoTZInfoArray[17] = 655360; //10<<16 == 655360  October
   lMexicoTZInfoArray[18] = 327680; //5<<16 == 327680  5th/Last Sunday
   lMexicoTZInfoArray[19] = 2;
   lMexicoTZInfoArray[20] = 0;
   lMexicoTZInfoArray[21] = 0;
   lMexicoTZInfoArray[38] = 262144; //4<<16 == 262144  April
   lMexicoTZInfoArray[39] = 65536;  //1<<16 == 65536   l1st Sunday
   lMexicoTZInfoArray[40] = 2;
   lMexicoTZInfoArray[41] = 0;
   lMexicoTZInfoArray[42] = -60;

   ArrayCopy(lMountainTZInfoArray,NewYorkTZInfoArray);
   MountainTZInfoArray[0]=420;

   ArrayCopy(lPacificTZInfoArray,NewYorkTZInfoArray);
   lPacificTZInfoArray[0]=480;
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine:  Set up to get the chart scale number                                         |
//+-------------------------------------------------------------------------------------------+
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam)
  {
   Chart_Scale=ChartScaleGet();
   init();
  }
//+-------------------------------------------------------------------------------------------+
//| Subroutine:  Get the chart scale number                                                   |
//+-------------------------------------------------------------------------------------------+
int ChartScaleGet()
  {
   long result=-1;
   ChartGetInteger(0,CHART_SCALE,0,result);
   return((int)result);
  }

//+-------------------------------------------------------------------------------------------+
//| Indicator End                                                                             |                                                        
//+-------------------------------------------------------------------------------------------+      

//+-------------------------------------------------------------------------------------------+
//| Indicator End                                                                             |                                                        
//+-------------------------------------------------------------------------------------------+      


//Global External Inputs-----------------------------------------------------------------------
bool   Indicator_On                          = true;
string Preface____________                   = "Get Broker_GMT_Offset w/Clock & live feed.";
int    Broker_GMT_Offset                     = 0;
bool   Apply_it_now_because_feed_is_not_live = false;
string End_Preface________                   = "";
string _                               = "";
string Part_1                          = "Indicator Master Controls:";
bool   Show_Clock_in_Panel             = false;
bool   Bid_Line_On                     = false;
bool   Levels_On                       = false;

bool   Pivots_PVT_On                   = false;
int    __PVT_Max_TF                    = 60;
bool   Pivots_SR_On                    = false;
int    __Show_Levels_Thru_2345         = 5;
bool   __Show_MidPivots                = false;
int    __SR_Max_TF                     = 60;
bool   Pivots_Fibonacci                = false;
bool   PivotsTz_On                     = false;
bool   __Use_Preferred_Offset          = false;
int    __Alternative_GMT_Offset        = 0;
bool   Range_Day_On                    = false;
int    __Day_Min_TF                    = 1;
int    __Day_Max_TF                    = 240;
bool   Range_Week_On                   = false;
int    __Week_Min_TF                   = 15;
int    __Week_Max_TF                   = 240;
bool   Separators_On                   = false;
int    __Prior_Days_To_Show            = 5;
int    __Separators_Max_TF             = 60;

string __                              = "";
string Part_2                          = "Panel Settings:";
bool   Show_Chart_ID_and_TF            = true;
bool   Show_Forex_Fractional_Pip       = true;
int    __Shift_Fractional_Pip          = 0;
int    Digits_To_Show_In_Spread        = 2;
int    Days_In_Range_Day_Avg           = 15;
int    Weeks_In_Week_ATR               = 13;
bool   Show_Swaps_vs_Candle_Time       = true;
color  Panel_Background_Color          = C'025,025,025';
color  Symbol_And_TF_Color             = C'208,208,208';
color  Spread_Color                    = C'120,120,120';
color  PipVal_Color                    = C'120,120,120';
color  Range_Color                     = C'120,120,120';
color  Swaps_Time_Color                = C'120,120,120';
color  Bid_UP_Color                    = C'046,188,046';
color  Bid_DN_Color                    = C'234,000,000';
color  Bid_Last_Digit_Normal           = C'100,100,100';
color  Bid_Last_Digit_Small            = C'160,160,160';
color  sonicS                          = C'004,162,255';
color  sonicO                          = C'000,115,183';
color  sonicN                          = C'000,075,121';
color  sonicI                          = C'138,000,000';
color  sonicC                          = C'176,000,000';
color  sonicR                          = C'221,000,000';
color  smiley1                         = C'255,255,100';
color  smiley2                         = White;
color  Smiley_Back_with_Clock          = C'025,025,025';
color  Smiley_Back_without_Clock       = C'025,025,025';
color  ID_TF_Background_for_Smiley     = C'025,025,025';

string ___                             = "";
string Part_3                          = "Bid Line Settings:";
color  Bid_Ray_Color                   = C'100,100,100';
int    Bid_Ray_LineStyle_01234         = 0;
int    Bid_Ray_Thickness               = 1;
color  Bid_Dot_Up_Color                = Lime;
color  Bid_Dot_Dn_Color                = Red;
int    Bid_Dot_Size                    = 6;

string ____                            = "";
string Part_4                          = "Horizontal Lines Position Settings:";
string note_4_0                        = "Choose line display number.";
string note_4_1                        = "1 = Fullscreen";
string note_4_2                        = "2 = Session";
int    Levels_Display_Number           = 1;
int    Pivots_Display_Number           = 2;
int    Ranges_Display_Number           = 2;
bool   Subordinate_Lines               = true;

string _____                           = "";
string Part_5                          = "Horizontal Lines Labels Settings:";
bool   Pivot_PVT_Label_On              = true;
bool   Pivot_SRM_Labels_On             = true;
bool   Range_Labels_On                 = true;
string FontStyle                       = "Verdana";
int    FontSize                        = 7;
bool   Subordinate_Labels              = true;


string _______                         = "";
string Part_7                          = "Pivots Settings:";
color  PVT1_Back_Color                 = CLR_NONE;
int    PVT1_Style_01234                = 0;
int    PVT1_Width_12345                = 3;
color  PVT2_Top_Color                  = C'230,216,000';
int    PVT2_Style_01234                = 0;
int    PVT2_Width_12345                = 1;
color  R_Pivot_Color                   = C'179,000,000';
int    R_Style_01234                   = 2;
int    R_Width_12345                   = 1;
color  S_Pivot_Color                   = C'090,075,173';
int    S_Style_01234                   = 2;
int    S_Width_12345                   = 1;
color  MidPivots_Color                 = C'085,085,000';
int    mP_Style_01234                  = 2;
int    mP_Width_12345                  = 1;

string ________                        = "";
string Part_8                          = "Range Day Settings:";
color  RDH_Color                       = Red;
color  RDL_Color                       = C'000,115,230';
int    RD_Style_01234                  = 0;
int    RD_Width_12345                  = 1;

string _________                       = "";
string Part_9                          = "Range Week Settings:";
color  RWH_Color                       = Red;
color  RWL_Color                       = C'000,115,230';
int    RW_Style_01234                  = 0;
int    RW_Width_12345                  = 2;

string __________                      = "";
string Part_10                         = "Separators Settings:";
color  Separators_Color                = C'085,085,085';
int    Separators_Style_01234          = 2;
int    Separators_Width_12345          = 1;
bool   Separators_Thru_SubWindows      = true;







  string ______                          = "";
  string Part_6                          = "Levels Settings:";
  bool   __Show_Half_Lines               = false;
 bool   __Show_Quarter_Lines            = false;
 int    __Levels_Whole_Max_TF           = 10080;
 int    __Levels_Half_Max_TF            = 1440;
 int    __Levels_Quarter_Max_TF         = 240;
 color  Level_Whole_Color               = C'041,033,073';
 int    Level_Whole_Style_01234         = 0;
 int    Level_Whole_Width_12345         = 1;
 color  Level_Half_Color                = C'000,053,000';
 int    Level_Half_Style_01234          = 0;
 int    Level_Half_Width_12345          = 1;
 color  Level_Quarter_Color             = C'043,033,019';
 int    Level_Quarter_Style_01234       = 0;
 int    Level_Quarter_Width_12345       = 1;

string ____________                    = "";
string Part_12                         = "Clock Settings:";
color  Clock_MktClosed                 = C'120,120,120';
color  Location_MktClosed              = C'120,120,120';
color  Clock_MktOpen                   = C'174,111,047';
color  Location_MktOpen                = C'036,157,036';
bool   Show_AMPM_Time                  = false;
string Note_12_1                       = "Choosing Locations to Display:";
string Note_12_2                       = "Select 7 maximum from list,";
string Note_12_3                       = "0 = display off.";
string Note_12_4                       = "1 = Display on.";
int    Broker                          = 0;
int    Local=0; //Your computer's time.
int    Auckland                        = 0;
int    Sydney                          = 1;
int    Tokyo                           = 1;
int    HongKong                        = 1;
int    Jakarta                         = 0;
int    India                           = 0;
int    Dubai                           = 0;
int    Moscow                          = 0;
int    Israel                          = 0;
int    Helsinki                        = 1;
int    Frankfurt                       = 1;
int      London=1; //DST London=GMT+1, NonDST London=GMT
int    GMT=0; //No change btwn DST/summer & NonDST/winter
int    Brazil                          = 0;
int    NewYork                         = 1;
int    Central                         = 0;
int    Mexico                          = 0;
int    Mountain                        = 0;
int    Pacific                         = 0;

//Buffers, Constants and Variables-------------------------------------------------------------
bool          Deinitialized;

//Deinit
int           obj_total,k;
string        name;

//Panel
color         Static_Price_Color,Static_Bid_Color,Bid_Dot_Color,Static_Bid_Dot_Color;
double        Poin,Poin2,New_Price,Old_Price,level,Spread,ARg,RangeAchieved,dRG,dRange,wRange;
double        pipValue;
int           Chart_Scale,modifier,Color,Factor,G,h,i,l,m,s,t,LP,LS,T1,T2;
string        item01 = "z[C2P2 Panel] Box 1";
string        item02 = "y[C2P2 Panel] Box 2";
string        item03 = "z[C2P2 Text] ID&TF";
string        item04 = "z[C2P2 Text] Spread";
string        item05 = "z[C2P2 Text] Spread2";
string        item06 = "z[C2P2 Text] Pip";
string        item07 = "z[C2P2 Text] Pip2";
string        item08 = "z[C2P2 Text] Range";
string        item09 = "z[C2P2 Text] Range2";
string        item10 = "z[C2P2 Text] Swap";
string        item11 = "z[C2P2 Text] Swap2";
string        item12 = "z[C2P2 Text] Price1";
string        item13 = "z[C2P2 Text] Price2";
string        item14 = "z[C2P2 Text] Logo1 S";
string        item15 = "z[C2P2 Text] Logo1 o";
string        item16 = "z[C2P2 Text] Logo1 n";
string        item17 = "z[C2P2 Text] Logo1 i";
string        item18 = "z[C2P2 Text] Logo1 c";
string        item19 = "z[C2P2 Text] Logo1 R";
string        item20 = "d[C2P2 Bid] Bid Line";
string        item21 = "e[C2P2 Bid] Bid Dot";
string        item22 = "z[C2P2 Text] Smiley1";
string        item23 = "z[C2P2 Text] Smiley2";
string        ID,Price,C,tab,tab1,timeleft;

//Levels
color         linecolor;
double        linelevel,linestyle,linewidth,BL;
int           j,Line1_Color,Line2_Color,Line3_Color;
int           u1=00,u2=50,u3=25,u4=75;
int           v1,ssp,ssp1,NumberOfRanges;
string        linename;

//Pivots
datetime      pvtDT;
double        p,d,q,r1,r2,r3,r4,r5,s1,s2,s3,s4,s5;
double        today_high,today_low,yesterday_high,yesterday_open,
yesterday_low,yesterday_close;
int           Pdisplay,idxfirstbaryesterday,idxlastbaryesterday,idxfirstbartoday,idxbar,
tzdiff,tzdiffsec,barsperday,dayofweektoday,dayofweektofind,Pivots_GMT_Offset;
string        prefix;

//Range Day
datetime      d1,d2;
double        dRangeHigh,dRangeLow,HiToday,LoToday,dRH,dRL;
int           ii,iii,x,xx,r,dtf,Hbarshift,Lbarshift,rdc,rwc,Rdisplay,RDshift;

//Range Week
datetime      w1,w2;
double        HiWeek,LoWeek;
double        wRangeAvg,wRangeHigh,wRangeLow,wRH,wRL;
int           wtf,wHbarshift,wLbarshift,RWdisplay,RWshift;

//Horizontal Lines Placement
datetime      startline,stopline;
int           a,b,c,R2,T,T4;
string        line,dt;

//Horizontal Labels Placement
datetime      startlabel;
string        label,spc;

//vLines & Labels
bool          vLabels_Chart_Top=true;
datetime      shift,T3;
double        top,bottom,scale,YadjustTop,YadjustBot,vLabels_Dist_Above_Border,time2,time4;
int           bps,MF,time3;
int           vLabels_Dist_To_Border=1;
string        vline,vlabel;
string        vLabels_Asian_Open       = "      Ao ";
string        vLabels_Berlin_Open      = "     Fo  ";
string        vLabels_London_Open      = "      Lo";
string        vLabels_NewYork_Open     = "     Ny";
string        vLabels_London_Close     = "      Lc ";
string        Label_Day_Separator      = "day";

//Get GMT Offsets in Support of PivotsTz and Market vLines                    
int           GMT_Ref_Time,Sydney_GMT_Offset,Berlin_GMT_Offset,London_GMT_Offset,
NYC_GMT_Offset,GMT_At_Lo,GMT_At_NYo,GMT_At_Lc,GMT_At_Ao,GMT_At_Fo;

//Import Time Zone Data in Support of Clock, PivotsTz and Market vLines
bool          BKR_UTC_Match,FLAG_static_broker,Displaying_Pivots;
datetime      Local_Time,BrokerDT,AucklandDT,SydneyDT,TokyoDT,ChinaDT,JakartaDT,IndiaDT,
DubaiDT,MoscowDT,IsraelDT,HelsinkiDT,BerlinDT,LondonDT,UTC,BrazilDT,NewYorkDT,
CentralDT,MexicoDT,MountainDT,PacificDT,StaticBrokerDT;
int           ClockFontSize,TimezoneFontSize,LineSpacing,z,time,place,offset;
int           AucklandTZInfoArray[43],SydneyTZInfoArray[43],TokyoTZInfoArray[43],
ChinaTZInfoArray[43],JakartaTZInfoArray[43],IndiaTZInfoArray[43],
DubaiTZInfoArray[43],MoscowTZInfoArray[43],IsraelTZInfoArray[43],
HelsinkiTZInfoArray[43],BerlinTZInfoArray[43],LondonTZInfoArray[43],
BrazilTZInfoArray[43],NewYorkTZInfoArray[43],CentralTZInfoArray[43],
MexicoTZInfoArray[43],MountainTZInfoArray[43],PacificTZInfoArray[43],
LocalTZInfoArray[43];
int           LocalTimeArray[4],systemTimeArray[4],AucklandTimeArray[4],SydneyTimeArray[4],
TokyoTimeArray[4],ChinaTimeArray[4],JakartaTimeArray[4],IndiaTimeArray[4],
DubaiTimeArray[4],MoscowTimeArray[4],IsraelTimeArray[4],HelsinkiTimeArray[4],
BerlinTimeArray[4],LondonTimeArray[4],BrazilTimeArray[4],NewYorkTimeArray[4],
CentralTimeArray[4],MexicoTimeArray[4],MountainTimeArray[4],PacificTimeArray[4];
string        Locals,Brokers,Aucklands,Sydneys,Tokyos,Chinas,Jakartas,Indias,Dubais,
Moscows,Israels,Helsinkis,Berlins,Londons,UTCs,Brazils,NewYorks,Centrals,
Mexicos,Mountains,Pacifics;
string        Brokerp,Localp,Aucklandp,Sydneyp,Tokyop,Chinap,Jakartap,
Indiap,Dubaip,Moscowp,Israelp,Helsinkip,Berlinp,Londonp,UTCp,
Brazilp,NYp,Centralp,Mexicop,Mountainp,Pacificp,FontName;
string        timeStr,LocalTimeS,sMonth,sDay,sHour,sMin,sSec;
int           hour,nYear,nMonth,nDay,nHour,nMin,nSec,nMilliSec;

//Clock - Normal hrs 8-17 (9 hrs), Sydney 9-18 (9 hrs) and Tokyo 9-18 (9 hrs)   
int           LocalOpenHour        =  8;
int           LocalCloseHour       = 17;
int           SydneyLocalOpenHour  =  9;
int           SydneyLocalCloseHour = 18;
int           TokyoLocalOpenHour   =  9;
int           TokyoLocalCloseHour  = 18;