TzPivotsD_v3.5 (Black)

Author: CaveMan, Domas4 and Traderathome, Copyright @ 2009
Price Data Components
Series array that contains open time of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains open prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1
0 Views
0 Downloads
0 Favorites
TzPivotsD_v3.5 (Black)

//+-------------------------------------------------------------------------------------------+
//|                                                                                           |
//|                                    TzPivotsD.mq4                                          |
//|                                                                                           |
//+-------------------------------------------------------------------------------------------+

#property copyright "CaveMan, Domas4 and Traderathome, Copyright @ 2009"
#property link      "email: traderathome@msn.com"

/*=============================================================================================
TzPivotsD_v3.5:
In Forex mode, you can now select to display either the 4 digit or 5 digit format.  If your
platform is 4 digit and you select the 5 digit display, a "0" is added to displayed numbers.
If your platform is 5 digit and you select to not display 5 digits, numbers are rounded off
to 4 digits.  You now have the option to not display the pivot line label(s) for each  
catagory of pivot lines.  Not showing certain labels can make for a cleaner chart appearance.
Five new features have been added to the Data Panel.  New coding allows the user to input 
whether or not the MT4 OHLC display (upper left corner of chart) is being used (checked in  
Chart Properties).  If it is not being used (unchecked in Chart Properties), then input "false" 
in Data Panel settings.  The Data Panel will adjust position upwards and automatically display
the currency pair ID and TF.  New code will shift negative numbers in the Data Panel one space 
to the left, keeping the numbers column better aligned.  If your platform is 5 digit and you 
have identified it as such in the Data Panel settings, range and spread information will appear 
normal/same as on a 4 digit platform.  But you have by additional input, your separate choice 
of digits for the display of the spread.  And you have the option of displaying the time to
the next candle. Finally, even if this pivots indicator is set to not display pivots on higher
TF charts, if the Data Panel is selected, it will now remain on those charts.  Also in this
revision, the unused Scroller feature is removed.  The Relabeler Adjustment is changed to 
hard code and it's comment panel is removed.  The External Inputs Window is re-arranged.

TzPivotsD_v3.4:
Additional refinements by Caveman to the TzShift code.  Relabeler code/Test Comments revised.  
The yHL lines code revised to use the Today_yHL line configuration for full screen lines.  
Corrected alignment errors for some pivot labels.

TzPivotD_v3:
This is a Benchmark advancement of the indicator, made possible by "Caveman", who generously
devoted his time and programming skills to extensively recode the time zone shift section,  
and to add DST code which automates the turning On/Off of DST.  With the new time zone shift
code it is anticipated the indicator can handle any situation where there are gaps between 
trading days, where there are partial trading days, or both.  And with the new DST code there 
is no need to adjust your time zone shift settings twice a year.  Also, it provides for 
customizing your own DST setting in case you/your broker are in a time zone not covered by the
DST code as it is.  Other changes and improvements are as follows.  The external inputs window 
is reworked for greater clarity and consistency of terminology.  The yHL option StartLine =2 
can be used even though all other pivots are using StartLine =3.  The yHL labels can be aligned 
with the rest of the pivot labels on the right side of the Today Separator.  From that setting 
they can be shifted to the left side of the Today Separator.  Label placement for full screen
lines is now expressed as "0" to "100" percent of the distance from right to left, requiring 
only the number be entered.  Data Comments now include user input of the number of days to be 
used incomputing the average range.  New code from Domas4 lets you enter a time frame, above 
which the indicator will automatically not display.  With this feature, the bid line Price 
Label is removed and a separate indicator is provided to display price and time remaining on 
the candle.  It is called the Bid Line Price & Timer Indicator.  Using a separate indicator for 
price and time keeps that information visible when TzPivotsD is set to not display.  MaxRight 
settings are removed.  When lines are full screeen, and if the option has been selected to show 
the right margin price labels, you can also "Preeminate_MarginLabels_Lines".  This will bring 
both the lines and the margin price labels to the foreground.  This does not affect the pivot 
line labels subordination setting.  Separator label coding is modified to place labels a little 
closer to upper/lower chart borders; helpful when using larger fonts.  

TzPivotsD_v2:
Many "THANKS!" are owed to Domas4 for coding the price labels to be compatible with non-forex 
items.  Set that input choice to "false" for non-forex items such as Gold and Stocks, etc. 
Additional coding of the Scroll Compensator was made in hopes of improving performance.  Now
the user can leave the Scroll_Left_Adjustment at "0" and code will try to assign best value 
based upon the number of bars per chart.  This changes with the chart "zoom" the user has 
selected, and with different size monitors!  It is a tough thing to try to automate.  If there 
are any problems, leave the Scroll Compensator off unless you are using it.  When on, you can 
input a value to override hardcoded values.  An input of "1" should be best, so long as the 
function is turned off when not being used, because a value of "1" will immediately force 
lines to become full screen lines. A value of "0" allows the hard coded values to be operative.
The Data Comments section has been improved.

TzPivotsD:
My gratitude and profound appreciation I wish to express to Domas4 for recoding the time zone 
shift core code of Shimodax. The Shimodax code is present in all versions of the SDX_TzPivot 
indicator, which is the predecessor to TzPivotsD. TzPivotsD is the first time zone shift indy
to bring a much needed update to this core code, an update that fixes the errant pivots that 
were produced on H4 and Day charts. Domas4's work on the code also facilitated the inclusion 
of the color background boxes for the Yesterday and the Today trading sessions. Also, Domas4
corrected the Camarilla formula.

This first release of TzPivotsD comes with some improvements and additions compared to the 
SDX-TzPivots indicator.  Some highlights are:

 1) The Indicator Window's sequence of external input has been cleaned up and reorganized in 
    an attempt to simplify it.
                                                  
 2) When full screen lines are shown, label placement is affected when zooming in and out on 
    the charts.  Now, with the next data tic, proper label placement is restored.
   
 3) Upgraded coding for the Period Separator labels lets you display either a simple 
    "Yesterday" and "Today", or a more detailed display, showing the actual name of the day
    and the correct timezone shift from GMT, as selected by the user.  And now you can choose
    to display either one, or both, or neither of the Separators.    
                                           
 4) Added a third line placement choice that keeps the main pivot lines to the right of the 
    current candle for a really clean looking chart.
   
 5) Added and a third label placement choice that keeps labels to the right of the current 
    Candle.  This choice is automatic for the new third line placement, but can also be used
    as an override choice for label placement with the other line placement choices.

 6) The Camarilla line labels and the yHigh/yLow line labels now have additional separate 
    Shift control inputs.  This enables the labels to be shifted to the left of the other 
    labels when lines are so close that labels overlap.  When this shift option is used, 
    different chart zoom settings will require different shift settings.  Please note that  
    when line placement #2 is used, yL and yH labels automatically appear to right of the 
    Yesterday Separator.  When this moves off the chart, then the labels remain at the left 
    of the chart.  That is unless there is a value specified in the SHIFT.  A SHIFT value 
    other than "0" will cause these labels to appear to the left of the Today Separator, at 
    a distance from the Separator that increases with lncreasing SHIFT values.
      
 7) The formula for Camarilla lines is corrected and the core time shift code is improved,
    thanks again to Domas4 for both fixes!
      
 8) The Yesterday and the Today sessions can be boxed in colors.  These boxes are positioned 
    to coincide with any selected TZ shift of pivots.
   
 9) A large DayCandle can be displayed to the right of the current candle, on any TF chart.
    The DayCandle also has a PriceLabel and Pointer.  All can be shifted to the right.
    
10) Domas4 also expanded the code for yH/yL lines.  Now you can use one style for these lines
    thru tje "Yesterdays zone", and use another style thru the current day, the "Today zone."  
   
11) Labels can be subordinated so they lay beneath chart items.            
   
12) With past versions, if the chart was scrolled left too far, then the labels would cease 
    to appear.  Chart scroll compensation has been added.  Now, as you scroll charts left 
    beyond the point where labels will last appear, with continued scrolling the labels will 
    appear at the left margin of the chart.  Inputting a higher number will cause this 
    function to initiate later, as you scroll into past time.  Inputing a lower number will 
    cause this function to initiate sooner, as you scroll into past time.  When you scroll 
    back into the current day, normal label placement will be restored. 
     
13) The "Comments" section is revamped with new displayed information.  Also, a colored 
    background box has been added to hide chart items beneath, keeping the comments legible.  
    The background color is user selectable.  Many thanks go out to Cobra for this nice
    background box feature!
           
You can read more about time zone input settings and the other external inputs for this 
indicator in the sections following.  As with the creation of TzPivotsMW, Domas4 is greatly 
appreciated for his work here.                                                     
                                                                               - Traderathome                                                                  
----------------------------------------------------------------------------------------------- 
Introduction - Time Zone Inputs:

   "HrsServerTzFromGMT" input:    
   This is your software server's local timezone expressed in relation to GMT.  For example, 
   some MetaQuotes MT4 servers (live and demo) reside at a location 2 hours ahead of GMT, 
   hence GMT+2, and so the input here is "+2" (or just "2" for a positive relationship).  If,
   for example, your software server is in London, England which is normally GMT+0, and is 
   GMT+1 during Daylight Savings Time (DST), you would normally enter "0", but change it to 
   "1" during DST.  If your MT4 server is at GMT, then enter "0".
                     
   "HrsChoiceTzFromGMT" input:
   This is the timezone you desire to base the pivot calculations on.  It must be expressed in 
   relation to GMT.  If you desire the same timezone as your server, enter in the same # you 
   entered for the server.  If you desire London time, it would be "+1" during DST and "0" 
   otherwise.  If you desire GMT time, then enter "0".  If you desire NY time (GMT-5) then 
   enter "-5", etc.
     
   An example:
   If your software server is located in the Eastern Standard Time zone (GMT-5) and want the 
   pivot levels to be based upon the London trading session (GMT+1 during DST, otherwise GMT+0), 
   then enter "-5" for the "HrsServerTzFromGMT" timezone, and for the "HrsChoiceTzFromGMT" 
   timezone enter "1" during DST, otherwise  enter "0".
   
   Final note:
   Please understand that the "HrsServerTzFromGMT" timezone setting depends on the time 
   displayed on your MetaTrader charts.  Determine from that what Tz the server is in (hence, 
   the Tz shift from GMT Tz), no matter what the clock on your wall says.  To get normal, 
   non-time shifted pivot calculations, simply use "0" for both timezone inputs, or use the
   "HrsServerTzFromGMT" for both inputs. 
                        
-----------------------------------------------------------------------------------------------
Comments regarding some of the many Indicator Window inputs:

Indicator_On:
   Use "true" to turn indicator "ON", and "false" to turn "OFF".  This way you do not have to
   delete the indicator from the chart's list of indicators when you do not want it displayed.
   And the indicator will preserve your settings for the chart.
   
Use_For_Forex:
   For forex application, set to "true" to enable the proper digits display for the prices of
   the various forex pairs.  
   
Display_5_Digits:
   Regardless of whether your platform is 4-digit or 5-digit, you can control the digits 
   displayed with this input.      
                              
HrsServerTZFromGMT:
   Enter the number of hours difference between GMT and the time zone of your platform server.  
   Your server time is evident in the time scale below the charts.  Go to World Clock.com 
   (http://www.timeanddate.com/worldclock/) to determine the server hours difference from GMT 
   (and in which direction).  If the server is east of GMT the number entry is positive, if 
   twest of GMT the number entry is negative.
     
HrsChoiceTzfromGMT:
   Enter the number of hours difference between GMT and the timezone you want as the basis for 
   pivots calculations.  For example, if you wish to have the pivot day start at NY time, then 
   enter "-5".  If you wish to have the pivot day start at Zurich time, then enter "1".  For 
   normal, non-time shifted pivot calculations, enter the same number as in the previous input.
   
Max_Display_TF:
   On charts of a higher TF than you input, the indicator will only display the Data Panel, if
   it has been selected.
       
Use_Day_Formula:
   Enter "false" if you wish to switch to the fibonacci formula for pivots.
  
A Note on the DayCandle:
   The inputs allow you to select to show a Day candle on the chart, which you can shift to the 
   right.  The colors for the candle are in the "Colors" tab of the Indicator Window.     
   
A Note on Yesterday and Today Background Boxes:
   These inputs allow you to highlight yesterday and today with background colors.  To show 
   these background "boxes" select "true" and select a color for each.
 
StartLines:
   Using "1" will produce pivot lines across the full screen.  Using "2" will start the pivot 
   lines at the Today Separator.  On the lowest timeframe charts (M1, M5), the starting Point
   of the lines will move left across the chart, eventually making the lines full screen wide.
   Using "3" will keep the start of the lines right of the current candle. 
   
StopLines_At_Current_Candle:
   This option works with LinePlacement 1 and 2, and causes those lines to end at the current 
   candle instead of at the right margin. Fullscreen lines (LinePlacement 1) will cease to 
   have right margin price labels displayed (if that option is selected) since the lines will
   no longer be full screen wide.     
        
A Note on Pivot lines Color, Line Style and Thickness:
   Enter a color for the pivot line.  Enter the number for the desired line style (0=solid, 
   1=dash, 2=dot, 3=dashdot, 4=dashdashdot).  Enter the number (1+) for the deired thickness 
   if it is to be a solid line.
   
A Note on Yesterday High and Low lines:
   Two sets of style and thickness are provided.  This is to allow for one set to be used 
   for the lines thru the Yesterday Zone (left of Today Separator), and the other set to be 
   used for the lines thru the Today Zone (right of the Today Separator), should the user
   wish to highlight the different zones accordingly. 
   
yHL_StartLine2_With_StartLine3:
   When "3" has been selected above, to start lines at the current candle, you may want to
   keep the start of the yHL lines at the Yesterday Separator.  To do so, enter "true".     

A Note on Pivot Labels Subordination, Color, Font Style and Price:
   Subordinate labels to other chart items by entering "true", the recommended setting.
   When "false" lines appear on top of some other chart items, and if lines appear full
   screen wide with margin labels selected, then those labels will be on top of the other 
   margin scale numbers.  Enter a color for the pivot lines labels.  Enter the name of the 
   font style you want.  Arial and Verdana are good choices.  Arial Bold and Verdana Bold 
   are also good.  Enter a number for size of font desired (usually 8 - 12).  To include the
   price in the label, enter "true".
         
FScr_MarginLabels_Shown:
   "true" displays prices in the right margin, but only when lines are full screen lines.
 
FScr_LineLabels_PerCent_Left: 
   Use numbers 100 - 0 will place labels from full left to full right.  This feature is 
   enabled only for fullscreen lines, either as originally selected, or once lines over time
   have become fullscreen on the lowest timeframes (M1, M5).
      
Shift_Left_yHL_labels:
   This allows these labels to be moved to the left of other labels, according to the number
   input.  This feature helps when labels might become stacked and congested.  
   
Shift_left_CamarillaLabels:
   Same as for yH/yL labels (see above).  

A Note On The List Of "Show" Labels:
   The label for each type of line can be shown, or not.  Enter "false" to not show.
   
Align_yHL_Labels_With_Pivots:
   When using "2" for Startlines, to start lines at the Today Separator, the yHL lines and
   their labels start at the Yesterday Separator.  By inputting "true", the yHL labels will
   be aligned with the other labels to the right of the Today Separator.
   
yHL_Labels_TabLeftofSeparator:
   Once the yHL labels have been aligned with the other labels, when using "2" for StartLines
   Startlines (see above), entering a number here will tab left the yHL labels.  This is to
   ienable the yHL labels to be moved to the LEFT of the Today Separator, leaving the other
   labels to the right of the Today Separator.      

A Note on Separator Lines Color, Selection, Line Style And Thickness:
   Enter a color for the separator line.  Enter "true" to show.  Enter the number for the 
   desired line style (0=solid, 1=dash, 2=dot, 3=dashdot, 4=dashdashdot).  Enter the number
   (1+) for the deired thickness if it is to be a solid line. 
 
A Note on Separator Labels Color, Selection, Font Style, Font Size And Subordination:
   Enter a color for the separator label.  Enter "true" to show.  Enter the name of the font
   style you want.  Enter the number for the desired font size.  Enter "true" to subordinate
   Separators labels to other chart items, the recommended setting. 
   
SeparatorLabels_Detailed:
   "true" will display day name and the time zone shift (hours from GMT) that you have 
   selected for the puppose of pivot calculations.  "false" will just show the day name. 
 
SeparatorLabels_Chart_Bottom:
   "true" will place the Period Separator labels at the bottom of the screen.  "false" will
   place them at the top.  If the screen is enlarged, downsized, or scrolled, these labels
   will be displaced.  Their postion should be restored with the next data tick. 

Data_Panel_Box_Color:
   This option allows the Data Panel to appear within a background colored box.  This box will
   hide chart features beneath it so that the data remains legible.  An exception is the MT4
   candles when "Chart on foreground" is checked in Chart Properties.  To hide the candles
   beneath the background box, uncheck this item.  Pivot labels should also be subordinated
   to not interfere.  Enter the background color you want.
     
Show_Data_Panel:
   If "true" then range, spread, swap long/short and time to next bar data is displayed in
   the upper left area of the chart. 

Chart_OHLC_Is_Shown: 
   Enter "true" if the OHLC data is showing in the chart upper left.  If you do not want 
   this data, in Chart Properties uncheck "Show OHLC".  Then enter "false" and the Data Panel
   will show the pair ID and TF for you, for a cleaner chart appearance.

Platform_Is_5_Digits:
   Enter "true" if this is the case, otherwise enter "false".  Now the panel data will
   properly display.
   
Digits_To_Show_In_Spread:
   Normally the spread displays as a whole number with no digits.  If you enter a number
   higher than "0", then digits will be added to the whole number accordingly.   

Days_Used_For_Range_Data:
   Enter the number of days to be used in the "average" range calculation.

Show_Time_To_New_Candle:
   Enter "true" if you want this data displayed in the panel.
   
A Note On The TzTest_Panel:
   When the Data Panel is "off" this Displays key data in management of the TzShift code.
   This is Caveman's cave....don't mess around in there!
   
A Note On DST Settings:
   Just follow the instructions provided by Caveman in the External Inputs Window.   
                                                                                                                                                                           
=============================================================================================*/
#property indicator_chart_window
#property indicator_buffers 5   
#property indicator_color1  Green
#property indicator_color2  FireBrick
#property indicator_color3  Lime
#property indicator_color4  Red
#property indicator_color5  CLR_NONE   
#property indicator_width1  1
#property indicator_width2  1
#property indicator_width3  5
#property indicator_width4  5 
#property indicator_width5  1
/*---------------------------------------------------------------------------------------------
Color Suggestions:              White Chart         Black Chart

TodayBoxColor                   C'249,249,249'      C'25,22,27'
YesterdayBoxColor               C'244,244,244'      C'17,16,35'
CentralPivotColor               Blue                Blue
R_Color                         Tomato              FireBrick
S_Color                         LimeGreen           ForestGreen
MidPivotsColor                  Olive               C'108,108,0'    
QtrPivotsColor                  C'92,78,177'        C'92,78,177'       
TodayOpenColor                  MediumVioletRed     MediumVioletRed 
CamarillaColor                  C'43,168,165'       C'43,168,165'
YesterdayHighLowColor           C'1,149,175'        C'1,149,175'
LabelsColor                     LightSlateGray      DarkGray
PeriodSeparatorLinesColor       Olive               C'108,108,0'
PeriodSeparatorsLabelsColor     Crimson             Red
DataComment                     C'211,238,254'      C'25,25,25'
TzShift_Comment                 LavenderBlush       C'50,0,70'
---------------------------------------------------------------------------------------------*/
//---- External Inputs
extern bool   Indicator_On                    = true;
extern bool   Use_For_Forex                   = true;
extern bool   Display_5_Digits                = false;

