Navigation´╝ÜHome > Content >

TzPivotsMW_v3.5_(Black).mq4

Time: 2015-01-24 | Download file:TzPivotsMW_v3.5_(Black).mq4

//+-------------------------------------------------------------------------------------------+
//|                                                                                           |
//|                                   TzPivotsMW.mq4                                          |
//|                                                                                           |
//+-------------------------------------------------------------------------------------------+

#property copyright "CaveMan, Domas4 and Traderathome, Copyright @ 2009"
#property link      "email:  [email protected]"

/*=============================================================================================
TzPivotsMW_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.  
The label code for the various line placement selections has been changed so that the labels
should now align exactly with the TzPivotsD_v3.5 labels for the same line placements.  The 
External Inputs Window has been re-arranged.

TzPivotsMW_v3:
New DST code from CaveMan automates the turning On/Off of DST so there is no need to adjust
your time zone shift settings twice a year.  It provides for customizing your own DST 
setting should you/your broker be in a time zone not covered by the DST code as it is.
New code from Domas4 lets you enter a time frame, above which the indicator will not display.
This lets you switch to large TF charts to make assesments without having to turn the indy
off to remove a congestion of pivot lines.  The external inputs section is reworked.  Most
notably a "Pivot Line Star/Stopt Settings" section is added along with new code that allows 
lines to be started at the Day Separator.  This establishes greater compatibility with the 
"PivotsD" indy.  In addition, labels for Monthly and Weekly pivots now have separate shift 
inputs.  If a Monthly line is so close to a Weekly line that their labels interfere, you can
use different shift numbers to display the Monthy and Weekly labels. Code for MaxRight label
settings is removed because the current labels shift code accomplishes the same within a few
character spaces.

TzPivotsMW_v2:
Errant pivots issue is fixed.  The ability for price labels to handle the pricing of non-forex
items (Gold, Oil, Stocks, etc.) is incorporated by Domas4.

TzPivotsMW:
Both Monthy and Weekly pivots can be displayed with this indicator.  It provides for color 
and line style selection of pivot lines.  It provides for color, font size and font style 
selection of line labels, and the ability to position labels from far left to far right on 
chart.  The default setting for the labels is to the far left on the chart.  As you zoom 
in/out on the chart, an activity that will distort the position of the labels, with the next 
incoming data tic each label is automatically restored to the proper position.  Included is 
the ability to independently turn on/off the price displayed in the line labels and also in 
the right chart margin. Pivot lines can be calculated using either the "Daily" pivot formula 
(default), or the "Fibonacci" formula, which has two added levels.  Included are MidPivot 
lines which can be turned on/off.

Compliments of Domas4, the indicator allows the pivot lines to display using different line 
styles for the current day than for all time previous.  You can for example, accentuate the 
historic M and W pivots using the solid line style, but select the "DOT" style for their 
display thru the current day, thus subordinating them to any Daily pivots that may also be 
shown.  Or instead, you can accentuate the lines in the "Today zone" with solid and use one 
of the not-solid line styles for the "historic lines" prior to the start of the day.

Since users may use a daily pivot indicator that shifts time zones (EX: the new TzPivotsD or 
versions of SDX-TzPivots), the same new Domas4 time shift code that is used in TzPivotsD 
(an improvement over the Shimodax code used in SDX-TzPivots) is incorporated. By using the 
same Tz shift settings as would be used in TzPivotsD or SDX-TzPivots, this indicator will 
switch at the proper time to the different line style selected for the current day.  To show 
pivot lines with one style before the current day and another style during the current day, 
the full screen lines option must not be selected.  If it is selected, then pivot lines will 
be normal full screen lines per the Part_3 settings.   Per MT4 code, normal full screen lines 
are the only linee for which right margin labels can be displayed.

Another line display configuration provided by Domas4 is the option to stop the lines at the 
current candle, instead of at the right chart margin.  This option works whether or not the 
option for fullscreen lines has been selected.  If it has been selected, then the full screen 
lines will be changed and stop at the current candle.  In this event, right margin price 
labels, if selected, will no longer display (because lines are no longer full screen lines).

A variety of font styles are availabe for the label displays.  Just enter the name of the 
font style you want.  Arial, Batang and Verdana are good for plain type.  Arial Bold and 
Verdana Bold produce good "medium thickness" type.  Arial Black produces "bold thickness" 
type.  The default is Verdana, as it tends to be very legible thru a wide range of font sizes.  
You can also subordinate labels, so that they lay beneath chart lines and other chart items.
   
The first item in the Indicator Window is the "ON/OFF" switch for the indicator, with a 
default of "true".  To turn the indicator display "Off", removing all the pivot lines and 
labels it displays, just edit this to "false".  You do not have to remove the indicator from 
your chart indicators list.  Your indicator settings for that chart are reserved while "Off". 

TzPivotsMW is a fine match to the new TzPivotsD, and as with the creation of that indicator, 
Domas4 is greatly appreciated for his splendid work on this indicator.
                                                                              - Traderathome
=============================================================================================*/                                                                            
#property  indicator_chart_window
#property indicator_buffers  1
#property indicator_color1   CLR_NONE
/*---------------------------------------------------------------------------------------------
Color Suggestions:              White Chart              Black Chart   

MainPivot_Color                 Blue                     C'27,63,171'
Pivot_Resistances_Color         Tomato                   Maroon     
Pivot_Supports_Color            LimeGreen                DarkGreen   
MidPivots_Color                 Olive                    C'85,85,0'
LabelsColor                     LightSlateGray           DarkGray 
---------------------------------------------------------------------------------------------*/

