Sidebar for the article “The V-Trade, Part 3: Technical Analysis—Fibonacci Projections And Daily Pivots” by Sylvain Vervoort, in the May 2018 issue of Technical Analysis of STOCKS & COMMODITIES magazine.
//+---------------------------------------------+ //| SvePivots.mq4 Version 3.3 | //| Copyright © 2008-2017, Sylvain vervoort | //| https://stocata.org/ | //+---------------------------------------------+ #property copyright "©2008-2018, Sylvain vervoort" #property link "https://stocata.org/" #property description "Pivot points calculated on previous day with Lowest low" #property description "and Highest high price indication. Not shown on daily," #property description "weekly or monthly chart! 2018 V3.3" #property description " " #property description "Make sure you have a clean correct database!" #property strict #property indicator_chart_window #property indicator_buffers 15 #property indicator_color1 Blue #property indicator_color2 Red #property indicator_color3 SkyBlue #property indicator_color4 Coral #property indicator_color5 Aqua #property indicator_color6 Pink #property indicator_color7 LightBlue #property indicator_color8 Magenta #property indicator_color9 LightGray #property indicator_color10 LightGray #property indicator_color11 LightGray #property indicator_color12 LightGray #property indicator_color13 LightGray #property indicator_color14 LightGray #property indicator_color15 LightGreen #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_width6 1 #property indicator_width7 1 #property indicator_width8 1 #property indicator_width9 1 #property indicator_width10 1 #property indicator_width11 1 #property indicator_width12 1 #property indicator_width13 1 #property indicator_width14 1 #property indicator_width15 1 #property indicator_style1 STYLE_DASH #property indicator_style2 STYLE_DASH #property indicator_style3 STYLE_DASH #property indicator_style4 STYLE_DASH #property indicator_style5 STYLE_DASH #property indicator_style6 STYLE_DASH #property indicator_style7 STYLE_DASH #property indicator_style8 STYLE_SOLID #property indicator_style9 STYLE_DASH #property indicator_style10 STYLE_DASH #property indicator_style11 STYLE_DASH #property indicator_style12 STYLE_DASH #property indicator_style13 STYLE_DASH #property indicator_style14 STYLE_DASH #property indicator_style15 STYLE_SOLID //---- input parameters extern int DiffLocMinServTme = 0; // Difference Local Time Minus Server Time //---- buffers and other Definitions double PPBuffer[]; // Pivot Point double S1Buffer[]; // Support 1 double R1Buffer[]; // Resistance 1 double S2Buffer[]; // Support 1 double R2Buffer[]; // Resistance 2 double S3Buffer[]; // Support 1 double R3Buffer[]; // Resistance 3 double PLBuffer[]; // Previous day low double S1MBuffer[]; // Support 1 mean value double R1MBuffer[]; // Resistance 1 mean value double S2MBuffer[]; // Support 2 mean value double R2MBuffer[]; // Resistance 2 mean value double S3MBuffer[]; // Support 3 mean value double R3MBuffer[]; // Resistance 3 mean value double PHBuffer[]; // Previous day High double PP, S1, S2, S3, R1, R2, R3, PL, LastHigh, LastLow; double S1M, S2M, S3M, R1M, R2M, R3M, PH; int GMTDiff = 0, DstTime, DstCorrection, DifLocMinServ; int ThisDay, PrevDay; bool SundayTrade = false; //+---------------------------------------------+ //| SvePivots indicator initialisation function | //+---------------------------------------------+ int OnInit() { // Check validity of the input: Local minus Server time DifLocMinServ = DiffLocMinServTme; if( MathAbs(DifLocMinServ) > 12 ) { DifLocMinServ = 0; Alert("Enter a valid difference for Local minus Server time!"); Alert("Invalid! Difference should be +-12, 0 used instead!"); } // Buffer parameters SetIndexStyle(0, DRAW_LINE, STYLE_DOT); SetIndexStyle(1, DRAW_LINE, STYLE_DOT); SetIndexStyle(2, DRAW_LINE, STYLE_DOT); SetIndexStyle(3, DRAW_LINE, STYLE_DOT); SetIndexStyle(4, DRAW_LINE, STYLE_DOT); SetIndexStyle(5, DRAW_LINE, STYLE_DOT); SetIndexStyle(6, DRAW_LINE, STYLE_DOT); SetIndexStyle(7, DRAW_LINE, STYLE_SOLID); SetIndexStyle(8, DRAW_LINE, STYLE_DOT); SetIndexStyle(9, DRAW_LINE, STYLE_DOT); SetIndexStyle(10, DRAW_LINE, STYLE_DOT); SetIndexStyle(11, DRAW_LINE, STYLE_DOT); SetIndexStyle(12, DRAW_LINE, STYLE_DOT); SetIndexStyle(13, DRAW_LINE, STYLE_DOT); SetIndexStyle(14, DRAW_LINE, STYLE_SOLID); SetIndexBuffer(0, PPBuffer); SetIndexBuffer(1, S1Buffer); SetIndexBuffer(2, R1Buffer); SetIndexBuffer(3, S2Buffer); SetIndexBuffer(4, R2Buffer); SetIndexBuffer(5, S3Buffer); SetIndexBuffer(6, R3Buffer); SetIndexBuffer(7, PLBuffer); SetIndexBuffer(8, S1MBuffer); SetIndexBuffer(9, R1MBuffer); SetIndexBuffer(10, S2MBuffer); SetIndexBuffer(11, R2MBuffer); SetIndexBuffer(12, S3MBuffer); SetIndexBuffer(13, R3MBuffer); SetIndexBuffer(14, PHBuffer); // Daylight saving Time correction DstTime = TimeDaylightSavings(); // wintertime DstTime == 0 // summertime DstTime == daylight saving time difference in seconds (+3600 seconds) if (DstTime==0) DstCorrection = 3600; else DstCorrection = 0; // Indicator name string DiffLocServTime = IntegerToString(DifLocMinServ); IndicatorShortName("SvePivots("+DiffLocServTime+")"); // GMT/UTC Difference Local minus Server time GMTDiff = TimeHour(TimeGMT()) - TimeHour(TimeLocal()) + DifLocMinServ; SundayTrade = false; //---- return(INIT_SUCCEEDED); } //+---------------------------------------------+ //| SvePivots Indicator calculation function | //+---------------------------------------------+ int OnCalculate (const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[]) { // Do not show daily Pivots on Day, Week or Monthly charts if(Period() == PERIOD_D1) return(rates_total); if(Period() == PERIOD_W1) return(rates_total); if(Period() == PERIOD_MN1) return(rates_total); // How many bars in this chart? int counted_bars = prev_calculated; // How may bars in the chart? if (counted_bars < 0) return(-1); // No bars return error. if (counted_bars > 0) counted_bars--; // -1 to start count from index 0. int limit=(MathMin(rates_total-counted_bars,rates_total-1)); for(int i=limit; i>=0 && !_StopFlag; i--) { // Handle the output for the first history bar if(i == limit) { LastLow = open[i]; LastHigh = open[i]; i--; } // Keep track of the highest and lowest price reached during the current day if(high[i+1] > LastHigh) LastHigh = high[i+1]; if(low[i+1] < LastLow) LastLow = low[i+1]; // What day of the week are we? ThisDay = TimeDayOfWeek(Time[i] +GMTDiff*3600+DstCorrection); PrevDay = TimeDayOfWeek(Time[i+1]+GMTDiff*3600+DstCorrection); // Is there data available starting on a Sunday (forex)? // If yes, set SundayTrade TRUE. if(ThisDay == 0) SundayTrade = true; // If current bar and previous bar are within the same day, // or current bar is a Saterday, just extend the current pivot level if(ThisDay - PrevDay == 0 || ThisDay == 6) FunctionWriteCurrPivot(i); // If current and previous day are different AND not a Saterday or // not a Sunday trade then calculate and draw new pivots else if(ThisDay != PrevDay && !SundayTrade && ThisDay != 6) { double PriceClose = close[i+1]; double PriceOpen = open [i]; FunctionCalcNewPivots (i,PriceClose,PriceOpen); FunctionWriteCurrPivot(i); } // If there are Sunday Trading hours and this is a Monday,the new week is // already started on the Sunday, we just extend the Sunday values else if(SundayTrade && ThisDay == 1) FunctionWriteCurrPivot(i); // If we have a day change AND trading on Sunday true, we handle it here // calculating the new pivots and draw them on the chart else if(ThisDay != PrevDay && SundayTrade) { double PriceClose = close[i+1]; double PriceOpen = open [i]; FunctionCalcNewPivots (i,PriceClose,PriceOpen); FunctionWriteCurrPivot(i); } } //---- return(rates_total); } // +-------------------------------------------+ // Function, store current pivot values for this new bar | // +--------------------------------------------+ int FunctionWriteCurrPivot(int a) { PPBuffer[a] = PP; S1Buffer[a] = S1; R1Buffer[a] = R1; S2Buffer[a] = S2; R2Buffer[a] = R2; S3Buffer[a] = S3; R3Buffer[a] = R3; PLBuffer[a] = PL; S1MBuffer[a] = S1M; R1MBuffer[a] = R1M; S2MBuffer[a] = S2M; R2MBuffer[a] = R2M; S3MBuffer[a] = S3M; R3MBuffer[a] = R3M; PHBuffer [a] = PH; return(a); } // +-------------------------------------------+ // Function calculate new pivott values for this new bar | // +-------------------------------------------+ int FunctionCalcNewPivots(int a, double PrClose, double PrOpen) { PP = (LastHigh + LastLow + PrClose) / 3; R1 = (2*PP) - LastLow; S1 = (2*PP) - LastHigh; R2 = PP + (LastHigh - LastLow); S2 = PP - (LastHigh - LastLow); R3 = (2*PP) + (LastHigh - (2*LastLow)); S3 = (2*PP) - ((2* LastHigh) - LastLow); PL = LastLow; R1M = (R1-PP)/2 + PP; S1M = (PP-S1)/2 + S1; R2M = (R2-R1)/2 + R1; S2M = (S1-S2)/2 + S2; R3M = (R3-R2)/2 + R2; S3M = (S2-S3)/2 + S3; PH = LastHigh; LastLow = PrOpen; LastHigh = PrOpen; PrevDay = ThisDay; return(a); } // ---------------------------------------------- // END OF PROGRAM