extern string _                               = "";
extern string Part_1                          = "Time Zone Shift Settings:";
extern int    HrsServerTzFromGMT              = 2;   
extern int    HrsChoiceTzFromGMT              = 0;

extern string __                              = "";
extern string Part_2                          = "Display Settings:";
extern string TF_Choices                      = "M1, M5, M15, M30, H1, H4, D, W, M";
extern string Max_Display_TF                  = "H1";

extern string ___                             = "";
extern string Part_3                          = "Pivot Formula Settings:";
extern bool   Use_Day_Formula                 = false;

extern string ____                            = "";
extern string Part_4                          = "Day Candle and Session Box Settings:";
extern bool   Show_DayCandle                  = true;
extern int    Shift_DayCandle_Right           = 53; 
extern bool   Show_Today_Box                  = true;
extern color  Today_Box_Color                 = C'25,22,27';
extern bool   Show_Yesterday_Box              = true;
extern color  Yesterday_Box_Color             = C'17,16,35';

extern string _____                           = "";
extern string Part_5                          = "Pivot Lines Start/Stop Settings:"; 
extern string note1                           = "Start lines full screen wide, enter '1'";
extern string note2                           = "Start lines at Day Separator, enter '2'";
extern string note3                           = "Start lines at current candle, enter '3'";
extern int    StartLines                      = 2; 
extern string note4                           = "StartLines 1 & 2, can end lines at the";
extern string note5                           = "current candle instead of right margin.";
extern bool   StopLines_At_Current_Candle     = false;

extern string ______                          = "";
extern string Part_6                          = "Pivot Lines Appearance Settings:";
extern color  CentralPivot_Color              = Blue; //DodgerBlue; 
extern int    CP_LineStyle_01234              = 2;
extern int    CP_SolidLineThickness           = 2;
extern color  Resistance_Pivots_Color         = FireBrick;
extern int    R_LineStyle_01234               = 2;
extern int    R_SolidLineThickness            = 2; 
extern color  Support_Pivots_Color            = ForestGreen; 
extern int    S_LineStyle_01234               = 2;
extern int    S_SolidLineThickness            = 2; 
extern color  MidPivots_Color                 = C'108,108,0';
extern bool   Show_MidPivots                  = true;
extern int    mP_LineStyle_01234              = 2;
extern int    mP_SolidLineThickness           = 1; 
extern color  QuarterPivots_Color             = C'92,78,177';
extern bool   Show_QuarterPivots              = false;
extern int    qP_LineStyle_01234              = 2;
extern int    qP_SolidLineThickness           = 1; 
extern color  TodayOpen_Color                 = MediumVioletRed;
extern bool   Show_TodayOpen                  = false; 
extern int    TO_LineStyle_01234              = 2;
extern int    TO_SolidLineThickness           = 1; 
extern color  Camarilla_Color                 = C'43,168,165';
extern bool   Show_Camarilla                  = false;
extern int    Cm_LineStyle_01234              = 2;
extern int    Cm_SolidLineThickness           = 1; 
extern color  YesterdayHighLow_Color          = C'1,149,175';
extern bool   Show_YesterdayHighLow           = true;
extern string note6                           = "With StartLines 2 and 3, *Yesterday*";
extern string note7                           = "yHL lines can have different style";
extern string note8                           = "settings than *Today* yHL lines.";
extern int    Yest_yHL_LineStyle_01234        = 0;
extern int    Yest_yHL_SolidLineThickness     = 1; 
extern int    Today_yHL_LineStyle_01234       = 2;
extern int    Today_yHL_SolidLineThickness    = 1;
extern string note9                           = "With StartLines 3 you can still use";
extern string note10                          = "StartLine 2 for yHL lines.";
extern bool   yHL_StartLine2_With_StartLine3  = false;