//---- Global 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   MonthlyPivots_Shown             = true;
extern bool   MonthlyPivots_Day_Formula       = true;
extern bool   WeeklyPivots_Shown              = true;
extern bool   WeeklyPivots_Day_Formula        = true;

extern string ____                            = "";
extern string Part_4                          = "Pivot Lines Start/Stop Settings:";
extern string note10                          = "Start with fullscreen lines, enter '1'";
extern string note11                          = "Start lines at Day Separator, enter '2'";
extern string note12                          = "Start lines at current candle, enter '3'";
extern int    StartLines                      = 1;
extern bool   StopLines_At_Current_Candle     = true;

extern string _____                           = "";
extern string Part_5                          = "Pivot Lines Appearance Settings:";
extern color  MainPivot_Color                 = C'27,63,171';     
extern color  Resistance_Pivots_Color         = Maroon;      
extern color  Support_Pivots_Color            = DarkGreen;     
extern color  MidPivots_Color                 = C'85,85,0'; 
extern bool   Show_Monthly_MidPivots          = true; 
extern bool   Show_Weekly_MidPivots           = true;
extern int    CurrentDay_LineStyle_01234      = 2;
extern int    CurrentDay_SolidLineThickness   = 1; 
extern int    Prior\FScr_LineStyle_01234      = 0;     
extern int    Prior\FScr_SolidLineThickness   = 1;
extern bool   FScr_With_Dual_Configuration    = true;

extern string ______                          = "";
extern string Part_6                          = "Label Settings:"; 
extern bool   PivotLabels_Subordinate         = true; 
extern color  PivotLabels_Color               = DarkGray; 
extern string PivotLabels_FontStyle           = "Verdana Bold";
extern int    PivotLabels_Fontsize            = 10;
extern int    Shift_MonthLabels_PerCent_Left  = 73;
extern int    Shift_WeekLabels_PerCent_Left   = 60;  
extern bool   Show_Monthly_CentralPivot_Label = true;
extern bool   Show_Monthly_MainPivot_Labels   = true;
extern bool   Show_Monthly_MidPivot_Labels    = true;
extern bool   Show_Weekly_CentralPivot_Label  = true;
extern bool   Show_Weekly_MainPivot_Labels    = true;
extern bool   Show_Weekly_MidPivot_Labels     = true;
extern bool   Show_Price_in_PivotLabels       = true;
extern bool   Show_RightMargin_Prices         = false;

