//+------------------------------------------------------------------+ //| SDK-Pivots-v1.2.mq4 | //| | //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2011, f451" #property link "" //#property strict /*------------------------------------------------------------------------------------ Introduction: Time-Zone Inputs: LocalTimeZone: TimeZone for which MT4 shows your local time, e.g. 1 or 2 for Europe (GMT+1 or GMT+2 (daylight savings time). Use zero for no adjustment. The MetaQuotes demo server uses GMT +2. DestTimeZone: TimeZone for the session from which to calculate the levels (e.g. 1 or 2 for the European session (without or with daylight savings time). Use zero for GMT Example: If your MT server is living in the EST (Eastern Standard Time, GMT-5) zone and want to calculate the levels for the London trading session (European time in summer GMT+1), then enter -5 for LocalTimeZone, 1 for Dest TimeZone. Please understand that the LocalTimeZone setting depends on the time on your MetaTrader charts (for example the demo server from MetaQuotes always lives in CDT (+2) or CET (+1), no matter what the clock on your wall says. If in doubt, leave everything to zero. --------------------------------------------------------------------------------------- SDK-Pivots-v1.2: This version is the combination and culmination of all stages of revision/upgrade subsequent to the original SDX-TzPivots released by Shimodax, plus modifications to align the expanded Floor Pivot and Camarilla calculations to those described by Frank Ochoa in his book "Secrets of a Pivot Boss". It also includes a very significant new feature - the indicator now shows the central pivot range going back the number of days specified for the the user. These multi day pivot relationships (in particular) the most recent two days - when combined with the opening price give you a view of the market type today. For more information see Frabk Ochoa's book. In the original, you could display both Daily pivots and Fib pivots, but the Fibs were not per standard formula. You could display mid-pivots, Yesterday H/L, todays Open, Camarilla and SweetSpots. Line style and colors were hard coded, meaning if you wanted to change line styles here and there, or colors, you had to change them in the code and re-complile the indicator. In this area, a lot has been added. Of all the original functions intended, only SweetSpots is eliminated, as Shimodax has created a separate and better SDX-SweetSpots indicator. This _v1.2 upgrade provides for full customization of all lines and labels....color, style, thickness, font style, font size. Period Separator lines can be displayed, or not. Their display can be at the top or bottom of the screen, eliminating some congestion. Their labels can be displayed, or not. Additional cosmetic changes include label changes, and better label positioning and justification to improve the overall look. Additional comments regarding some of the many Indicator Window inputs: Local_HrsServerTzFromGMT: Enter the number of hours difference between GMT and the time zone your platform server is in. MT4 demo servers are GMT +2 hrs. Use default value "0" for normal, non-time shifted pivot calculations. Dest_HrsNewTZfromGMT: Enter the number of hours difference between GMT and the new time zone you are selecting as the basis for pivots calculations. For example, if you wish to have the day start at NY time, then enter "-5". If you wish to have the day start at Zurich time, then enter "1". Use the default value of "0" for normal, non-time shifted pivot calculations. Show_1Daily_2FibonacciPivots: Either formula can be used to produce the main pivot line FullScreenLinesMarginPrices: "true" displays lines across entire screen with prices in the right margin. "false" displays lines starting at the "Today" Period Separator and which do not have margin labels. For these lines, you will want to add labels. MoveLabels_LR_DecrIncr: Increasing the number moves the line labels to the right on the chart. Decreasing the number moves the line labels to the left on the chart. This feature is absent in the original indicator. It is for the "FullLinesMarginPrices = true" mode, to relocate line ID labels. It also is used in the "FullLinesMarginPrices = false" mode once the Relabeler code takes over and is producing full screen lines. Color Choices for lines and labels: Enter the colors of your choice. LineStyle_01234: Your number entry selects the line style for the lines. 0=solid, 1=dash, 2=dashdot, 3=dashdot, and 4=dashdotdot. SolidLineThickness: Your number entry selects the width of solid lines. 0 and 1 = single width. 2, 3, 4 graduate the thickness. Coding assures that no matter what number this is set at, non-solid line styles selected will still display without having to change this entry back to 0, or 1. _Label_Norm_Bold_Black_123: Entry of "1" produces Arial. Entry of "2" produces Arial Bold. And an entry of "3" produces Arial Black font style. ShowPeriodSeparatorLines: The choice of "true" will place a pair of vertical lines on the chart showing the start and stop of the new "Destination" 24 hour period you have selected for pivot calculations. Choosing "false" cancels display of these lines and their "Yesterday" and "Today" labels. PlaceAt_TopBot_12_OfChart: "1" will place the Period Separator labels "Yesterday" and "Today" at the top of the screen. "2" will place them at the bottom. The charts are less congested. If the screen is enlarged, downsized, or scrolled, these labels will move. But the next data tick restores their position. LineLabelsIncludePrice: Line labels have IDs such as R#, PV, or S#, but selecting "true" will add the price anytime you have these labels on the chart. Relabeler_Adjustment: This number is used in the FullScreenLinesMarginPrices = "false" mode to trigger when the relabeler puts labels on the screen. It works under the assumption that the Today Period Separator is soon to go off-screen, taking the labels with it. The ideal number would trigger the relabeler when the first labels are about to move off the left of the chart. Lowering the number triggers sooner and raising it delays triggering. The number is the number of candles between the Today Separator and the chart left border. For example, a value of "10" will trigger the relabeler when the Today Period Separator is 10 candles from the chart left border. A value of "0" triggers when the Today Period Separator hits the left border. This feature allows for fine tuning charts of different scales and timeframes. In most cases either of the example values is sufficient. If the chart timeframe and scale is such that full sessions are displayed without the Today Separator ever disappearing, then relabeling and this adjustment to it, will not be required. It only comes into play when the scale is such that the Today Period Separator will move off the left of the screen, taking the labels with it, before the next session Separators can come on-screen. Scaling down to make larger candles causes more timeframes to require this feature, The coding takes this into account and use of this adjustment is really only for fine tuning whenever the user desires to do so. Show_Relabeler_Comment: If "true" then Relabeler related data appears in chart upper left. It serves to help a new user better understand the Relabeler. Show_Data_Comment: If "true" then key prior/current day pip data appears in chart upper left. - Traderathome, December 20, 2008 ---------------------------------------------------------------------------------- v4.2: Modified code controlling mid-screen placement of line labels when full screen lines are shown. Now mid-screen label placement is automatic when zooming in and out on the charts. - Traderathome, February 1, 2009 ---------------------------------------------------------------------------------- v4.3: Modified code for Period Separator labels so that instead of just showing "Yesterday" and "Today", these are now replaced with the actual name of the Day and include the time zone shift from GMT selected by the user. When the original selection for full screen lines is "false", after time on small timeframe charts, like M1 and M5, lines become full screen by necessity. However, when a new day starts, the old lines are cleared and the new lines are again not full screen. - Traderathome, March 14, 2009 --------------------------------------------------------------------------------- v4.4: For simpicity, grouped the main support lines and the main resistance lines, so far as the selection of color, style and width. v4.7: Added "ZoomAdjust" window input.... bit difficult to explain, but I'll try. For the line labels displayed to the left of the current Period Separator, keeping neat spacing from the Separator line is difficult in that some things "upset the apple cart". Adding prices to the labels can necessitate label shifting. Zooming the chart in or out can necessitate label shifting. Even increasing or decreasing the font size, or changing the font style can necessitate label shifting. And this group of labels needs to be shifted independent from the rest of the labels. The "ZoomAdjust" allows the user to input a number to move those labels to a neater location relative to the Separator, once the chart zoom has been made, and the selection of whether or not prices are included has been made, and the choices of font size and style have been made. The "ZoomAdjust_3_6_15_30_50" numbers are there to suggest the range that may be necessary. If prices are included, and if a large font and the "3" style are selected, you may need to input a large number to move the labels far enough away from the Separator to keep the labels from overlapping it. An even larger number may be required if the chart is then zoomed out even more. You will have to experiment with it to get the hang of it. You can simply ignore it, too, and just not use it. But, if you set up a chart that will be around a while, and you want things nice on it, this is a useful addition. - Traderathome, March 27, 2009 ---------------------------------------------------------------------------------- v4.7.1: Corrects previous failure to deinitialize when "turned off". - Traderathome, April 05, 2009 ---------------------------------------------------------------------------------- v4.7.2: Altered code so all items displayed except for the Period Separators and Separator Labels go into the background relative to other charting items. This prevents the annoying breakup of other chart study lines. - Traderathome, April 11, 2009 -------------------------------------------------------------------------------- v1.0-SDK: Reworked the floor pivot and Camarilla pivot calculations to align with the expanded formulas described by Frank Ochoa in his book "Secrets of a Pivot Boss". Removed the quarter pivots option, and added a switch to show or not show the inner Camarillas (S1,S2, R1,R2) which are relevant only during tight ranges. Added the Top and Bottom of the Central Pivot Range (tc, bc) which are used to show pivot range width and describe two day pivot relationships. - f451, October 6, 2011 v1.2-SDK: Extended calculation and display of the pivot and central pivot range going back a number of days as specified by the user. 2 days is the minimum required to see the 2-day pivot relationship. - f451, October 10, 2011 SDK-Pivots-v1.3 altered code so that the indicator can now show historical Pivots etc - CJA October 15 2013 SDK-Pivots-nmc altered to run on the new MT4 600 builds. - CJA June 27 2014 --------------------------------------------------------------------------------*/ #property indicator_chart_window extern bool Indicator_On = true; extern int Days = 5; // number of Days back to calculate pivots. extern int Local_HrsServerTzFromGMT = 0; //Data collection Tz of your server extern int Dest_HrsNewTZfromGMT = 0; //New destination Tz governing data extern int Show_1Daily_2FibonacciPivots = 1; extern bool withMarginPrices = true; extern bool LineLabelsIncludePrice = true; extern int MoveLabels_LR_DecrIncr = 0; //-# to move left, +# to move right extern int PercentageOffset = 25; //-# to move left, +# to move right extern color PivotLinesLabelColor = Gray; extern int LineLabelsFontSize = 8; extern int L_Label_Norm_Bold_Black_123 = 2; extern int ZoomAdjust_3_6_15_30_50 = 20; //for 8,9 fontsize: 2, 5, 10, 20, 40 extern color R_Color = CornflowerBlue; extern int R_LineStyle_01234 = 2; extern int R_SolidLineThickness = 1; extern color CentralPivotColor = PaleGoldenrod; extern int CentralPivotLineStyle_01234 = 0; extern int CentralPivotSolidLineThickness = 1; extern color C_Color = Yellow; extern int C_LineStyle_01234 = 0; extern int C_SolidLineThickness = 2; extern bool ShowTwoDayPivots = false; extern color S_Color = Crimson; extern int S_LineStyle_01234 = 2; extern int S_SolidLineThickness = 1; extern color MidPivotsColor = Gray; extern int MidPivotsLineStyle_01234 = 2; extern int MidPivotsLineThickness = 1; extern bool ShowMidPivots = false; extern color YesterdayHighLowColor = BurlyWood; extern int HighLowLineStyle_01234 = 2; extern int HighLowSolidLineThickness = 1; extern bool ShowYesterdayHighLow = true; extern color TodayOpenColor = DarkOliveGreen; extern int TodayOpenLineStyle_01234 = 0; extern int TodayOpenSolidLineThickness = 1; extern bool ShowTodayOpen = true; extern color CamarillaHiColor = LightSkyBlue; extern color CamarillaLoColor = IndianRed; extern int CamarillaLineStyle_01234 = 0; extern int CamarillaSolidLineThickness = 1; extern bool ShowCamarilla = false; extern bool ShowInnerCamarillas = false; extern color PeriodSeparatorLinesColor = RosyBrown; extern int SeparatorLinesStyle_01234 = 2; extern int SeparatorLinesThickness = 1; extern bool ShowPeriodSeparatorLines = true; extern color PeriodSeparatorsLabelsColor = DarkGray; extern int PlaceAt_TopBot_12_OfChart = 2; extern int SeparatorLabelFontSize = 8; extern int S_Label_Norm_Bold_Black_123 = 2; extern bool ShowPeriodSeparatorLabels = true; extern int Relabeler_Adjustment = 8; //-# to advance trigger, +# to delay trigger extern bool Show_Relabeler_Comment = false; extern bool Show_Data_Comment = true; int MoveLabels, MoveLabels2; int A,B; //relabeler triggers int digits; //decimal digits for symbol's price int offset; double pts; bool FullScreenLines = false; string ObjPivot = "[PIVOT]"; string ObjCamarilla = "[CAMARILLA]"; string ObjSeparator = "[TIME]"; string dayString[]; int idxfirstbar[]; int idxlastbar[]; double day_open[]; double day_close[]; double day_high[]; double day_low[]; double p[]; double bc[]; double tc[]; double cr5[]; double cr4[]; double cr3[]; double cr2[]; double cr1[]; double cs1[]; double cs2[]; double cs3[]; double cs4[]; double cs5[]; double r1[]; double r2[]; double r3[]; double r4[]; double r5[]; double s1[]; double s2[]; double s3[]; double s4[]; double s5[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { pts = MarketInfo( Symbol(), MODE_POINT ); if (Digits == 5 || (Digits == 3 && StringFind(Symbol(), "JPY") != -1)) { pts = Point*10; } else if (Digits == 6 || (Digits == 4 && StringFind(Symbol(), "JPY") != -1)) { pts = Point*100; } else { pts = Point; } if (Ask>10) digits=2; else digits=4; return(0); } //+------------------------------------------------------------------+ //| Custom indicator de-initialization function | //+------------------------------------------------------------------+ int deinit() { int obj_total= ObjectsTotal(); for (int i= obj_total; i>=0; i--) { string name= ObjectName(i); if ((StringSubstr(name,0,7)==ObjPivot) || (StringSubstr(name,0,11)==ObjCamarilla) || (StringSubstr(name,0,6)==ObjSeparator)) ObjectDelete(name); } Comment(" "); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { if (Indicator_On == false) {deinit();return(0);} if (Period() > PERIOD_H4) {deinit();return(0);} MoveLabels = (WindowFirstVisibleBar()/2)- MoveLabels_LR_DecrIncr; MoveLabels2= MoveLabels+ZoomAdjust_3_6_15_30_50; static datetime timelastupdate= 0; static datetime lasttimeframe= 0; datetime startofday= 0, startline= 0, endline=0, startlabel= 0; ArrayResize(dayString,Days+1); ArrayResize(day_open,Days+1); ArrayResize(day_close,Days+1); ArrayResize(day_high,Days+1); ArrayResize(day_low,Days+1); ArrayResize(p,Days+1); ArrayResize(bc,Days+1); ArrayResize(tc,Days+1); ArrayResize(idxfirstbar,Days+1);//cs4[idx] ArrayResize(idxlastbar,Days+1); ArrayResize(cr5,Days+1); ArrayResize(cs4,Days+1); ArrayResize(cr3,Days+1); ArrayResize(cr2,Days+1); ArrayResize(cr1,Days+1); ArrayResize(cs1,Days+1); ArrayResize(cs2,Days+1); ArrayResize(cs3,Days+1); ArrayResize(cs4,Days+1); ArrayResize(cs5,Days+1); ArrayResize(r1,Days+1); ArrayResize(r2,Days+1); ArrayResize(r3,Days+1); ArrayResize(r4,Days+1); ArrayResize(s1,Days+1); ArrayResize(s2,Days+1); ArrayResize(s3,Days+1); ArrayResize(s4,Days+1); ArrayResize(s5,Days+1); lasttimeframe= Period(); timelastupdate= CurTime(); //-----let's find out which bars mark the beginning and end going back the user specified days ----- ComputeDayIndices(Local_HrsServerTzFromGMT, Dest_HrsNewTZfromGMT, Days); GetOHLC(idxfirstbar,idxlastbar, day_open, day_high, day_low, day_close); // set label offset int PC = idxfirstbar[1]-idxlastbar[1]; //# of bars btwn day separators - use as offset offset = MathRound((PercentageOffset/100) * PC)-2; //----relabeler code-------------------------------------------------------------------------------------- A=0; B=0; //reset: relabeler off, margin labels off if (FullScreenLines == true && withMarginPrices == true) {B = 1;} //B=1 asserts margin labels if (FullScreenLines == true && withMarginPrices == false){B = 0;} //B=0 prevents margin labels if (FullScreenLines == false) { int AA = WindowFirstVisibleBar(); //# of visible bars on chart int BB = ( (Time[0]-Time[idxfirstbar[0]])/(Period()*60)); //# of bars btwn current time and first day separator int RR = (AA - BB); //# number of bars btwn first day Separator and chart left margin int AL = Relabeler_Adjustment; //default of zero activates relabeler as first day separator goes off-screen if (RR > AL){A = 0;} //labels not near enough to chart left margin to trigger relabeler if (RR <= AL){A = 1; if(withMarginPrices == true) B = 1;} //labels close enough - switch to full-screen } //----Autolabeler test comment string test = "A = "+A+", "; test = test + "Current time to Separator = "+BB+" candles."; test = test + " Separator to Chart left = "+RR+" candles."; test = test + " Total candles visable = "+AA+" candles."; test = test + " Relabeler is set to trigger when Separator is "+AL+" candles from chart left. \n"; test = test + " Number of candles between days = " + PC; if(Show_Relabeler_Comment ==true){Comment(test);} else {Comment (" ");} //----clear all objects before redrawing screen int obj_total= ObjectsTotal(); for (int x= obj_total; x>=0; x--) { string name= ObjectName(x); if((StringSubstr(name,0,7)==ObjPivot) || (StringSubstr(name,0,11)==ObjCamarilla) || (StringSubstr(name,0,6)==ObjSeparator)) ObjectDelete(name); } //------draw the vertical bars/labels that mark the session spans------------------------------------------ if(ShowPeriodSeparatorLines == true) { int DZ = Dest_HrsNewTZfromGMT; string GMT = "(GMT +0) "; if(DZ>0 && DZ<10) {GMT = "(GMT +"+ Dest_HrsNewTZfromGMT +") ";} if(DZ>9) {GMT = "(GMT +"+ Dest_HrsNewTZfromGMT +")";} if(DZ<0 && DZ>-10) {GMT = "(GMT +"+ Dest_HrsNewTZfromGMT +") ";} if(DZ<-9) GMT = "(GMT "+ Dest_HrsNewTZfromGMT +")"; if(SeparatorLinesStyle_01234>0) {SeparatorLinesThickness=1;} double top = WindowPriceMax(); double bottom = WindowPriceMin(); double scale = top - bottom; double YadjustTop = scale/5000; //250; double YadjustBot = scale/(350/SeparatorLabelFontSize); double level = top - YadjustTop; if (PlaceAt_TopBot_12_OfChart==2){level = bottom + YadjustBot;} for (int dy = 0; dy < Days; dy++) { SetTimeLine("Day "+DoubleToStr(dy,0), dayString[dy] + GMT, idxfirstbar[dy]+0, PeriodSeparatorsLabelsColor, level); } } //---- Calculate Pivot Levels ------------------------------------------------------------------------------- // TODO: generalise all pivot calcs at some point double q, d; for (int idx = 1; idx <= Days; idx++) { d = (day_high[0] - day_low[0]); q = (day_high[idx] - day_low[idx]); // RANGE // calculate pivots going back as many days as specified p[idx] = (day_high[idx] + day_low[idx] + day_close[idx]) / 3; bc[idx] = (day_high[idx] + day_low[idx])/2; tc[idx] = 2*p[idx] - bc[idx]; if(day_low[idx]==0)cr5[idx] = 0; if(day_low[idx]!=0)cr5[idx] = (day_high[idx]/day_low[idx])*day_close[idx]; cr4[idx] = (q*0.55)+day_close[idx]; cr3[idx] = (q*0.275)+day_close[idx]; cr2[idx] = (q*0.1833)+day_close[idx]; cr1[idx] = (q*0.09167)+day_close[idx]; cs1[idx] = day_close[idx]-(q*0.09167); cs2[idx] = day_close[idx]-(q*0.1833); cs3[idx] = day_close[idx]-(q*0.275); cs4[idx] = day_close[idx]-(q*0.55); cs5[idx] = day_close[idx]-(cr5[idx]-day_close[idx]); if (bc[idx] > tc[idx]) { double temp = bc[idx]; bc[idx] = tc[idx]; tc[idx] = temp; } } if(Show_1Daily_2FibonacciPivots == 1) { for (idx = 1; idx <= Days; idx++) { q = (day_high[idx] - day_low[idx]); r1[idx] = (2*p[idx])-day_low[idx]; r2[idx] = p[idx]+(day_high[idx] - day_low[idx]); //r2 = p-s1+r1; r3[idx] = (2*p[idx])+(day_high[idx]-(2*day_low[idx])); // r3 = r1 + (day_high[1] - yersterday_low); r4[idx] = r3[idx] + (r2[idx] - r1[idx]); s1[idx] = (2*p[idx])-day_high[idx]; s2[idx] = p[idx]-(day_high[idx] - day_low[idx]); //s2 = p-r1+s1; s3[idx] = (2*p[idx])-day_high[idx] - (day_high[idx]-day_low[idx]); // s3 = s1 - (day_high[1] - day_low[1]); s4[idx] = s3[idx] - (s1[idx]-s2[idx]); }} if(Show_1Daily_2FibonacciPivots == 2) { for (idx = 1; idx <= Days; idx++) { q = (day_high[idx] - day_low[idx]); r1[idx] = p[idx] + (q * 0.382); r2[idx] = p[idx] + (q * 0.618); r3[idx] = p[idx] + q; r4[idx] = p[idx] + (q * 1.618); r5[idx] = p[idx] + (q * 2.618); s2[idx] = p[idx] - (q * 0.618); s1[idx] = p[idx] - (q * 0.382); s3[idx] = p[idx] - q; s4[idx] = p[idx] - (q * 1.618); s5[idx] = p[idx] - (q * 2.618); }} if(FullScreenLines==false&&A==0) //lines start at separators, no margin labels in this mode { startlabel= Time[idxfirstbar[0]+offset]; startline = Time[idxfirstbar[0]+1]; //was "+1", "+0" stops line at Separator if (Time[0] > Time[idxfirstbar[0]]){startline = Time[idxfirstbar[0]];} } if(FullScreenLines==false&&A==1) //lines started at separators, but switched to full screen, value of B governs margin labels { startlabel= Time[MoveLabels]+offset; startline = WindowFirstVisibleBar(); } if(FullScreenLines==true) //lines selected to be full screen, margin labels governed by value of B in relabeler code { startlabel=Time[MoveLabels]+offset; startline = WindowFirstVisibleBar(); } for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; if(R_LineStyle_01234>0){R_SolidLineThickness=0;} if(S_LineStyle_01234>0){S_SolidLineThickness=0;} if(C_LineStyle_01234>0){S_SolidLineThickness=0;} SetLevel(" R5 ["+DoubleToStr(idx,0)+"] ", r5[idx], R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R4 ["+DoubleToStr(idx,0)+"] ", r4[idx], R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R3 ["+DoubleToStr(idx,0)+"] ", r3[idx], R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R2 ["+DoubleToStr(idx,0)+"] ", r2[idx], R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R1 ["+DoubleToStr(idx,0)+"] ", r1[idx], R_Color, R_LineStyle_01234, R_SolidLineThickness, startline, startlabel, 0, endline); if (ShowTwoDayPivots) { SetLevel(" BC ["+DoubleToStr(idx,0)+"] ", bc[idx], C_Color, C_LineStyle_01234, C_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" TC ["+DoubleToStr(idx,0)+"] ", tc[idx], C_Color, C_LineStyle_01234, C_SolidLineThickness, startline, startlabel, 0, endline); }} if(Show_1Daily_2FibonacciPivots == 1) { for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; SetLevel(" PV ["+DoubleToStr(idx,0)+"] ", p[idx], CentralPivotColor, CentralPivotLineStyle_01234 , CentralPivotSolidLineThickness, startline, startlabel, 0, endline); }} if(Show_1Daily_2FibonacciPivots == 2) { for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; SetLevel(" FPV ["+DoubleToStr(idx,0)+"] ", p[idx], CentralPivotColor, CentralPivotLineStyle_01234 , CentralPivotSolidLineThickness, startline, startlabel, 0, endline); }} for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; SetLevel(" S1 ["+DoubleToStr(idx,0)+"] ", s1[idx], S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S2 ["+DoubleToStr(idx,0)+"] ", s2[idx], S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S3 ["+DoubleToStr(idx,0)+"] ", s3[idx], S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S4 ["+DoubleToStr(idx,0)+"] ", s4[idx], S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S5 ["+DoubleToStr(idx,0)+"] ", s5[idx], S_Color, S_LineStyle_01234, S_SolidLineThickness, startline, startlabel, 0, endline); } //----- Camarilla Lines if (ShowCamarilla==true) { if(CamarillaLineStyle_01234>0){CamarillaSolidLineThickness=0;} if (ShowInnerCamarillas) { for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; SetLevel(" R1c ["+DoubleToStr(idx,0)+"] ", cr1[idx], CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R2c ["+DoubleToStr(idx,0)+"] ", cr2[idx], CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S1c ["+DoubleToStr(idx,0)+"] ", cs1[idx], CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S2c ["+DoubleToStr(idx,0)+"] ", cs2[idx], CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); } } for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; SetLevel(" R3c ["+DoubleToStr(idx,0)+"] ", cr3[idx], CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R4c ["+DoubleToStr(idx,0)+"] ", cr4[idx], CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" R5c ["+DoubleToStr(idx,0)+"] ", cr5[idx], CamarillaLoColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S3c ["+DoubleToStr(idx,0)+"] ", cs3[idx], CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S4c ["+DoubleToStr(idx,0)+"] ", cs4[idx], CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" S5c ["+DoubleToStr(idx,0)+"] ", cs5[idx], CamarillaHiColor, CamarillaLineStyle_01234, CamarillaSolidLineThickness, startline, startlabel, 0, endline); } } //------ Midpoints Pivots (mid-levels between pivots) if (ShowMidPivots==true) { if(FullScreenLines==false&&A==0) { startlabel= Time[idxfirstbar[0]+offset]; startline = Time[idxfirstbar[0]+1]; //was "+1", "+0" stops line at Separator if (Time[0] > Time[idxfirstbar[0]]){startline = Time[idxfirstbar[0]];} } if(FullScreenLines==false&&A==1) { startlabel= Time[MoveLabels]+offset; startline = WindowFirstVisibleBar(); } if(FullScreenLines==true) { startlabel=Time[MoveLabels]+offset; startline = WindowFirstVisibleBar(); } if(MidPivotsLineStyle_01234>0){MidPivotsLineThickness=0;} for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-1+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; SetLevel(" mR5 ["+DoubleToStr(idx,0)+"] ", (r4[idx]+r5[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mR4 ["+DoubleToStr(idx,0)+"] ", (r3[idx]+r4[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mR3 ["+DoubleToStr(idx,0)+"] ", (r2[idx]+r3[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mR2 ["+DoubleToStr(idx,0)+"] ", (r1[idx]+r2[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mR1 ["+DoubleToStr(idx,0)+"] ", (p[idx]+r1[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mS1 ["+DoubleToStr(idx,0)+"] ", (p[idx]+s1[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mS2 ["+DoubleToStr(idx,0)+"] ", (s1[idx]+s2[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mS3 ["+DoubleToStr(idx,0)+"] ", (s2[idx]+s3[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mS4 ["+DoubleToStr(idx,0)+"] ", (s3[idx]+s4[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); SetLevel(" mS5 ["+DoubleToStr(idx,0)+"] ", (s4[idx]+s5[idx])/2, MidPivotsColor, MidPivotsLineStyle_01234, MidPivotsLineThickness, startline, startlabel, 0, endline); } } //---- Yesterday High/Low if (ShowYesterdayHighLow == true) { for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-3+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; if(HighLowLineStyle_01234>0){HighLowSolidLineThickness=0;} SetLevel(" yHigh ["+DoubleToStr(idx,0)+"] ",day_high[idx],YesterdayHighLowColor,HighLowLineStyle_01234, HighLowSolidLineThickness, startline, startlabel, 0, endline); SetLevel(" yLow ["+DoubleToStr(idx,0)+"] ",day_low[idx],YesterdayHighLowColor,HighLowLineStyle_01234, HighLowSolidLineThickness, startline, startlabel, 0, endline); }} //---- Today Open if (ShowTodayOpen == true) { if(FullScreenLines==false&&A==0) { startlabel= Time[idxfirstbar[0]+1+ZoomAdjust_3_6_15_30_50]; startline = Time[idxfirstbar[0]+1+ZoomAdjust_3_6_15_30_50]; //was "+1", "+0" stops line at Separator } if(FullScreenLines==false&&A==1) { startlabel= Time[MoveLabels2]; startline = WindowFirstVisibleBar(); } if(FullScreenLines==true) { startlabel=Time[MoveLabels2]; startline = WindowFirstVisibleBar(); } for ( idx = 1; idx <= Days; idx++) { startlabel= Time[idxlastbar[idx]-3+offset]; startline = Time[idxlastbar[idx]-1]; //was "+1", "+0" stops line at Separator endline = Time[idxlastbar[idx-1]-1]; if(TodayOpenLineStyle_01234>0){TodayOpenSolidLineThickness=0;} SetLevel(" Open ["+DoubleToStr(idx,0)+"] ", day_open[idx-1],TodayOpenColor,TodayOpenLineStyle_01234, TodayOpenSolidLineThickness, startline, startlabel, 0, endline); }} //------ Comment for upper left corner if (Show_Data_Comment) { string comment= "\n"; comment= comment + "Range: Yesterday "+DoubleToStr(MathRound(q/pts),0) +" pips, Today "+DoubleToStr(MathRound(d/pts),0)+" pips" + "\n"; comment= comment + "Highs: Yesterday "+DoubleToStr(day_high[1],Digits) +", Today "+DoubleToStr(day_high[0],Digits) +"\n"; comment= comment + "Lows: Yesterday "+DoubleToStr(day_low[1],Digits) +", Today "+DoubleToStr(day_low[0],Digits) +"\n"; comment= comment + "Close: Yesterday "+DoubleToStr(day_close[1],Digits) + "\n"; comment= comment + "Pivot: Yesterday " + DoubleToStr(p[2],Digits) + " Today " + DoubleToStr(p[1],Digits) + "\n"; comment= comment + "Central Pivot Range: Yesterday " + DoubleToStr(MathRound((tc[2]-bc[2])/pts),0)+" pips, Today " + DoubleToStr(MathRound((tc[1]-bc[1])/pts),0)+" pips" + "\n"; comment= comment + "Fibos: 38.2% " + DoubleToStr(day_low[1] + q*0.382, Digits) + ", " + DoubleToStr(day_high[1] - q*0.382,Digits) + "\n"; comment= comment + "Fibos: 61.8% " + DoubleToStr(day_low[1] + q*0.618, Digits) + ", " + DoubleToStr(day_high[1] - q*0.618,Digits) + "\n"; Comment(comment); } return(0); } //+-------------------------------------------------------------------------------------+ //| Get Open, High, Low, Close of the day | //+-------------------------------------------------------------------------------------+ void GetOHLC(int &idxfirstbar2[], int &idxlastbar2[], double &open[], double &high[], double &low[], double &close[]) { //------walk forward through user specificed number of days and collect high/lows within the day------------------------------ for (int d = 0; d <= Days; d++) { high[d] = -99999; // not high enough to remain alltime high low[d] = +99999; // not low enough to remain alltime low for (int k = idxfirstbar2[d]; k>=idxlastbar2[d]; k--) { if (open[d]==0) // grab first value for open open[d]= Open[k]; high[d]= MathMax(High[k], high[d]); low[d]= MathMin(Low[k], low[d]); // overwrite close in loop until we leave with the last iteration's value close[d]= Close[k]; } } } //+-------------------------------------------------------------------------------------+ //| Compute index of first/last bar of Yesterday and today | //+-------------------------------------------------------------------------------------+ void ComputeDayIndices(int tzlocal, int tzdest, int days) { int tzdiff= tzlocal - tzdest, tzdiffsec= tzdiff*3600, dayminutes= 24 * 60, barsperday= dayminutes/Period(); int dayofweek= TimeDayOfWeek(Time[0] - tzdiffsec), // what day is today in the dest timezone? 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 idxfirstbar[0]= 0; for (int z = 0; z <= days; z++) { switch (dayofweek) { case 6: // sat case 0: // sun case 1: // mon dayofweektofind = 5; // Yesterday in terms of trading was previous friday break; default: dayofweektofind = dayofweek -1; break; } //----search backwards for the last occurrence (backwards) of the day today (today's first bar)----------- for (int i=(z*barsperday)+1; i<=(z+1)*barsperday+1; i++) { datetime timec= Time[i] - tzdiffsec; if (TimeDayOfWeek(timec)!=dayofweek) { idxfirstbar[z]= i-1; idxlastbar[z+1] = i; break; } } if (dayofweektofind == 1) { dayString[z+1] = " Monday "; dayString[z] = " Tuesday ";} if (dayofweektofind == 2) { dayString[z+1] = " Tuesday "; dayString[z] = "Wednesday ";} if (dayofweektofind == 3) { dayString[z+1] = "Wednesday "; dayString[z] = " Thursday ";} if (dayofweektofind == 4) { dayString[z+1] = " Thursday "; dayString[z] = " Friday ";} if (dayofweektofind == 5) { dayString[z+1] = " Friday "; dayString[z] = " Monday ";} dayofweek = dayofweektofind; } } //+-----------------------------------------------------------------------------------------+ //| Helper sub-routine that creates lines and their labels | | //+-----------------------------------------------------------------------------------------+ void SetLevel(string text, double level, color col1, int linestyle, int thickness, datetime startline, datetime startlabel, int CC, datetime endline = 0, int type = 0) { digits= Digits; string labelname, linename, pricelabel; if (endline==0) endline = Time[0]; if (type == 1) // scope to include Obj for Central Pivots etc etc { labelname = ObjCamarilla+" " + text + " Label"; linename= ObjCamarilla + " " + text + " Line"; } else { labelname = ObjPivot+" " + text + " Label"; linename= ObjPivot + " " + text + " Line"; } //----create or move the horizontal line------------------------------------------------- int Z; if (CC == 0){Z = OBJ_TREND;} if (CC == 1){Z = OBJ_HLINE;} if (ObjectFind(linename) != 0) { ObjectCreate(linename, Z, 0, startline, level, endline, level); ObjectSet (linename, OBJPROP_RAY, false); ObjectSet (linename, OBJPROP_STYLE, linestyle); ObjectSet (linename, OBJPROP_COLOR, col1); ObjectSet (linename, OBJPROP_WIDTH, thickness); ObjectSet (linename, OBJPROP_BACK, true); } else { ObjectMove (linename, 1, endline, level); ObjectMove (linename, 0, startline, level); } //----create or move the labels----------------------------------------------------------- string FontStyle; if (L_Label_Norm_Bold_Black_123 <= 1){FontStyle = "Arial";} if (L_Label_Norm_Bold_Black_123 == 2){FontStyle = "Arial Bold";} if (L_Label_Norm_Bold_Black_123 >= 3){FontStyle = "Arial Black";} pricelabel= " " + text; if (LineLabelsIncludePrice && StrToInteger(text)==0) {pricelabel= pricelabel + ": "+DoubleToStr(level, Digits);} if (ObjectFind(labelname) != 0) { ObjectCreate (labelname, OBJ_TEXT, 0, startlabel, level); ObjectSetText (labelname, pricelabel, LineLabelsFontSize, FontStyle, PivotLinesLabelColor); ObjectSet (labelname, OBJPROP_BACK, true); } else { ObjectMove(labelname, 0, startlabel, level); } } //+-------------------------------------------------------------------------------------------+ //| Helper=draws vertical timelines & gets "Yesterday/today" from elsewhere and displays them.| //+-------------------------------------------------------------------------------------------+ void SetTimeLine(string objname, string text, int idx, color col1, double vleveltext) { string FontStyle; string name= "[TIME] " + objname; int x= Time[idx]; if (ObjectFind(name) != 0) { ObjectCreate(name, OBJ_TREND, 0, x, 0, x, 100); ObjectSet(name, OBJPROP_STYLE, SeparatorLinesStyle_01234); ObjectSet(name, OBJPROP_COLOR, PeriodSeparatorLinesColor); ObjectSet(name, OBJPROP_WIDTH, SeparatorLinesThickness); } else { ObjectMove(name, 0, x, 0); ObjectMove(name, 1, x, 100); } if(ShowPeriodSeparatorLabels ==true) { if (S_Label_Norm_Bold_Black_123 <= 1){FontStyle = "Arial";} if (S_Label_Norm_Bold_Black_123 == 2){FontStyle = "Arial Bold";} if (S_Label_Norm_Bold_Black_123 >= 3){FontStyle = "Arial Black";} if (ObjectFind(name + " Label") != 0) { ObjectCreate (name + " Label", OBJ_TEXT, 0, x, vleveltext); ObjectSetText(name + " Label", text, SeparatorLabelFontSize, FontStyle, PeriodSeparatorsLabelsColor); } else { ObjectMove(name + " Label", 0, x, vleveltext); } } } //+-------------------------------------------------------------------------------------------+ //| End of Program | //+-------------------------------------------------------------------------------------------+