extern string _______                         = "";     
extern string Part_7                          = "Pivot Label Settings:";
extern bool   PivotLabels_Subordinate         = true; 
extern color  PivotLabels_Color               = DarkGray; 
extern string PivotLabels_FontStyle           = "Verdana Bold";
extern int    PivotLabels_FontSize            = 10;
extern bool   PivotLabels_Prices              = true;
extern string note11                          = "FScr = only for lines full screen wide.";
extern bool   FScr_MarginLabels_Shown         = true;
extern int    FScr_LineLabels_PerCent_Left    = 50; 
extern int    FScr_ShiftLeft_yHL_Labels       = 0;
extern int    FScr_ShiftLeft_CamarillaLabels  = 0;
extern bool   Show_CentralPivot_Label         = true;
extern bool   Show_MainPivot_Labels           = true;
extern bool   Show_MidPivot_Labels            = false;
extern bool   Show_QuarterPivot_Labels        = false;
extern bool   Show_Open_Label                 = false;
extern bool   Show_Camarilla_Labels           = false;
extern bool   Show_yHL_Labels                 = false;

extern string ________                        = "";
extern string Part_8                          = "Special yHL Label Settings:"; 
extern string note12                          = "With StartLines 2 yHL labels can be";
extern string note13                          = "aligned with the other pivot labels.";
extern bool   Align_yHL_Labels_With_Pivots    = false;
extern string note14                          = "yHL labels can now be shifted left of";    
extern string note15                          = "separator...input tab left number."; 
extern int    yHL_Labels_TabLeftofSeparator   = 3; 

extern string _________                       = "";
extern string Part_9                          = "Day Separators Settings:";
extern color  Separator_Color                 = C'108,108,0';
extern bool   Separator_Today_Shown           = true;
extern bool   Separator_Yesterday_Shown       = true;
extern int    Separator_LineStyle_01234       = 2;
extern int    Separator_SolidLineThickness    = 1;
extern color  SeparatorLabels_Color           = Red; 
extern bool   SeparatorLabels_Shown           = true;
extern string SeparatorLabels_FontStyle       = "Verdana Bold";
extern int    SeparatorLabels_FontSize        = 8;
extern bool   SeparatorLabels_Subordinate     = false;
extern bool   SeparatorLabels_Detailed        = true;
extern bool   SeparatorLabels_Chart_Bottom    = true;


extern string __________                      = ""; 
extern string Part_10                         = "Data Panel & Tz Test Section:"; 
extern color  Data_Panel_Box_Color            = C'25,25,25';
extern bool   Show_Data_Panel                 = true;
extern bool   Chart_OHLC_Is_Shown             = true;//"false"=OHLC must beunchecked in Chart Properties
extern bool   Platform_Is_5_Digits            = false;
extern int    Digits_To_Show_In_Spread        = 0;
extern int    Days_Used_For_Range_Data        = 30;
extern bool   Show_Time_To_New_Candle         = true;
extern color  TzTest_Panel_Box_Color          = C'50,0,70';
extern bool   Show_TzTest_Panel               = true;

// Start - Added by CaveMan to cater for DST
extern string ___________                     = "";
extern string Part_11                         = "DST Zone Settings:";
extern string note16                          = "Enter preset DST zone number 1 - 4";
extern string note17                          = "or enter ' 5 ' for a custom DST zone.";
extern string note18                          = "1 US   2 EU   3 AUS   4 NZ   5 Cust.";
extern int    DST_Zone                        = 1;
extern bool   Auto_Adjust_For_DST             = true;
extern string note19                          = "To customized A DST setting -";  
extern string note20                          = "Enter # month DST starts,";
extern int    Custom_DST_Start_Month          = 3; //March
extern string note21                          = "Enter # Sunday DST starts,";
extern string note22                          = "1-1st Sunday, 2-2nd ....7-Last Sunday";
extern int    Custom_DST_Start_Sunday         = 2; //2nd Sunday of March start DST
extern string note23                          = "Enter 24 hour time DST starts,";
extern string Custom_DST_Start_Time           = "02:00"; //DST starting time
extern string note24                          = "Repeat for DST end,";
extern int    Custom_DST_End_Month            = 11; //November
extern int    Custom_DST_End_Sunday           = 1;  //1st Sunday of November end DST
extern string Custom_DST_End_Time             = "02:00"; //DST ending time
// End - Added by CaveMan to cater for DST

//---- Buffers, Constants, Variables
int    MoveLabels, A, B, digits, fxDigits, TodayBar, YesterdayBar, Relabeler_Adjustment;
double DayHigh[], DayLow[], DayOpen[], DayClose[], Old_Price;
string Yesterday, Today, Price;
 
// Start - Added by CaveMan to cater for DST
int original_server_time;
int DST_shifted_server_time;
int LastRefresh;
int First_Time;
// End - Added by CaveMan to cater for DST

// Start - Added by CaveMan to decouple yHL and Yest/Today Separators from TzShift code
double today_high, today_low, today_open, yesterday_high, yesterday_open, yesterday_low, yesterday_close;
double true_yesterday_high, true_yesterday_low;
// End - Added by CaveMan to decouple yHL and Yest/Today Separators from TzShift code

//+-------------------------------------------------------------------------------------------+
//| Program Initialization                                                                    |
//+-------------------------------------------------------------------------------------------+
int init()
   { 
// Start - Added by CaveMan to cater for DST
   original_server_time = HrsServerTzFromGMT;
   DST_shifted_server_time = HrsServerTzFromGMT + 1;
   LastRefresh = TimeHour(iTime(NULL,0,0));
   First_Time = true;
// End - Added by CaveMan to cater for DST

   if (Use_For_Forex)
      {
      string sub=StringSubstr(Symbol(), 3, 3);
      if (Display_5_Digits) {if (sub == "JPY") {fxDigits = 3;} else {fxDigits = 5;}}
      else {if (sub == "JPY") {fxDigits = 2;} else {fxDigits = 4;}}
      }
       
   SetIndexBuffer(0, DayHigh);
   SetIndexBuffer(1, DayLow);
   SetIndexBuffer(2, DayClose);
   SetIndexBuffer(3, DayOpen);
   if (Show_DayCandle) for (int i=0;i<4;i++){
      SetIndexStyle(i,DRAW_HISTOGRAM);
      SetIndexShift(i,Shift_DayCandle_Right);
      SetIndexLabel(i,"[TzPivotsD] DayCandle");}                 
   return(0);
   }
//+-------------------------------------------------------------------------------------------+
//| Program De-initialization                                                                 |
//+-------------------------------------------------------------------------------------------+
int deinit()
   {
   int obj_total= ObjectsTotal();  
   for (int k= obj_total; k>=0; k--){
      string name= ObjectName(k);           
      if (StringSubstr(name,0,11)=="[TzPivotsD]") {ObjectDelete(name);}}
   A=0; B=0; Comment(""); 
   return(0);
   }