// Start - Added by CaveMan to cater for DST
extern string ________                        = "";
extern string Part_8                          = "DST Zone Settings:";
extern string note1                           = "Enter preset DST zone number 1 - 4";
extern string note2                           = "or enter ' 5 ' for a custom DST zone.";
extern string note3                           = "1 US   2 EU   3 AUS   4 NZ   5 Cust.";
extern int    DST_Zone                        = 1;
extern bool   Auto_Adjust_For_DST             = true;
extern string note4                           = "To customized A DST setting -";  
extern string note5                           = "Enter # month DST starts,";
extern int    Custom_DST_Start_Month          = 3; //March
extern string note6                           = "Enter # Sunday DST starts,";
extern string note7                           = "1-1st Sunday, 2-2nd ....7-Last Sunday";
extern int    Custom_DST_Start_Sunday         = 2; //2nd Sunday of March start DST
extern string note8                           = "Enter 24 hour time DST starts,";
extern string Custom_DST_Start_Time           = "02:00"; //DST starting time
extern string note9                           = "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

//---- Global Internal Buffers and Variables
int      fxDigits,CalcPeriod,shift,dow,S;
datetime StartTime;
double   HiPrice,LoPrice,Range,ClosePrice,Pivot,R1,S1,R2,S2,R3,S3,R4,S4,R5,S5;
string   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

//+-------------------------------------------------------------------------------------------+
//| 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;}}
      }
     
   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)=="[TzPivotsMW") {ObjectDelete(name);}
      }                   
   return(0);
   } 
     
//+-------------------------------------------------------------------------------------------+
//| Program Start                                                                             |
//+-------------------------------------------------------------------------------------------+   
int start()
   {  
   deinit(); if (Indicator_On == false) {deinit(); 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(" TzPivotMW - Daylight Savings Time (DST) is in effect.");}
      First_Time = false; LastRefresh = TimeHour(iTime(NULL,0,0));}