//+-------------------------------------------------------------------------------------------+
//| Program Start                                                                             |
//+-------------------------------------------------------------------------------------------+
int start()
{
   deinit();if (Indicator_On == false) {return(0);}   
   
   //Exit if period is greater than -----------------------------------------------
   int E;if(Max_Display_TF== "M1") {E= 1;}
   else {if(Max_Display_TF== "M5") {E= 5;}
   else {if(Max_Display_TF== "M15"){E= 15;}
   else {if(Max_Display_TF== "M30"){E= 30;}
   else {if(Max_Display_TF== "H1") {E= 60;}
   else {if(Max_Display_TF== "H4") {E= 240;}
   else {if(Max_Display_TF== "D")  {E= 1440;}
   else {if(Max_Display_TF== "W")  {E= 10080;}
   else {if(Max_Display_TF== "M")  {E= 43200;}}}}}}}}}
   //if(Period() > E) {deinit(); return(-1);}        

// Start - Added by CaveMan to cater for DST
// Code will only check for DST on every new hour bar
   if(TimeHour(iTime(NULL,0,0)) == 0) LastRefresh = -1; // to cater for crossover into a new day
   if(First_Time || TimeHour(iTime(NULL,0,0)) > LastRefresh){
      if (Adjust_for_DST()){Print(" TzPivot - Daylight Savings Time (DST) is in effect.");}
      First_Time = false; LastRefresh = TimeHour(iTime(NULL,0,0));}
// End - Added by CaveMan to cater for DST

   //Tz shift code,let's find out which hour bars make today and yesterday---------------------
   datetime starttoday, startyesterday, startline, stopline, startlabel, startpivottoday;
   //double today_high,today_low,today_open,yesterday_high,yesterday_open,yesterday_low,yesterday_close; //CaveMan moved to Global 
   int      idxfirstbartoday, idxlastbartoday, idxfirstbaryesterday, idxlastbaryesterday,  
            idxstartyesterday, idxendyesterday;  //Caveman added idxstartyesterday and idxendyesterday 
                                   
   TzShift(HrsServerTzFromGMT,HrsChoiceTzFromGMT,idxfirstbartoday, idxfirstbaryesterday, idxlastbaryesterday, idxstartyesterday, idxendyesterday);
   
// Start - Added by CaveMan to decouple today/yesterday separator and pivots starting point    
   //All occurences of "startline = starttoday;" are replaced with "startline = startpivottoday;"
   startpivottoday = Time[1];//Start time of TF bar previous to current bar.  Start point for lines during 1st TF of new day.
   if (Time[0] > iTime(NULL, PERIOD_H1, idxfirstbartoday)){startpivottoday = iTime(NULL, PERIOD_H1, idxfirstbartoday);}       
// End - Added by CaveMan to decouple ytoday/yesterday separator and pivots starting point
   
// Start - Added by CaveMan to decouple yesterday_high/yesterday_low and today/yesterday separator
   starttoday = iTime(NULL, PERIOD_H1, idxfirstbartoday);
   startyesterday = iTime(NULL, PERIOD_H1, idxstartyesterday); 
   //The variables yesterday_high and yesterday_low are too highly coupled to indexes computed by TzShift(). With the 
   //modifications to handle holidays and Sunday data, it has become necessary to decouple yHL and the today/yesterday
   //separator from the rest of the codes without affecting the rest of the indicator codes.

   //Walk forward through yestday's start and collect high/lows within the same day
   true_yesterday_high= -99999;  // not high enough to remain alltime high
   true_yesterday_low=  +99999;  // not low enough to remain alltime low 
   for (int idxbar= idxstartyesterday; idxbar>=idxendyesterday; idxbar--)//Domas4 code
      {
      true_yesterday_high= MathMax(iHigh(NULL, PERIOD_H1, idxbar), true_yesterday_high);
      true_yesterday_low= MathMin(iLow(NULL, PERIOD_H1, idxbar), true_yesterday_low);      
      }
// End - Added by CaveMan to decouple yesterday_high/yesterday_low and today/yesterday separator   
   
   //Walk forward through yestday's start and collect high/lows within the same day
   yesterday_high= -99999;  // not high enough to remain alltime high
   yesterday_low=  +99999;  // not low enough to remain alltime low 
   for (idxbar= idxfirstbaryesterday; idxbar>=idxlastbaryesterday; idxbar--)//Domas4 code
      {
      if (yesterday_open==0) yesterday_open= iOpen(NULL, PERIOD_H1, idxbar);// grab first value for open      
      yesterday_high= MathMax(iHigh(NULL, PERIOD_H1, idxbar), yesterday_high);
      yesterday_low= MathMin(iLow(NULL, PERIOD_H1, idxbar), yesterday_low);      
      yesterday_close= iClose(NULL, PERIOD_H1, idxbar);
      }

   //Walk forward through today and collect high/lows within the same day
   today_open= iOpen(NULL, PERIOD_H1, idxfirstbartoday);  //Domas4 code
   today_high= -99999; 
   today_low=  +99999; 
   for (int j= idxfirstbartoday; j>=0; j--)
      {
      today_high= MathMax(today_high, iHigh(NULL, PERIOD_H1, j));
      today_low= MathMin(today_low, iLow(NULL, PERIOD_H1, j));
      }
     
   //Define yesterday/today data used to calculate pivot levels--------------------------------
   double p,d,q;   
   d = (today_high - today_low);
   q = (yesterday_high - yesterday_low);
   p = (yesterday_high + yesterday_low + yesterday_close) / 3;       
                          
   //------ Comments for upper left corner-----------------------------------------------------       
   if (Show_Data_Panel){
      int b = 76; int x1 = 0; int y1 = 0; int x2 = 3; int y2 = 0;      
      if (Show_Time_To_New_Candle && Chart_OHLC_Is_Shown) {y1=12; y2=12;}
      else {if (Show_Time_To_New_Candle) {b = 78; x2 = 0; y2 = 11;}
      else {if (Chart_OHLC_Is_Shown) {b = 67; y1=12; x2=15; y2=12;} }}  
           
      ObjectCreate("[TzPivotsD] DPbox1", OBJ_LABEL, 0, 0, 0, 0, 0);
      ObjectSetText("[TzPivotsD] DPbox1", "g", b, "Webdings");//76, 84
      ObjectSet("[TzPivotsD] DPbox1", OBJPROP_CORNER, 0);
      ObjectSet("[TzPivotsD] DPbox1", OBJPROP_XDISTANCE, x1);             
      ObjectSet("[TzPivotsD] DPbox1", OBJPROP_YDISTANCE, y1);            
      ObjectSet("[TzPivotsD] DPbox1", OBJPROP_COLOR, Data_Panel_Box_Color);
      ObjectSet("[TzPivotsD] DPbox1", OBJPROP_BACK, false);      
            
      ObjectCreate("[TzPivotsD] DPbox2", OBJ_LABEL, 0, 0, 0, 0, 0);
      ObjectSetText("[TzPivotsD] DPbox2", "g", b, "Webdings");//84
      ObjectSet("[TzPivotsD] DPbox2", OBJPROP_CORNER, 0);
      ObjectSet("[TzPivotsD] DPbox2", OBJPROP_XDISTANCE, x2);                       
      ObjectSet("[TzPivotsD] DPbox2", OBJPROP_YDISTANCE, y2);             
      ObjectSet("[TzPivotsD] DPbox2", OBJPROP_COLOR, Data_Panel_Box_Color);
      ObjectSet("[TzPivotsD] DPbox2", OBJPROP_BACK, false);
            
      //Daily Average Range
      double Ra=0;
      for(int i=0; i<Days_Used_For_Range_Data; i++)
         {Ra = Ra + (iHigh(NULL,PERIOD_D1,i)/Point- iLow(NULL,PERIOD_D1,i)/Point);}
      Ra= (Ra/Days_Used_For_Range_Data); 
      
      //Server net TZ shift and resultant offset from GMT   
      int gmt1 = HrsChoiceTzFromGMT - HrsServerTzFromGMT; //serverTZshift
      int gmt2 = HrsChoiceTzFromGMT;
      
      //Spread
      int spread = MarketInfo(Symbol(), MODE_SPREAD); 
      
      //Move decimal left if 5 digit platform
      double q2= q;            
      if (Platform_Is_5_Digits)
         {
         d = d/10; q2 = q2/10; Ra = Ra/10; spread = spread/10;
         }  

                   
      //Get time (H/M/S) remaining on current candle		
   	int h,m,s,t;    
      t=Time[0]+(Period()*60)-CurTime();
      s=t%60; string seconds= s; if (s<10) seconds= "0"+seconds; 
      m=(t-t%60)/60;   
      for(i=0; i<24; i++){
         if(m>=60){m=m-60;h=h+1;}
         string minutes= m; if (m<10) minutes= "0"+minutes;   
         string hours= h; if (h<10) hours= "0"+hours; 
         string timeleft= minutes+":"+seconds;
       //if (h>=1) timeleft= hours+":"+minutes+":"+seconds;
         if (h>=1) timeleft= hours+":"+minutes;        
         if (Period()>1440) timeleft= "OFF";}
        
                
      //Set up Comment string
      string C= "   ", timeframe;
      string label = string Symbol();      
      if (Chart_OHLC_Is_Shown) C= "";  
      //else {if (Chart_OHLC_is_Shown==false) C= "\n";}            
      if (Chart_OHLC_Is_Shown==false) {
      if (Period()== 1)  C =C +  "   "+label+"   M1\n";
      else {if (Period()== 5)  C =C +  "   "+label+"   M5\n";
      else {if (Period()== 15) C =C +  "  "+label+"   M15\n";
      else {if (Period()== 30)  C =C +  "  "+label+"   M30\n";
      else {if (Period()== 60)  C =C +  "   "+label+"   H1\n";
      else {if (Period()== 240)  C =C +  "   "+label+"   H4\n";
      else {if (Period()== 1440)  C =C +  "  "+label+"   Daily\n";
      else {if (Period()== 10080) C =C +  ""+label+"   Weekly\n";
      else {if (Period()== 43200) C =C +  ""+label+"   Monthly\n"; } }}}}}}}}
      C=C + ".... TzPivotsD v3.5 ....\n";      
      C=C + " Range Today:   "+DoubleToStr(MathRound(d/Point),0)+ "\n";  
      C=C + "      Prior Day:   "+DoubleToStr(MathRound(q2/Point),0)+ "\n";           
      C=C + "         "+Days_Used_For_Range_Data+" Day:   "+ DoubleToStr(Ra,0) + "\n";  
      C=C + "          Spread:   " + DoubleToStr(spread,Digits_To_Show_In_Spread) + "\n"; 
      if ((MarketInfo(Symbol(),MODE_SWAPLONG)<0)) {
      C=C + "    Swap Long:  "+DoubleToStr(MarketInfo(Symbol(),MODE_SWAPLONG),2) + "\n";} 
      else {C=C + "    Swap Long:   "+DoubleToStr(MarketInfo(Symbol(),MODE_SWAPLONG),2) + "\n";}       
      if ((MarketInfo(Symbol(),MODE_SWAPSHORT)<0)) {                    
      C=C + "   Swap Short:  "+DoubleToStr(MarketInfo(Symbol(),MODE_SWAPSHORT),2) + "\n"; }           
      else {C=C + "   Swap Short:   "+DoubleToStr(MarketInfo(Symbol(),MODE_SWAPSHORT),2) + "\n";}          
      if (Show_Time_To_New_Candle) {C=C + "  New Candle:   "+timeleft +"\n"; }                                  
      Comment(C);}      
   
   //Do not skip display of pivots, per user Max TF input--------------------------------------
   if(Period() <= E) {        
   
   //Calculate Pivot Levels--------------------------------------------------------------------
   double r1,r2,r3,r4,r5, s1,s2,s3,s4,s5;       
      
   if(Use_Day_Formula) 
   {
   r3 = (2*p)+(yesterday_high-(2*yesterday_low));
   r2 = p+(yesterday_high - yesterday_low);  //r2 = p-s1+r1;
   r1 = (2*p)-yesterday_low;  
   s1 = (2*p)-yesterday_high;
   s2 = p-(yesterday_high - yesterday_low);  //s2 = p-r1+s1;
   s3 = (2*p)-((2* yesterday_high)-yesterday_low);
   }
   if(Use_Day_Formula == false)
   {
   r5 = p+ (q * 2.618);
   r4 = p+ (q * 1.618);
  	r3 = p+q;  
   r2 = p+ (q * 0.618); 
   r1 = p+ (q * 0.382); 
   s1 = p- (q * 0.382);     
   s2 = p- (q * 0.618);    
  	s3 = p-q; 
   s4 = p- (q * 1.618);
   s5 = p- (q * 2.618);  
   }
   
   //Construct pivot lines and labels----------------------------------------------------------
   //Preparation:
   if (FScr_LineLabels_PerCent_Left < 0) {FScr_LineLabels_PerCent_Left =0;}
   if (FScr_LineLabels_PerCent_Left > 100) {FScr_LineLabels_PerCent_Left =100;}
   MoveLabels = (WindowFirstVisibleBar()*FScr_LineLabels_PerCent_Left)/100;  
   string spc ="";
   stopline = Time[0];
                 
   //Relabeler --------------------------------------------------------------------------------
   A=0; B=0; //reset:  relabeler off, margin labels off
   if (StartLines==1) {
      A=1; //A=1=use fullscreen labels code
      if (FScr_MarginLabels_Shown) B=1;} //B=1=activate margin labels
   if (StartLines != 1){
      if (Time[WindowFirstVisibleBar()- Relabeler_Adjustment] >= iTime(NULL, PERIOD_H1, idxfirstbartoday)){
      A = 1; //labels close to left side of screen.  Switch to full screen lines label coding
      if(FScr_MarginLabels_Shown) B = 1;}}  //activate right margin price labels

   //-----Central Pivot------------------------------------------------------------------------
   if(StartLines == 2 && A == 0)//start@separators-not yet fullscreen, B=0=no margin labels
      {
      spc="              ";//14
      if(PivotLabels_Prices ){spc="                              ";}//30
      startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday);  
      startline = startpivottoday;
      }  
   if(A == 1)//lines fullscreen
      {
      spc="                 ";//17
      if(PivotLabels_Prices ){spc="                                 ";}//33
      startlabel= Time[MoveLabels];
      startline = WindowFirstVisibleBar();
      }      
   if(StartLines==3) 
      {
      spc="              ";//14
      if(PivotLabels_Prices ){spc="                              ";}//30      
      startlabel = Time[0];    
      startline  = Time[1];       
      }             
              
   if(Use_Day_Formula){     
   Pivots("    DPV", p, CentralPivot_Color, CP_LineStyle_01234 ,
               CP_SolidLineThickness, startline, stopline, startlabel, B, spc);}
   if(Use_Day_Formula == false){  
   Pivots("    FPV", p, CentralPivot_Color, CP_LineStyle_01234 ,
               CP_SolidLineThickness, startline, stopline, startlabel, B, spc);}
                  
   //-----Main Pivots--------------------------------------------------------------------------
   if(StartLines == 2 && A == 0) 
      {
      spc="              ";//14
      if(PivotLabels_Prices ){spc="                              ";}//30
      startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday);  
      startline = startpivottoday;
      }
   if(A == 1)
      {
      spc="                 ";//17
      if(PivotLabels_Prices ){spc="                                 ";}//33
      startlabel= Time[MoveLabels];      
      startline = WindowFirstVisibleBar();
      }      
   if(StartLines==3) 
      {
      spc="              ";//14
      if(PivotLabels_Prices ){spc="                              ";}//30
      startlabel = Time[0];    
      startline  = Time[1];       
      }       

   if(R_LineStyle_01234>0){R_SolidLineThickness=0;} 
   if(S_LineStyle_01234>0){S_SolidLineThickness=0;} 

   Pivots("      R3", r3, Resistance_Pivots_Color, R_LineStyle_01234, R_SolidLineThickness, startline, stopline, startlabel, B, spc);   
   Pivots("      R2", r2, Resistance_Pivots_Color, R_LineStyle_01234, R_SolidLineThickness, startline, stopline, startlabel, B, spc); 
   Pivots("      R1", r1, Resistance_Pivots_Color, R_LineStyle_01234, R_SolidLineThickness, startline, stopline, startlabel, B, spc);   
   Pivots("      S1", s1, Support_Pivots_Color, S_LineStyle_01234, S_SolidLineThickness, startline, stopline, startlabel, B, spc);
   Pivots("      S2", s2, Support_Pivots_Color, S_LineStyle_01234, S_SolidLineThickness, startline, stopline, startlabel, B, spc);
   Pivots("      S3", s3, Support_Pivots_Color, S_LineStyle_01234, S_SolidLineThickness, startline, stopline, startlabel, B, spc);    

   if(Use_Day_Formula==false){
   Pivots("      R5", r5, Resistance_Pivots_Color, R_LineStyle_01234, R_SolidLineThickness, startline, stopline, startlabel, B, spc);  
   Pivots("      R4", r4, Resistance_Pivots_Color, R_LineStyle_01234, R_SolidLineThickness, startline, stopline, startlabel, B, spc);
   Pivots("      S4", s4, Support_Pivots_Color, S_LineStyle_01234, S_SolidLineThickness, startline, stopline, startlabel, B, spc);
   Pivots("      S5", s5, Support_Pivots_Color, S_LineStyle_01234, S_SolidLineThickness, startline, stopline, startlabel, B, spc);}
   
   //-----Midpoint Pivots----------------------------------------------------------------------
   if (Show_MidPivots) 
      {
      spc="";
      if(StartLines == 2 && A == 0)//start at day separator
         {
         spc="              ";//14
         if(PivotLabels_Prices ){spc="                              ";}//30
         startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday);  
         startline = startpivottoday;
         }
      if(A == 1)//switched to full screen
         {
         spc="                 ";//17
         if(PivotLabels_Prices ){spc="                                 ";}//33
         startlabel= Time[MoveLabels]; 
         startline = WindowFirstVisibleBar();
         } 
      if(StartLines==3) 
         {
         spc="             ";//13
         if(PivotLabels_Prices ){spc="                              ";}//30   
         startlabel = Time[0];    
         startline  = Time[1];       
         }        
               
      if(mP_LineStyle_01234>0){mP_SolidLineThickness=0;}

      Pivots("   mR3", (r2+r3)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mR2", (r1+r2)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mR1", (p+r1)/2,  MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mS1", (p+s1)/2,  MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mS2", (s1+s2)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mS3", (s2+s3)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      
      if(Use_Day_Formula==false){
      Pivots("   mR5", (r4+r5)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mR4", (r3+r4)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);      
      Pivots("   mS4", (s3+s4)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("   mS5", (s4+s5)/2, MidPivots_Color, mP_LineStyle_01234, mP_SolidLineThickness, startline, stopline, startlabel, B, spc);}     
      }

   //-----Quarterpoint Pivots------------------------------------------------------------------
   if (Show_QuarterPivots) 
      {
      spc="";
      if(StartLines == 2 && A == 0)
         {
         spc="              ";//14
         if(PivotLabels_Prices ){spc="                              ";}//30
         startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday);  
         startline = startpivottoday;
         }
      if(A == 1)
         {
         spc="                 ";//17
         if(PivotLabels_Prices ){spc="                                 ";}//33
         startlabel= Time[MoveLabels];
         startline = WindowFirstVisibleBar();
         } 
      if(StartLines==3) 
         {
         spc="              ";//14
         if(PivotLabels_Prices ){spc="                              ";}//30
         startlabel = Time[0];    
         startline  = Time[1];       
         }         
                               
      if(qP_LineStyle_01234>0){qP_SolidLineThickness=0;} 
     
      Pivots("  q3R3", r2+((r3-r2)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q1R3", r2+(r3-r2)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3R2", r1+((r2-r1)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q1R2", r1+(r2-r1)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3R1", p+((r1-p)/4)*3,   QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q1R1", p+(r1-p)/4,       QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);     
      Pivots("  q1S1", p-(p-s1)/4,       QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3S1", p-((p-s1)/4)*3,   QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);     
      Pivots("  q1S2", s1-(s1-s2)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3S2", s1-((s1-s2)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc); 
      Pivots("  q1S3", s2-(s2-s3)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3S3", s2-((s2-s3)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      
      if(Use_Day_Formula==false){
      Pivots("  q3R5", r4+((r5-r4)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q1R5", r4+(r5-r4)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3R4", r3+((r4-r3)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q1R4", r3+(r4-r3)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);               
      Pivots("  q1S4", s3-(s3-s4)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3S4", s3-((s3-s4)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc); 
      Pivots("  q1S5", s4-(s4-s5)/4,     QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("  q3S5", s4-((s4-s5)/4)*3, QuarterPivots_Color, qP_LineStyle_01234, qP_SolidLineThickness, startline, stopline, startlabel, B, spc);}
      }

   //-----Today Open---------------------------------------------------------------------------
   if (Show_TodayOpen)
      {
      spc="";
      if(StartLines == 2 && A == 0)
         {
         spc="              ";//14
         if(PivotLabels_Prices ){spc="                              ";}//30
         startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday);  
         startline = startpivottoday;
         }
      if(A == 1)
         {
         spc="                 ";//17
         if(PivotLabels_Prices ){spc="                                 ";}//33
         startlabel= Time[MoveLabels];
         startline = WindowFirstVisibleBar();
         } 
      if(StartLines==3) 
         {
         spc="              ";//14
         if(PivotLabels_Prices ){spc="                              ";}//30 
         startlabel = Time[0];    
         startline  = Time[1];       
         }  
        
      if(TO_LineStyle_01234>0){TO_SolidLineThickness=0;} 
      Pivots("  Open",today_open,TodayOpen_Color,TO_LineStyle_01234,
                   TO_SolidLineThickness,startline,stopline,startlabel, B, spc);
      }

   //-----Camarilla Lines----------------------------------------------------------------------
   if (Show_Camarilla) 
      {
      spc="";if (FScr_ShiftLeft_CamarillaLabels<0){FScr_ShiftLeft_CamarillaLabels=0;}
      if(StartLines == 2 && A == 0)
         {
         spc="             ";//13
         if(PivotLabels_Prices ){spc="                            ";}//28
         startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday); 
         if(FScr_ShiftLeft_CamarillaLabels>0) {startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday+FScr_ShiftLeft_CamarillaLabels);}  
         startline = startpivottoday;
         }
      if(A == 1)
         {
         spc="                ";//16
         if(PivotLabels_Prices ){spc="                               ";}//31  
         startlabel= Time[MoveLabels];
         if(FScr_ShiftLeft_CamarillaLabels>0) {spc="";startlabel= Time[MoveLabels+FScr_ShiftLeft_CamarillaLabels];} 
         startline = WindowFirstVisibleBar();
         }   
      if(StartLines==3) 
         {
         spc="             ";//13
         if(PivotLabels_Prices ){spc="                            ";}//28
         startlabel = Time[0];
         if(FScr_ShiftLeft_CamarillaLabels>0) {spc="";startlabel= Time[0+FScr_ShiftLeft_CamarillaLabels];}     
         startline  = Time[1];       
         }  

      if(Cm_LineStyle_01234>0){Cm_SolidLineThickness=0;}
      double cr2, cr1, cs1,cs2;
	   cr2 = (q*1.1/6)+yesterday_close;
	   cr1 = (q*1.1/12)+yesterday_close;
	   cs1 = yesterday_close-(q*1.1/12);	
	   cs2 = yesterday_close-(q*1.1/6);		   
      Pivots("    caR1", cr1, Camarilla_Color, Cm_LineStyle_01234, Cm_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("    caR2", cr2, Camarilla_Color, Cm_LineStyle_01234, Cm_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("    caS1", cs1, Camarilla_Color, Cm_LineStyle_01234, Cm_SolidLineThickness, startline, stopline, startlabel, B, spc);
      Pivots("    caS2", cs2, Camarilla_Color, Cm_LineStyle_01234, Cm_SolidLineThickness, startline, stopline, startlabel, B, spc);
      }

   //-----Yesterday High/Low-------------------------------------------------------------------
   //Modifications made by CaveMan in this section "Yesterday High/Low are:-
   // 1. Replaced yesterday_high with true_yesterday_high and yesterday_low with true_yesterday_low
   // 2. Replaced idxfirstbaryesterday with idxstartyesterday
 
   if (Show_YesterdayHighLow)
      {     
      spc="";if (FScr_ShiftLeft_yHL_Labels<0){FScr_ShiftLeft_yHL_Labels=0;}
      
      //Section A: If StartLine = 2 and lines are not yet full screen
      if(StartLines ==2 && A == 0){
         
         //Put label to right of Yesterday Separator
         spc="            ";//12 
         if(PivotLabels_Prices ){spc="                       ";}//23 
         startlabel= iTime(NULL, PERIOD_H1, idxstartyesterday);
          
         //Put labels to left of startoftoday   // Align labels with other pivot labels
         if(Align_yHL_Labels_With_Pivots){
         spc="                     ";//21
         if(PivotLabels_Prices ){spc="                                     ";}//38, 37(v3.4.6)
         startlabel= iTime(NULL, PERIOD_H1, idxfirstbartoday + yHL_Labels_TabLeftofSeparator);}          
 
         //if Yesterday Separator is off chart, put label at left on chart if they are not just left of Today Separator
         if (iTime(NULL, 0, WindowFirstVisibleBar()) >= iTime(NULL, PERIOD_H1, idxstartyesterday)){ 
            if( Align_yHL_Labels_With_Pivots==false){
            spc = "                         ";//25
            if(PivotLabels_Prices ){spc="                                    ";}//36         
            startlabel= iTime(NULL, 0, WindowFirstVisibleBar());}}
         
         //Move labels left only if startofyesterday is off screen AND the desired position is left of 
         //startoftoday and right of the left screen boundary                      
         if(FScr_ShiftLeft_yHL_Labels>0){
            if(iTime(NULL,0,WindowFirstVisibleBar()) >= iTime(NULL, PERIOD_H1, idxstartyesterday) && 
            iTime(NULL,PERIOD_H1,idxfirstbartoday+FScr_ShiftLeft_yHL_Labels) >= iTime(NULL,0,WindowFirstVisibleBar())){                
               spc="                                       ";//39
               if(PivotLabels_Prices ){spc="                     ";}//21
               startlabel=iTime(NULL, PERIOD_H1, idxfirstbartoday+FScr_ShiftLeft_yHL_Labels);}}  //*****}
               
         //Define time to start line and close Section A.                 
         startline = iTime(NULL, PERIOD_H1, idxstartyesterday);}
                          
      if(A == 1)
         {
         spc="                 ";//17
         if(PivotLabels_Prices ){spc="                                 ";}  //33
         startlabel= Time[MoveLabels];
         if(FScr_ShiftLeft_yHL_Labels>0) {spc=""; startlabel= Time[MoveLabels+FScr_ShiftLeft_yHL_Labels];} 
         startline = WindowFirstVisibleBar();         
         }             
      if(StartLines==3) 
         {
         spc="              ";//14
         if(PivotLabels_Prices ){spc="                              ";}//30
         startlabel = Time[0];
         if(FScr_ShiftLeft_yHL_Labels>0) {spc="";startlabel= Time[0+FScr_ShiftLeft_yHL_Labels];}
         startline  = Time[1];
         //Put label to right of Yesterday Separator
         if(yHL_StartLine2_With_StartLine3){startline = iTime(NULL, PERIOD_H1, idxstartyesterday);            
         spc="            ";//12 
         if(PivotLabels_Prices ){spc="                       ";}//23 
         startlabel= iTime(NULL, PERIOD_H1, idxstartyesterday);}                
         }                              
    
      //Make dual configuration lines (example: solid before today, dotted thru today)
      if(StartLines==2 && A==0){ 
      //if(StartLines==2){                   
         Pivots("yH ",true_yesterday_high,YesterdayHighLow_Color,Yest_yHL_LineStyle_01234,
                   Yest_yHL_SolidLineThickness,startyesterday, starttoday, startlabel,B, spc);      
         Pivots("yL ",true_yesterday_low,YesterdayHighLow_Color,Yest_yHL_LineStyle_01234,
                   Yest_yHL_SolidLineThickness,startyesterday, starttoday, startlabel,B, spc);                                                     
         Pivots("yHigh",true_yesterday_high,YesterdayHighLow_Color,Today_yHL_LineStyle_01234,
                   Today_yHL_SolidLineThickness,starttoday, stopline, 0 ,B, spc);      
         Pivots("yLow",true_yesterday_low,YesterdayHighLow_Color,Today_yHL_LineStyle_01234,
                   Today_yHL_SolidLineThickness,starttoday, stopline, 0 ,B, spc);}                    
                                               
      else{ if(StartLines==3 && yHL_StartLine2_With_StartLine3){ 
         Pivots("yH ",true_yesterday_high,YesterdayHighLow_Color,Yest_yHL_LineStyle_01234,
                   Yest_yHL_SolidLineThickness,startyesterday, starttoday, startlabel,B, spc);      
         Pivots("yL ",true_yesterday_low,YesterdayHighLow_Color,Yest_yHL_LineStyle_01234,
                   Yest_yHL_SolidLineThickness,startyesterday, starttoday, startlabel,B, spc);                                                     
         Pivots("yHigh",true_yesterday_high,YesterdayHighLow_Color,Today_yHL_LineStyle_01234,
                   Today_yHL_SolidLineThickness,starttoday, stopline, 0 ,B, spc);      
         Pivots("yLow",true_yesterday_low,YesterdayHighLow_Color,Today_yHL_LineStyle_01234,
                   Today_yHL_SolidLineThickness,starttoday, stopline, 0 ,B, spc);} 
      
      //Otherwise lines are full screen, so draw yHL lines according to Today_yHL style selection    
      else{              
         Pivots("       yH",true_yesterday_high,YesterdayHighLow_Color,Today_yHL_LineStyle_01234,
                   Today_yHL_SolidLineThickness,startline, stopline, startlabel,B, spc);      
         Pivots("       yL",true_yesterday_low,YesterdayHighLow_Color,Today_yHL_LineStyle_01234,
                   Today_yHL_SolidLineThickness,startline, stopline, startlabel,B, spc);}}
                                                                                  
      }
  
   //Draw the Period Separators and labels-----------------------------------------------------
   if(Period() < 1440) 
      {
      if(Separator_Today_Shown){
         int DZ = HrsChoiceTzFromGMT;
         string GMT = "(GMT)        ";
         if(DZ>0 &&  DZ<10) {GMT = "(GMT +"+ DZ +")   ";}
         if(DZ>=10) {GMT = "(GMT +"+ DZ +") ";}
         if(DZ<0 && DZ>-10) {GMT = "(GMT "+ DZ +")    ";}
         if(DZ<=-10) GMT = "(GMT "+ DZ +")  ";         
         if(Separator_LineStyle_01234>0) {Separator_SolidLineThickness=1;}	
      	double YadjustTop = (WindowPriceMax()-WindowPriceMin())/5000;
      	double YadjustBot = (WindowPriceMax()-WindowPriceMin())/(375/SeparatorLabels_FontSize); 	
         double level = WindowPriceMax() - YadjustTop; if (SeparatorLabels_Chart_Bottom){level = WindowPriceMin() + YadjustBot;}
         if (SeparatorLabels_Detailed){
            Separator("YesterdayEnd", Today + GMT, starttoday, SeparatorLabels_Color,level);}
         else{Separator("YesterdayEnd", Today, starttoday, SeparatorLabels_Color,level);}}
                
      if(Separator_Yesterday_Shown){     
         if (SeparatorLabels_Detailed){
            Separator("YesterdayStart", Yesterday + GMT, startyesterday, SeparatorLabels_Color,level);}
         else{Separator("YesterdayStart", Yesterday, startyesterday, SeparatorLabels_Color,level);}}        
      } 

   //Yesterday & Today Boxes and Candle code---------------------------------------------------

   if (Show_Today_Box) {
      colorbox("Today Box", iTime(NULL, PERIOD_H1, idxfirstbartoday), 
      Time[0], today_high, today_low, Today_Box_Color);}

// Start - Added by CaveMan to decouple yesterday_high/yesterday_low and today/yesterday separator
   //Modifications made by CaveMan in this section "Yesterday High/Low are:-
   // 1. Replaced yesterday_high with true_yesterday_high and yesterday_low with true_yesterday_low
   // 2. Replaced idxfirstbaryesterday with idxstartyesterday
   if (Show_Yesterday_Box) {
      colorbox("Yesterday Box", iTime(NULL, PERIOD_H1, idxstartyesterday), 
      iTime(NULL, PERIOD_H1, idxfirstbartoday), true_yesterday_high, true_yesterday_low, Yesterday_Box_Color);}
// End - Added by CaveMan to decouple yesterday_high/yesterday_low and today/yesterday separator

   if (Show_DayCandle)
      {
      double modifier = 1; if (digits==3 || digits==5) {modifier = 10.0;}
      TodayBar  = iBarShift(NULL,PERIOD_D1,iTime(NULL, PERIOD_H1, idxfirstbartoday));
      double open= iOpen(NULL, PERIOD_H1, idxfirstbartoday);
      double current  = iClose(NULL,PERIOD_H1,idxlastbartoday);      
      double change   = (current-open)/(Point*modifier);  
      int shift = 0; if(change>0){DayHigh[shift] = today_high; DayLow[shift] = today_low;}            
      else {DayHigh[shift] = today_low; DayLow[shift] = today_high;}            
      DayOpen[shift] = open+0.000001; DayClose[shift] = current;                      
      int limit; for(i=0,limit=Bars-1;i<4;i++) SetIndexDrawBegin(i,limit); 
      }

   //------ Finished 
   }  
   return(0);
}
   
//+-------------------------------------------------------------------------------------------+
//| Pivots sub-routine to name and draw pivot lines and labels                                |                                                                                  |
//+---------------------------------------------------------------------------------------- --+
void Pivots(string text, double level, color col1, int linestyle, int thickness, 
   datetime startline, datetime stopline, datetime startlabel, int CC, string spc)
   {
   //Assign names to lines and labels---------------------------------------------------------- 
   string pivotline = "[TzPivotsD] " + StringTrimLeft(text) + " Line"; 
   string pivotlabel = "[TzPivotsD] " + StringTrimLeft(text) + " Label";

   //Create or move horizontal line------------------------------------------------------------   
   int a = linestyle, b = thickness, c =1; if (a==0)c=b; 
   int F = true; //draw line as ray
   int G = true; //subordinate right margin labels & pivot lines    
   int Z; 
   if (CC == 0){Z = OBJ_TREND;}
   if (CC == 1){Z = OBJ_HLINE;}
   if (StopLines_At_Current_Candle && StartLines != 3){F = false;}  
   if (!PivotLabels_Subordinate && B==1) {G= false;}
   if (StringSubstr(text,0,3)=="yH "||StringSubstr(text,0,3)=="yL ") {text= StringSubstr(text,0,2); F= false;}                    
  
   //Draw the horizontal line 
   if (ObjectFind(pivotline) != 0){
      ObjectCreate(pivotline, Z, 0, startline, level, stopline, level);
      ObjectSet(pivotline, OBJPROP_STYLE, linestyle);
      ObjectSet(pivotline, OBJPROP_COLOR, col1);
      ObjectSet(pivotline, OBJPROP_WIDTH, c);
      ObjectSet(pivotline, OBJPROP_BACK, G); 
      ObjectSet(pivotline, OBJPROP_RAY, F);}
   else{
      ObjectMove(pivotline, 0, startline, level);
      ObjectMove(pivotline, 1, stopline, level);}
           
   //Create or move the labels----------------------------------------------------------------
   if (StringSubstr(text,4,1) == "D" || StringSubstr(text,4,1) == "F" && !Show_CentralPivot_Label) return (-1); 
   else {if (StringSubstr(text,6,1) == "S" || StringSubstr(text,6,1) == "R" && !Show_MainPivot_Labels) return (-1);        
   else {if (StringSubstr(text,3,1) == "m" && !Show_MidPivot_Labels) return (-1);
   else {if (StringSubstr(text,2,1) == "q" && !Show_QuarterPivot_Labels) return (-1); 
   else {if (StringSubstr(text,2,1) == "O" && !Show_Open_Label) return (-1);       
   else {if (StringSubstr(text,4,1) == "c" && !Show_Camarilla_Labels) return (-1);     
   else {if (StringSubstr(text,0,1) == "y" || StringSubstr(text,7,1) == "y" && !Show_yHL_Labels)return (-1);   
   else
      {                 
      //Define the standard digits used for Price
      if (Use_For_Forex) {Price=DoubleToStr(level, fxDigits);}
      else {Price=DoubleToStr(level, Digits);}   
      if (PivotLabels_Prices  && StrToInteger(text)==0) {text = text + "   " + Price;}      

      //Draw the labels 
      text = spc + text;      
      G= true; if(!PivotLabels_Subordinate) {G= false;}                         
      if (ObjectFind(pivotlabel) != 0){
         ObjectCreate(pivotlabel, OBJ_TEXT, 0, startlabel, level);     
         ObjectSetText(pivotlabel, text, PivotLabels_FontSize, PivotLabels_FontStyle, PivotLabels_Color);
         ObjectSet(pivotlabel, OBJPROP_BACK, G); }       
      else{ObjectMove(pivotlabel, 0, startlabel, level);} 
      }}}}}}}      
   }
   
//+-------------------------------------------------------------------------------------------+
//| Separator sub-routine to name and draw separator lines and labels                         |                                                        
//+-------------------------------------------------------------------------------------------+
void Separator(string objname, string text, int x, color col1, double vleveltext) 
   {
   string vline= "[TzPivotsD] " + objname, vlabel = vline + " Label";
   
   if (ObjectFind(vline) != 0){ 
      ObjectCreate(vline, OBJ_TREND, 0, x, 0, x, 100);
      ObjectSet(vline, OBJPROP_STYLE, Separator_LineStyle_01234);
      ObjectSet(vline, OBJPROP_COLOR, Separator_Color);
      ObjectSet(vline, OBJPROP_WIDTH, Separator_SolidLineThickness);
      ObjectSet(vline, OBJPROP_BACK, true);}
   else{
      ObjectMove(vline, 0, x, 0); 
      ObjectMove(vline, 1, x, 100);}
        
   if(SeparatorLabels_Shown){                           
      if (ObjectFind(vlabel) != 0){
         ObjectCreate (vlabel, OBJ_TEXT, 0, x, vleveltext);
         ObjectSetText(vlabel, text, SeparatorLabels_FontSize, SeparatorLabels_FontStyle, SeparatorLabels_Color); 
         ObjectSet(vlabel, OBJPROP_BACK, false);         
         if(SeparatorLabels_Subordinate) {ObjectSet(vlabel, OBJPROP_BACK, true);}}       
      else{ObjectMove(vlabel, 0, x, vleveltext);}}
   }
   
//+-------------------------------------------------------------------------------------------+
//| colorbox sub-routine to draw colored background for yesterday & today sessions            |                                                 
//+-------------------------------------------------------------------------------------------+      
void colorbox (string name, double starttime, double endtime, double high, double low, color col2)
   {
   string box = "[TzPivotsD] " + name;
   if (ObjectFind(box) != 0){
      ObjectCreate(box,OBJ_RECTANGLE,0,0,0);
      ObjectSet(box,OBJPROP_TIME1,starttime);
      ObjectSet(box,OBJPROP_TIME2,endtime);
      ObjectSet(box,OBJPROP_PRICE1,high);
      ObjectSet(box,OBJPROP_PRICE2,low);
      ObjectSet(box,OBJPROP_COLOR,col2);}
   else{      
      ObjectMove(box, 0, starttime, high);
      ObjectMove(box, 1, endtime, low);}                             
   }
 
//+-------------------------------------------------------------------------------------------+
//| TzShift sub-routine computes index of first/last bars of yesterday & first bar  of today  |
//+-------------------------------------------------------------------------------------------+
void TzShift(int tzServer, int tzChoice, int &idxfirstbartoday, int &idxfirstbaryesterday,int &idxlastbaryesterday,
             int &idxstartyesterday, int &idxendyesterday)//CaveMan adds 2 variables to decouple yHL & Yest/Today separators                
   {      
   int tzdiff               = tzServer - tzChoice,
       tzdiffsec            = tzdiff*3600, 
       barsperday           = (1440/PERIOD_H1),      
       dayofweektoday       = TimeDayOfWeek(iTime(NULL, PERIOD_H1, 0) - tzdiffsec),
       dayofweektofind      = -1;     
                
   //Due to gaps in the data, and shift of time around weekends (due to time zone)
   //it is not as easy as to just look back for a bar with 00:00 time  
   idxfirstbartoday= 0; idxfirstbaryesterday= 0;  idxlastbaryesterday= 0;     
   switch (dayofweektoday) { 
      case 0: dayofweektofind = 5; break; // Sun (Sunday considered as short trading day)
      default: dayofweektofind = dayofweektoday -1; break;}                    

   //Search backwards for the last occurence of a "today's first bar"
   for (int i=1; i<=barsperday + 1; i++){
      datetime timet = iTime(NULL, PERIOD_H1, i) - tzdiffsec;
      if(TimeDayOfWeek(timet) != dayofweektoday) {idxfirstbartoday = i-1;break;}}
   for (int j= 0; j<=2*barsperday + 1; j++) {
      datetime timey = iTime(NULL, PERIOD_H1, i+j) - tzdiffsec;
      if(TimeDayOfWeek(timey) == dayofweektofind) {idxlastbaryesterday = i+j; break;}}
   for (j= 1; j<=barsperday; j++) {
      datetime timey2 = iTime(NULL, PERIOD_H1, idxlastbaryesterday+j) - tzdiffsec;
      if(TimeDayOfWeek(timey2) != dayofweektofind){idxfirstbaryesterday = idxlastbaryesterday+j-1; break;}}
      
        
// Start - Added by CaveMan to cater for missing/partial previous day's data  
   //This section added to assign yesterday's start & end index for use by yHL & Yest/Today separators
   // Search for Friday if yesterday is a Sunday
   if (dayofweektofind != 0)
         {
          idxstartyesterday = idxfirstbaryesterday; // Assign yesterday's first bar location to index
          idxendyesterday = idxlastbaryesterday;    // Assign yesterday's last bar location to index
         }
   else // Search for Friday's data range
         {
            //Search backwards for the last occurence of a "today's first bar"
            for (i=1; i<=barsperday + 1; i++){
               timet = iTime(NULL, PERIOD_H1, i) - tzdiffsec;
               if(TimeDayOfWeek(timet) != dayofweektoday) {idxfirstbartoday = i-1;break;}}
            for (j= 0; j<=2*barsperday + 1; j++) {
               timey = iTime(NULL, PERIOD_H1, i+j) - tzdiffsec;
               if(TimeDayOfWeek(timey) == 5) {idxlastbaryesterday = i+j; break;}}
            for (j= 1; j<=barsperday; j++) {
               timey2 = iTime(NULL, PERIOD_H1, idxlastbaryesterday+j) - tzdiffsec;
               if(TimeDayOfWeek(timey2) != 5){idxfirstbaryesterday = idxlastbaryesterday+j-1;break;}}

           idxstartyesterday = idxfirstbaryesterday; // Assign yesterday's first bar location to index
           idxendyesterday = idxfirstbartoday + 1;    // Assign yesterday's last bar location to index
          }
   //This section takes care of the Christmas and New Year Day problem where there is a day of partial data on the eve
   //of these holidays followed by an entire day without any data at all. The workaround to handle this on market
   //open after the holiday is to use data from the day before the eve of the holiday right up to the end of the eve of
   //the holiday for pivot computation. E.g. On the 26 December market opens after Christmas. Use full day data of 23rd 
   //plus partial data of 24th Dec to compute the pivots. Same applies to New Year Day.
   int YesterdayBarsTotal = idxfirstbaryesterday - idxlastbaryesterday;
   if (YesterdayBarsTotal == 0)   
      {
         if (dayofweektofind == 0) { dayofweektofind = 4;} 
         else if (dayofweektofind == 1) { dayofweektofind = 5;} 
         else {dayofweektofind = dayofweektofind - 1;}

         //Repeat this search with the new dayofweektofind information
         for (i=1; i<=barsperday + 1; i++){
            timet = iTime(NULL, PERIOD_H1, i) - tzdiffsec;
            if(TimeDayOfWeek(timet) != dayofweektoday) {idxfirstbartoday = i-1;break;}}
         for (j= 0; j<=2*barsperday + 1; j++) {
            timey = iTime(NULL, PERIOD_H1, i+j) - tzdiffsec;
            if(TimeDayOfWeek(timey) == dayofweektofind) {idxlastbaryesterday = i+j; break;}}
         for (j= 1; j<=3*barsperday; j++) {
            timey2 = iTime(NULL, PERIOD_H1, idxlastbaryesterday+j) - tzdiffsec;
            if(TimeDayOfWeek(timey2) != dayofweektofind){idxfirstbaryesterday = idxlastbaryesterday+j-1;break;}}
         idxstartyesterday = idxfirstbaryesterday; // Assign yesterday's first bar location to index
         idxendyesterday = idxlastbaryesterday;    // Assign yesterday's last bar location to index
         YesterdayBarsTotal = idxfirstbaryesterday - idxlastbaryesterday;
       }      
   //Standard codes to handle days of partial data (including Fridays and Sundays)
   //If one hour bars < 24, use additional data from one more day back 
   if (YesterdayBarsTotal < 23)
      { 
         if (dayofweektoday == 0 && dayofweektofind == 4) {dayofweektofind = 3;} // for Sunday, search Thursday and found Thursday partial data, then search Wednesday.
         else if (dayofweektoday == 1 && dayofweektofind == 4) {dayofweektofind = 4;} // for Monday, Friday no data then include Thursday and Sunday data.
         else if (dayofweektofind == 0 || dayofweektofind == 1) { dayofweektofind = 5;} 
         else { dayofweektofind = dayofweektofind - 1; }
            //Search backwards for the last occurence of a "today's first bar"
            for (i=1; i<=barsperday + 1; i++){
               timet = iTime(NULL, PERIOD_H1, i) - tzdiffsec;
               if(TimeDayOfWeek(timet) != dayofweektoday) {idxfirstbartoday = i-1;break;}}
            for (j= 0; j<=3*barsperday + 1; j++){ // Need to increase another 24 hours to search
               timey = iTime(NULL, PERIOD_H1, i+j) - tzdiffsec;
               if(TimeDayOfWeek(timey) == dayofweektofind) {idxlastbaryesterday = i+j; break;}}
            for (j= 1; j<=4*barsperday; j++) {
               timey2 = iTime(NULL, PERIOD_H1, idxlastbaryesterday+j) - tzdiffsec;
               if(TimeDayOfWeek(timey2) != dayofweektofind){idxfirstbaryesterday = idxlastbaryesterday+j-1;break;}}     
   //This small section handles a very unique combination of events that coincide during the short opening trading hours 
   //of the Sunday following Christmas Day and New Year Day if both of these holidays happen to fall on a Thursday. 
   //This occured on the short Sunday trading hours before Monday kicks in. For those few hours, pivot used on Friday are 
   //extended into Sunday. These pivot levels are calculated using full Thursday's data. In this unique situation, 
   //Thursday was New Year Day (major public holiday)with no data at all. This will cause TzPivot to malfunction in similar 
   //situation in the future. As a workaround, for those short few hours of Sunday, if a similar situation should occur,
   //partial data of Wednesday and Friday will be used for pivot computation. 
         YesterdayBarsTotal = idxfirstbaryesterday - idxlastbaryesterday;
         if (YesterdayBarsTotal == 0)   
            {
               if (dayofweektofind == 1) { dayofweektofind = 5;}
               else {dayofweektofind = dayofweektofind - 1;}
               //Repeat this search with the new dayofweektofind information
               for (i=1; i<=barsperday + 1; i++){
                  timet = iTime(NULL, PERIOD_H1, i) - tzdiffsec;
                  if(TimeDayOfWeek(timet) != dayofweektoday) {idxfirstbartoday = i-1;break;}}
               for (j= 0; j<=2*barsperday + 1; j++) {
                  timey = iTime(NULL, PERIOD_H1, i+j) - tzdiffsec;
                  if(TimeDayOfWeek(timey) == dayofweektofind) {idxlastbaryesterday = i+j; break;}}
               for (j= 1; j<=3*barsperday; j++) {
                  timey2 = iTime(NULL, PERIOD_H1, idxlastbaryesterday+j) - tzdiffsec;
                  if(TimeDayOfWeek(timey2) != dayofweektofind){idxfirstbaryesterday = idxlastbaryesterday+j-1;break;}}
               idxlastbaryesterday = idxfirstbartoday + 1;
             }
   //Include partial day's data and combine with previous day's data for pivot computation. Do not include for Sundays
   //as Sunday short trading hours uses Friday's pivots that are computed from full Thursday's data.
   //This is more for handling of holidays including Christmas and New Year Day. 
            if (dayofweektoday != 0) idxlastbaryesterday = idxfirstbartoday + 1; 
       }
   //Comments for troubleshooting purposes.       
   if (Show_TzTest_Panel && Show_Data_Panel==false){ 
      int y = 11; if(!Chart_OHLC_Is_Shown) {y = 0;}
      
      ObjectCreate("[TzPivotsD] TZbox1", OBJ_LABEL, 0, 0, 0, 0, 0);
      ObjectSetText("[TzPivotsD] TZbox1", "g", 116, "Webdings");
      ObjectSet("[TzPivotsD] TZbox1", OBJPROP_CORNER, 0);
      ObjectSet("[TzPivotsD] TZbox1", OBJPROP_XDISTANCE, 0);
      ObjectSet("[TzPivotsD] TZbox1", OBJPROP_YDISTANCE, y);                 
      ObjectSet("[TzPivotsD] TZbox1", OBJPROP_COLOR, TzTest_Panel_Box_Color);
      ObjectSet("[TzPivotsD] TZbox1", OBJPROP_BACK, false); 
           
      ObjectCreate("[TzPivotsD] TZbox2", OBJ_LABEL, 0, 0, 0, 0, 0);
      ObjectSetText("[TzPivotsD] TZbox2", "g", 116, "Webdings");
      ObjectSet("[TzPivotsD] TZbox2", OBJPROP_CORNER, 0);
      ObjectSet("[TzPivotsD] TZbox2", OBJPROP_XDISTANCE, 84);
      ObjectSet("[TzPivotsD] TZbox2", OBJPROP_YDISTANCE, y);                 
      ObjectSet("[TzPivotsD] TZbox2", OBJPROP_COLOR, TzTest_Panel_Box_Color);
      ObjectSet("[TzPivotsD] TZbox2", OBJPROP_BACK, false);       
                        
      string C; Comment(C,
      "\n    -------------------   TZ  SHIFT  DATA   ------------------\n", 
      "\n    High, Low, Close         =   ", yesterday_high, " / ", yesterday_low, " / ", yesterday_close,
      "\n    No. of yesterday bars   =   ", YesterdayBarsTotal,
      "\n    Day of week today      =   ", dayofweektoday,
      "\n    Day of week to find     =   ", dayofweektofind,
      "\n    Today Start                =   ", TimeToStr(iTime(NULL,PERIOD_H1,idxfirstbartoday), TIME_DATE|TIME_MINUTES), " (",idxfirstbartoday , ") ",
      "\n    Pivot Range Start        =   ", TimeToStr(iTime(NULL,PERIOD_H1,idxfirstbaryesterday), TIME_DATE|TIME_MINUTES)," (",idxfirstbaryesterday ,") ",
      "\n    Pivot Range End         =   ", TimeToStr(iTime(NULL,PERIOD_H1,idxlastbaryesterday), TIME_DATE|TIME_MINUTES), " (",idxlastbaryesterday,") ",
      "\n    Separator Start            =   ", TimeToStr(iTime(NULL,PERIOD_H1,idxstartyesterday), TIME_DATE|TIME_MINUTES)," (",idxstartyesterday ,") ",
      "\n    Separator End             =   ", TimeToStr(iTime(NULL,PERIOD_H1,idxendyesterday), TIME_DATE|TIME_MINUTES), " (",idxendyesterday,") ");}             
// End - Added by CaveMan to cater for missing/partial previous day's data        

      int today_start = TimeDayOfWeek(iTime(NULL,PERIOD_H1, idxfirstbartoday) - tzdiffsec);
      int yesterday_start = TimeDayOfWeek(iTime(NULL,PERIOD_H1, idxstartyesterday) - tzdiffsec);//CaveMan modified from idxfirstbaryesterday
      switch(today_start){
         case 0: Today = "      Sunday    "; break;
         case 1: Today = "      Monday    "; break;
         case 2: Today = "    Tuesday     "; break;
         case 3: Today = "Wednesday     "; break;
         case 4: Today = "    Thursday    "; break;
         case 5: Today = "      Friday    ";  break;}               
      switch(yesterday_start){
         case 0: Yesterday = "      Sunday    "; break;
         case 1: Yesterday = "      Monday    "; break;
         case 2: Yesterday = "    Tuesday     "; break;
         case 3: Yesterday = "Wednesday     "; break;
         case 4: Yesterday = "    Thursday    "; break;
         case 5: Yesterday = "      Friday    ";  break;}                 
   }

// Start - Added by CaveMan to cater for DST
//+------------------------------------------------------------------------------+
//| Calculate and return actual date given which Sunday of the month information |
//|  --> Only US and EU DST is supported for the time being.                     |
//+------------------------------------------------------------------------------+
bool Adjust_for_DST()
   {
// This definition section can be made into extern for user configuration but not neccesary.

      string Instructions1       = "Enter which Sunday of the month";
      string Instructions2       = "DST should start and end.";
      string Instructions3       = "1,2,3,4,5,6 = 1st, 2nd, 3rd, 4th, 5th and 6th";
      string Instructions4       = "7 = Last Sundy of the month";

      int us_dst_start_sunday    = 2;        // 2nd Sunday of March start DST
      int us_dst_month_start     = 3;        // March
      string us_dst_time_start   = "02:00";  // DST starting time
      int us_dst_end_sunday      = 1;        // 1st Sunday of November end DST
      int us_dst_month_end       = 11;       // November
      string us_dst_time_end     = "02:00";  // DST ending time
 
      int eu_dst_start_sunday    = 7;        // 2nd Sunday of March start DST
      int eu_dst_month_start     = 3;        // March
      string eu_dst_time_start   = "02:00";  // DST starting time
      int eu_dst_end_sunday      = 7;        // 1st Sunday of November end DST
      int eu_dst_month_end       = 10;       // November
      string eu_dst_time_end     = "02:00";  // DST ending time
 
      int aus_dst_start_sunday    = 1;        // 2nd Sunday of March start DST
      int aus_dst_month_start     = 4;        // March
      string aus_dst_time_start   = "02:00";  // DST starting time
      int aus_dst_end_sunday      = 1;        // 1st Sunday of November end DST
      int aus_dst_month_end       = 10;       // November
      string aus_dst_time_end     = "02:00";  // DST ending time

      int nz_dst_start_sunday    = 1;        // 2nd Sunday of March start DST
      int nz_dst_month_start     = 4;        // March
      string nz_dst_time_start   = "02:00";  // DST starting time
      int nz_dst_end_sunday      = 7;        // 1st Sunday of November end DST
      int nz_dst_month_end       = 9;       // November
      string nz_dst_time_end     = "02:00";  // DST ending time

      datetime us_dst_start, us_dst_end; // dst start and end datetime
      datetime eu_dst_start, eu_dst_end; 
      datetime aus_dst_start, aus_dst_end; 
      datetime nz_dst_start, nz_dst_end; 
      datetime cus_dst_start, cus_dst_end; 
      
      int cus_dst_month_start   = Custom_DST_Start_Month;
      int cus_dst_start_sunday  = Custom_DST_Start_Sunday;
      string cus_dst_time_start = Custom_DST_Start_Time;
      int cus_dst_month_end     =  Custom_DST_End_Month;   
      int cus_dst_end_sunday    = Custom_DST_End_Sunday;
      string cus_dst_time_end   =  Custom_DST_End_Time;  
   
//    Print("US DST Start/End Date = ", TimeToStr(us_dst_start), " / ", TimeToStr(us_dst_end));
//    Print("EU DST Start/End Date = ", TimeToStr(eu_dst_start), " / ", TimeToStr(eu_dst_end));
      
      us_dst_start  = check_date(us_dst_start_sunday,  us_dst_month_start,  us_dst_time_start);
      us_dst_end    = check_date(us_dst_end_sunday,    us_dst_month_end,    us_dst_time_end);
      eu_dst_start  = check_date(eu_dst_start_sunday,  eu_dst_month_start,  eu_dst_time_start);
      eu_dst_end    = check_date(eu_dst_end_sunday,    eu_dst_month_end,    eu_dst_time_end);
      aus_dst_start = check_date(aus_dst_start_sunday, aus_dst_month_start, aus_dst_time_start);
      aus_dst_end   = check_date(aus_dst_end_sunday,   aus_dst_month_end,   aus_dst_time_end);
      nz_dst_start  = check_date(nz_dst_start_sunday,  nz_dst_month_start,  nz_dst_time_start);
      nz_dst_end    = check_date(nz_dst_end_sunday,    nz_dst_month_end,    nz_dst_time_end);
      cus_dst_start = check_date(cus_dst_start_sunday, cus_dst_month_start, cus_dst_time_start);
      cus_dst_end   = check_date(cus_dst_end_sunday,   cus_dst_month_end,   cus_dst_time_end);

      if (Auto_Adjust_For_DST && DST_Zone == 1 && iTime(NULL,0,0) > us_dst_start && iTime(NULL,0,0) < us_dst_end)
         {
            HrsServerTzFromGMT = DST_shifted_server_time;
            return(true);
         }
      else if (Auto_Adjust_For_DST && DST_Zone == 2 && iTime(NULL,0,0) > eu_dst_start && iTime(NULL,0,0) < eu_dst_end)
         {
            HrsServerTzFromGMT = DST_shifted_server_time;
            return(true);
         }
      else if (Auto_Adjust_For_DST && DST_Zone == 3 && iTime(NULL,0,0) > aus_dst_start && iTime(NULL,0,0) < aus_dst_end)
         {
            HrsServerTzFromGMT = DST_shifted_server_time;
            return(true);
         }
      else if (Auto_Adjust_For_DST && DST_Zone == 4 && iTime(NULL,0,0) > nz_dst_start && iTime(NULL,0,0) < nz_dst_end)
         {
            HrsServerTzFromGMT = DST_shifted_server_time;
            return(true);
         }
      else if (Auto_Adjust_For_DST && DST_Zone == 5 && iTime(NULL,0,0) > cus_dst_start && iTime(NULL,0,0) < cus_dst_end)
         {
            HrsServerTzFromGMT = DST_shifted_server_time;
            return(true);
         }
      else
         {
            HrsServerTzFromGMT = original_server_time;
            return(false);
         }
} 

//+------------------------------------------------------------------------------+
//| Calculate and return actual date given which Sunday of the month information |
//+------------------------------------------------------------------------------+
datetime check_date(int which_sunday, int which_month, string what_time)
{
   string start_date;
   int day_of_week, start_day;

   if (which_sunday == 7)  // Last Sunday of the month
      {
         for (int i = 31; i > 20; i--)
            {
               start_date = TimeYear(iTime(NULL,0,0)) + "." + which_month + "." + i;
               day_of_week = TimeDayOfWeek(StrToTime(start_date));
               if (day_of_week == 0) // equals to Sunday
                  {
                     start_date = TimeYear(iTime(NULL,0,0)) + "." + which_month + "." + i + " " + what_time;
                     break;
                   }
             } 
      }
   else // other Sundays of the month besides last Sunday of the month
      {
         start_date = TimeYear(iTime(NULL,0,0)) + "." + which_month + "." + "1";
         day_of_week = TimeDayOfWeek(StrToTime(start_date));
   
         if (day_of_week == 0) start_day = 1 + 7*(which_sunday - 1);
         else start_day = 1 + (7 - day_of_week) + 7 * (which_sunday - 1);
   
         start_date = TimeYear(iTime(NULL,0,0)) + "." + which_month + "." + start_day + " " + what_time;
      }
      
   return(StrToTime(start_date));
}
// End - Added by CaveMan to cater for DST

//+-------------------------------------------------------------------------------------------+
//| Program End                                                                               |                                                        
//+-------------------------------------------------------------------------------------------+

Comments