// End - Added by CaveMan to cater for DST

   //Shift Tz section--------------------------------------------------------------------------     
   datetime startofday, startofday2;  
   int idxfirstbaroftoday, idxfirstbarofyesterday;      
   TzShift(HrsServerTzFromGMT, HrsChoiceTzFromGMT, idxfirstbaroftoday);
   startofday= iTime(NULL, PERIOD_H1, idxfirstbaroftoday); 
   startofday2= Time[1]; 
   if (Time[0] > iTime(NULL, PERIOD_H1, idxfirstbaroftoday))
      {startofday2 = iTime(NULL, PERIOD_H1, idxfirstbaroftoday);}
 
   //Do Weekly Pivots--------------------------------------------------------------------------
   if (WeeklyPivots_Shown)
      {  	 	
      string wpLineStr,wpStr,wp,ws1Str;
      string wS1LineStr,ws1,wr1Str,wR1LineStr,wr1;
   	string ws2Str,wS2LineStr,ws2,wr2Str,wR2LineStr,wr2; 
   	string ws3Str,wS3LineStr,ws3,wr3Str,wR3LineStr,wr3;
   	string ws4Str,wS4LineStr,ws4,wr4Str,wR4LineStr,wr4;
   	string ws5Str,wS5LineStr,ws5,wr5Str,wR5LineStr,wr5;
   	string wmrLineStr; S=1;
	
      if (WeeklyPivots_Day_Formula)
         { 
         wpLineStr  = "    WPV";
         wS1LineStr = "    WS1";
         wR1LineStr = "    WR1";
         wS2LineStr = "    WS2";
         wR2LineStr = "    WR2";
         wS3LineStr = "    WS3";
         wR3LineStr = "    WR3";
         wmrLineStr = "Wm";            
         }        
      else  
         {
         wpLineStr  = " WFPV";
         wS1LineStr = " WFS1";
         wR1LineStr = " WFR1";
         wS2LineStr = " WFS2";
         wR2LineStr = " WFR2";
         wS3LineStr = " WFS3";
         wR3LineStr = " WFR3";
         wS4LineStr = " WFS4";
         wR4LineStr = " WFR4";
         wS5LineStr = " WFS5";
         wR5LineStr = " WFR5";
         wmrLineStr = "Wm";
         }
                   
      CalcPeriod = 10080; 
      shift	= iBarShift(NULL,CalcPeriod,Time[0])+ 1;//default=one period ago	
   
   	ClosePrice  = NormalizeDouble(iClose(NULL,CalcPeriod,shift),4);
      HiPrice     = NormalizeDouble (iHigh(NULL,CalcPeriod,shift),4); 
      LoPrice     = NormalizeDouble (iLow(NULL,CalcPeriod,shift),4);
      Range       = HiPrice -  LoPrice;
      Pivot       = NormalizeDouble((HiPrice+LoPrice+ClosePrice)/3,4);
      
      if (WeeklyPivots_Day_Formula)
         {
         R1 = (2*Pivot)-LoPrice;
         S1 = (2*Pivot)-HiPrice;
         R2 = Pivot+(R1-S1);
         S2 = Pivot-(R1-S1); 
         R3 = ( 2.0 * Pivot) + ( HiPrice - ( 2.0 * LoPrice ) );
         S3 = ( 2.0 * Pivot) - ( ( 2.0 * HiPrice ) - LoPrice );         
         }
      else
         {   
         R1 = Pivot + (Range  * 0.382);
         S1 = Pivot - (Range  * 0.382); 
         R2 = Pivot + (Range  * 0.618);
         S2 = Pivot - (Range  * 0.618);
         R3 = Pivot +  Range ;  
         S3 = Pivot -  Range ;
         R4 = Pivot + (Range  * 1.618);
         S4 = Pivot - (Range  * 1.618);
         R5 = Pivot + (Range  * 2.618);
         S5 = Pivot - (Range  * 2.618);
         }

      drawLine("wR3", R3, Resistance_Pivots_Color,startofday,startofday2); 
      drawLabel( wR3LineStr,R3,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wR2", R2, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(wR2LineStr,R2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wR1", R1, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(wR1LineStr,R1,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wPIVOT", Pivot, MainPivot_Color,startofday,startofday2);
      drawLabel(wpLineStr, Pivot,PivotLabels_Color,S,startofday,startofday);
      drawLine("wS1", S1, Support_Pivots_Color,startofday,startofday2);
      drawLabel(wS1LineStr,S1,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wS2", S2, Support_Pivots_Color,startofday,startofday2);
      drawLabel(wS2LineStr,S2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wS3", S3, Support_Pivots_Color,startofday,startofday2);
      drawLabel(wS3LineStr ,S3,PivotLabels_Color,S,startofday,startofday2);
     
      if(WeeklyPivots_Day_Formula==false){
      drawLine("wR5", R5, Resistance_Pivots_Color,startofday,startofday2); 
      drawLabel( wR5LineStr,R5,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wR4", R4, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(wR4LineStr,R4,PivotLabels_Color,S,startofday,startofday2);       
      drawLine("wS4", S4, Support_Pivots_Color,startofday,startofday2);
      drawLabel(wS4LineStr,S4,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wS5", S5, Support_Pivots_Color,startofday,startofday2);
      drawLabel(wS5LineStr ,S5,PivotLabels_Color,S,startofday,startofday2);}

      if(Show_Weekly_MidPivots) { 
      drawLine("wMR3", (R2+R3)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"R3",(R2+R3)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wMR2", (R1+R2)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"R2",(R1+R2)/2,PivotLabels_Color,S,startofday,startofday2); 
      drawLine("wMR1", (Pivot+R1)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"R1",(Pivot+R1)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wMS1", (Pivot+S1)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"S1",(Pivot+S1)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wMS2", (S1+S2)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"S2",(S1+S2)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wMS3", (S2+S3)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"S3",(S2+S3)/2,PivotLabels_Color,S,startofday,startofday2);
         
      if(WeeklyPivots_Day_Formula==false){
      drawLine("wMR5", (R4+R5)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"R5",(R4+R5)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wMR4", (R3+R4)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"R4",(R3+R4)/2,PivotLabels_Color,S,startofday,startofday2);                 
      drawLine("wMS4", (S3+S4)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"S4",(S3+S4)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("wMS5", (S4+S5)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(wmrLineStr+"S5",(S4+S5)/2,PivotLabels_Color,S,startofday,startofday2);} }
      }

   //Do Monthly Pivots------------------------------------------------------------------------- 
   if (MonthlyPivots_Shown)
      {    
   	string mpLineStr,mpStr,mp;
   	string ms1Str,mS1LineStr,ms1,mr1Str,mR1LineStr,mr1;
   	string ms2Str,mS2LineStr,ms2,mr2Str,mR2LineStr,mr2; 
   	string ms3Str,mS3LineStr,ms3,mr3Str,mR3LineStr,mr3;
   	string ms4Str,mS4LineStr,ms4,mr4Str,mR4LineStr,mr4;
   	string ms5Str,mS5LineStr,ms5,mr5Str,mR5LineStr,mr5;
   	string mmrLineStr; S=2;
  
      if (MonthlyPivots_Day_Formula)
         {
         mpLineStr  = "    MPV"; //removed a space
         mS1LineStr = "    MS1";
         mR1LineStr = "    MR1";
         mS2LineStr = "    MS2";
         mR2LineStr = "    MR2";
         mS3LineStr = "    MS3";
         mR3LineStr = "    MR3";
         mmrLineStr = " Mm";           
         }        
      else   
         {
         mpLineStr  = "  MFPV";
         mS1LineStr = "  MFS1";
         mR1LineStr = "  MFR1";
         mS2LineStr = "  MFS2";
         mR2LineStr = "  MFR2";
         mS3LineStr = "  MFS3";
         mR3LineStr = "  MFR3";
         mS4LineStr = "  MFS4";
         mR4LineStr = "  MFR4";
         mS5LineStr = "  MFS5";
         mR5LineStr = "  MFR5";
         mmrLineStr = " Mm";
         }
         
      CalcPeriod = 43200;
      shift	= iBarShift(NULL,CalcPeriod,Time[0])+ 1;//default=one period ago
    
    	ClosePrice  = NormalizeDouble(iClose(NULL,CalcPeriod,shift),4);
      HiPrice     = NormalizeDouble (iHigh(NULL,CalcPeriod,shift),4); 
      LoPrice     = NormalizeDouble (iLow(NULL,CalcPeriod,shift),4);
      Range       = HiPrice -  LoPrice;
      Pivot       = NormalizeDouble((HiPrice+LoPrice+ClosePrice)/3,4);
      
      if (MonthlyPivots_Day_Formula)
         {
         R1 = (2*Pivot)-LoPrice;
         S1 = (2*Pivot)-HiPrice;
         R2 = Pivot+(R1-S1);
         S2 = Pivot-(R1-S1); 
         R3 = ( 2.0 * Pivot) + ( HiPrice - ( 2.0 * LoPrice ) );
         S3 = ( 2.0 * Pivot) - ( ( 2.0 * HiPrice ) - LoPrice );
         }
      else
         {   
         R1 = Pivot + (Range  * 0.382);
         S1 = Pivot - (Range  * 0.382); 
         R2 = Pivot + (Range  * 0.618);
         S2 = Pivot - (Range  * 0.618);
         R3 = Pivot +  Range ;  
         S3 = Pivot -  Range ;
         R4 = Pivot + (Range  * 1.618);
         S4 = Pivot - (Range  * 1.618);
         R5 = Pivot + (Range  * 2.618);
         S5 = Pivot - (Range  * 2.618);        
         } 

      drawLine("mR3", R3, Resistance_Pivots_Color,startofday,startofday2); 
      drawLabel(mR3LineStr,R3,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mR2", R2, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(mR2LineStr,R2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mR1", R1, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(mR1LineStr,R1,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mPIVOT", Pivot, MainPivot_Color,startofday,startofday2);
      drawLabel(mpLineStr, Pivot,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mS1", S1, Support_Pivots_Color,startofday,startofday2);
      drawLabel(mS1LineStr,S1,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mS2", S2, Support_Pivots_Color,startofday,startofday2);
      drawLabel(mS2LineStr,S2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mS3", S3, Support_Pivots_Color,startofday,startofday2);
      drawLabel(mS3LineStr ,S3,PivotLabels_Color,S,startofday,startofday2);
      
      if(MonthlyPivots_Day_Formula==false){
      drawLine("mR5", R5, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(mR5LineStr,R5,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mR4", R4, Resistance_Pivots_Color,startofday,startofday2);
      drawLabel(mR4LineStr,R4,PivotLabels_Color,S,startofday,startofday2);      
      drawLine("mS4", S4, Support_Pivots_Color,startofday,startofday2);
      drawLabel(mS4LineStr,S4,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mS5", S5, Support_Pivots_Color,startofday,startofday2);
      drawLabel(mS5LineStr ,S5,PivotLabels_Color,S,startofday,startofday2);}   
         
      if(Show_Monthly_MidPivots) {
      drawLine("mMR3", (R2+R3)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"R3",(R2+R3)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mMR2", (R1+R2)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"R2",(R1+R2)/2,PivotLabels_Color,S,startofday,startofday2); 
      drawLine("mMR1", (Pivot+R1)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"R1",(Pivot+R1)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mMS1", (Pivot+S1)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"S1",(Pivot+S1)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mMS2", (S1+S2)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"S2",(S1+S2)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mMS3", (S2+S3)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"S3",(S2+S3)/2,PivotLabels_Color,S,startofday,startofday2);
         
      if(MonthlyPivots_Day_Formula==false){ 
      drawLine("mMR5", (R4+R5)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"R5",(R4+R5)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mMR4", (R3+R4)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"R4",(R3+R4)/2,PivotLabels_Color,S,startofday,startofday2);                 
      drawLine("mMS4", (S3+S4)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"S4",(S3+S4)/2,PivotLabels_Color,S,startofday,startofday2);
      drawLine("mMS5", (S4+S5)/2, MidPivots_Color,startofday,startofday2); 
      drawLabel(mmrLineStr+"S5",(S4+S5)/2,PivotLabels_Color,S,startofday,startofday2);} }                  
      }               
   return(0);
   } 

//+-------------------------------------------------------------------------------------------+
//| drawLabel sub-routine to name and draw labels for the pivot lines                         |                                                        
//+-------------------------------------------------------------------------------------------+
void drawLabel(string text, double level, color Color, int kind, datetime startofday, datetime startofday2)
   {    
         if (StringSubstr(text,4,2)=="MP" || StringSubstr(text,4,2)=="MF"  && Show_Monthly_CentralPivot_Label==false) return (-1);   
   else {if (StringSubstr(text,4,2)=="MS" || StringSubstr(text,4,2)=="MR"  && Show_Monthly_MainPivot_Labels==false) return (-1);        
   else {if (StringSubstr(text,0,3)==" Mm"|| StringSubstr(text,0,3)==" Mm" && Show_Monthly_MidPivot_Labels==false) return (-1);      
   else {if (StringSubstr(text,4,2)=="WP" || StringSubstr(text,4,2)=="WF"  && Show_Weekly_CentralPivot_Label==false) return (-1);    
   else {if (StringSubstr(text,4,2)=="WS" || StringSubstr(text,4,2)=="WR"  && Show_Weekly_MainPivot_Labels==false) return (-1);           
   else {if (StringSubstr(text,0,2)=="Wm" || StringSubstr(text,0,2)=="Wm"  && Show_Weekly_MidPivot_Labels==false) return (-1); 
  
   else {              
   //Determine start position for labels & initiate needed variables
   int S2; if (kind == 1){S2= Shift_WeekLabels_PerCent_Left;}
   else {S2= Shift_MonthLabels_PerCent_Left;}
   if (S2 < 0)   {S2 =0;}
   if (S2 > 100) {S2 =100;}
   int L, LabelsShift = (WindowFirstVisibleBar()*S2)/100;
   
   //Initiate needed time variables
   int time, startday = Time[1]; 
   if (Time[0] > iTime(NULL, PERIOD_D1, 0)){startday = iTime(NULL, PERIOD_D1, 0);} 
     
   //Define name and content of the pivot line labels
   string plabel = "[TzPivotsMW] " + StringTrimLeft(text) + " Label";
   if (Use_For_Forex) {Price=DoubleToStr(level, fxDigits);}
   else {Price=DoubleToStr(level, Digits);}         
   if (Show_Price_in_PivotLabels && StrToInteger(text)==0) {text = text + "   " + Price;}     
           
   //Set tabs required for desired text alignment 
   string tab; 
   if (StartLines==1) L= 1;
   if (StartLines==2 && startday<=iTime(NULL,0,WindowFirstVisibleBar()) ) L= 1;
   if (L==1){
      time= Time[LabelsShift];
      if (Show_Price_in_PivotLabels){tab="                                ";}       //33, 32(v3.4)                    
      else {tab = "                ";}}                                             //17, 16(v3.4)                   
   else { 
      if (Show_Price_in_PivotLabels){tab="                             ";}          //30, 29(v3.4)
      else {tab = "             ";}                                                 //14, 13(v3.4)
      if (StartLines==2){time= startofday2;}
      else {time= Time[0];}}

   //Draw labels    
   if (ObjectFind(plabel) != 0){     
      ObjectCreate(plabel, OBJ_TEXT, 0, time, level);       
      ObjectSetText(plabel, tab+text, PivotLabels_Fontsize, PivotLabels_FontStyle, Color);
      ObjectSet(plabel, OBJPROP_BACK, false);
      if (PivotLabels_Subordinate) {ObjectSet(plabel, OBJPROP_BACK, true);}}
   else {ObjectMove(plabel, 0, time, level);} 
        }   }}}}}        
   }
   
//+-------------------------------------------------------------------------------------------+
//| drawLine sub-routine to name and draw pivot lines                                         |                                                        
//+-------------------------------------------------------------------------------------------+
void drawLine(string text, double level, color Color, datetime startofday, datetime startofday2)    
    {
    //Define line labels
    string pline1= "[TzPivotsMW] " + StringTrimLeft(text) + " Line historic";//Lines historic
    string pline2= "[TzPivotsMW] " + StringTrimLeft(text) + " Line today";//Lines today zone  
    string pline3= "[TzPivotsMW] " + StringTrimLeft(text) + " Line full screen";//Lines fullscreen Y=1,F=true and HLINE
    
    //Define line configuration variables       
    int a = Prior\FScr_LineStyle_01234 ;
    int b = Prior\FScr_SolidLineThickness ;
    int c =1; if (a==0)c=b;        
    int u = CurrentDay_LineStyle_01234;
    int v = CurrentDay_SolidLineThickness;
    int w =1; if (u==0)w=v;    
    int Y,Z= OBJ_TREND, F= true; //F=true=extend line as ray line      
    int startline1, stopline1, startline2, stopline2, startline3, stopline3;
    
    //Define needed time variables
    int startline, startday = Time[1];    
    if (Time[0] > iTime(NULL, PERIOD_D1, 0)){startday = iTime(NULL, PERIOD_D1, 0);}  
    
    //Define other varibles needed to create/move lines    
    if(StartLines == 1)
       { 
       if(FScr_With_Dual_Configuration) {Y=0; Z= OBJ_TREND; F=true;}
       else {{Y=1; Z=OBJ_HLINE; F= false;}
          if(!Show_RightMargin_Prices || StopLines_At_Current_Candle) {Z = OBJ_TREND; F=true;}}
       }                           
    if (StartLines == 2) {Y= 2; Z= OBJ_TREND; F= true; startline= startofday2;}   
    if (StartLines == 3) {Y= 2; Z= OBJ_TREND; F= true; startline= Time[1];}       
    if (StopLines_At_Current_Candle) {Z= OBJ_TREND; F= false;}
               
    //Draw lines  
    if(Y==0){
       if(ObjectFind(pline1) != 0){        
          ObjectCreate(pline1, Z, 0, startofday, level, WindowFirstVisibleBar(), level);                            
          ObjectSet(pline1, OBJPROP_STYLE, a);              
          ObjectSet(pline1, OBJPROP_WIDTH, c); 
          ObjectSet(pline1, OBJPROP_COLOR, Color);
          ObjectSet(pline1, OBJPROP_BACK, true);}     
       if(ObjectFind(pline2) != 0){        
          ObjectCreate(pline2, Z, 0, startofday2, level, Time[0], level);                   
          ObjectSet(pline2, OBJPROP_STYLE, u);              
          ObjectSet(pline2, OBJPROP_WIDTH, v); 
          ObjectSet(pline2, OBJPROP_COLOR, Color);
          ObjectSet(pline2, OBJPROP_BACK, true); 
          ObjectSet(pline2, OBJPROP_RAY, F);} }                
    else {if(Y==1){
       if(ObjectFind(pline3) != 0){        
          ObjectCreate(pline3, Z, 0, WindowFirstVisibleBar(), level, Time[0], level);                            
          ObjectSet(pline3, OBJPROP_STYLE, a);              
          ObjectSet(pline3, OBJPROP_WIDTH, c); 
          ObjectSet(pline3, OBJPROP_COLOR, Color);
          ObjectSet(pline3, OBJPROP_BACK, true); 
          ObjectSet(pline3, OBJPROP_RAY, F);}}
    else {if(Y==2){
       if(ObjectFind(pline2) != 0){        
          ObjectCreate(pline2, Z, 0, startline, level, Time[0], level);                   
          ObjectSet(pline2, OBJPROP_STYLE, u);              
          ObjectSet(pline2, OBJPROP_WIDTH, v); 
          ObjectSet(pline2, OBJPROP_COLOR, Color);
          ObjectSet(pline2, OBJPROP_BACK, true); 
          ObjectSet(pline2, OBJPROP_RAY, F);}} 
            
    //Move lines          
    else{      
       if(Y==0){     
          ObjectMove  (pline1, 0, startofday,level);
          ObjectMove  (pline1, 1, WindowFirstVisibleBar(), level);  
          ObjectMove  (pline2, 0, startofday2,level);                               
          ObjectMove  (pline2, 1, Time[0], level);}     
    else {if(Y==1){ 
          ObjectMove  (pline3, 0, WindowFirstVisibleBar(),level);
          ObjectMove  (pline3, 1, Time[0], level);} 
    else {if(Y==2){
          ObjectMove  (pline2, 0, startline,level);                               
          ObjectMove  (pline2, 1, Time[0], level);}}   }}}}                           
    }
    
//+-------------------------------------------------------------------------------------------+
//| TzShift sub-routine computes index of first bar of today                                  |                                                        
//+-------------------------------------------------------------------------------------------+
void TzShift(int tzServer, int tzChoice, int &idxfirstbaroftoday)   
   {     
   int tzdiff= tzServer - tzChoice,
       tzdiffsec= tzdiff*3600,
       barsperday= (1440/PERIOD_H1);   
   int dayofweektoday= TimeDayOfWeek(iTime(NULL, PERIOD_H1, 0) - tzdiffsec),
       dayofweektofind= -1; 

   idxfirstbaroftoday= 0;
       
   switch (dayofweektoday)
      {
      case 6: // sat
      case 0: // sun
      case 1: dayofweektofind= 5; break; // mon          
      default: dayofweektofind= dayofweektoday -1; break;
      }
   for (int i=1; i<=barsperday + 1; i++)  
      {
      datetime timet= iTime(NULL, PERIOD_H1, i) - tzdiffsec;
      if (TimeDayOfWeek(timet)!=dayofweektoday) {idxfirstbaroftoday= i-1; 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                                                                               |                                                        
//+-------------------------------------------------------------------------------------------+

Recommend