//+------------------------------------------------------------------+ //| Original Indicator Auto-Pivot Plotter Labels.mq4 Elton Treloar | //| I called this one Pivot Point Medians + GMT correction | //| and was made by Linuxser | //| Thanks to Rosh form metaquotes forum for fix the redraw problem | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 DeepSkyBlue #property indicator_color2 DeepSkyBlue #property indicator_color3 DeepSkyBlue #property indicator_color4 Orange #property indicator_color5 Orange #property indicator_color6 Orange #define IND_NAME "Pivot Point Medians" //---- input parameters extern int StartHour=0; extern int StartMinute=0; extern int DaysToPlot=15; extern color SupportLabelColor=DeepSkyBlue; extern color ResistanceLabelColor=Orange; extern int fontsize=6; extern int LabelShift = 0; //---- buffers double M0Buffer[]; double M1Buffer[]; double M2Buffer[]; double M3Buffer[]; double M4Buffer[]; double M5Buffer[]; datetime LabelShiftTime; string Pivot="Pivot",Sup1="S 1", Res1="R 1"; string Sup2="S 2", Res2="R 2", Sup3="S 3", Res3="R 3"; double M0,M1,M2,M3,M4,M5; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE,2,0); SetIndexStyle(1,DRAW_LINE,2,0); SetIndexStyle(2,DRAW_LINE,2,0); SetIndexStyle(3,DRAW_LINE,2,0); SetIndexStyle(4,DRAW_LINE,2,0); SetIndexStyle(5,DRAW_LINE,2,0); SetIndexStyle(6,DRAW_LINE,2,0); SetIndexBuffer(0,M0Buffer); SetIndexBuffer(1,M1Buffer); SetIndexBuffer(2,M2Buffer); SetIndexBuffer(3,M3Buffer); SetIndexBuffer(4,M4Buffer); SetIndexBuffer(5,M5Buffer); IndicatorShortName(IND_NAME); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("M0"); ObjectDelete("M1"); ObjectDelete("M2"); ObjectDelete("M3"); ObjectDelete("M4"); ObjectDelete("M5"); ObjectDelete("M6"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- indicator calculation { if (counted_bars==0) if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; } int limit=Bars-counted_bars; int StartMinutesIntoDay=(StartHour*60)+StartMinute; // 8' o'clock x 60 = 480 int CloseMinutesIntoDay=StartMinutesIntoDay-Period(); // // **************************************************** // Check That cloes time isn't now a negative number. // Correct if it is by adding a full day's worth // of minutes. // **************************************************** if (CloseMinutesIntoDay<0) { CloseMinutesIntoDay=CloseMinutesIntoDay+1440; } // **************************************************** // Establish the nuber of bars in a day. // **************************************************** int BarsInDay=1440/Period(); // ****************************************************************************************** // ****************************************************************************************** // Main Loop // ****************************************************************************************** // ****************************************************************************************** for(int i=0; iPreviousHigh) PreviousHigh=High[SearchHighLow]; if (Low[SearchHighLow]0) { for (int SearchCount=SuggestedBar ;SearchCount>(SuggestedBar-DeltaBarFound-2) ;SearchCount--) { // ****************************************************************************** // Find time (in minutes) of the current bar AND the two bars either side of it. // This is done to allow for any missing bars in the data. i.e. If THE bar you // were after were to be missing you'd never get a valid close/open time. // This is the same reason for searching rather than just looking back a certain // number of bars from the close time. Missing bars upset the count back and // screw up all pivot calculations. There is still room for error but it's improved. // The best calculations will come from having the best data. ...of course. :) // ****************************************************************************** // int PreviousBarsTime=(TimeHour(Time[SearchCount+1])*60)+TimeMinute(Time[SearchCount+1]); int CurrentBarsTime=(TimeHour(Time[SearchCount])*60)+TimeMinute(Time[SearchCount]); int NextBarsTime=(TimeHour(Time[SearchCount-1])*60)+TimeMinute(Time[SearchCount-1]); if (CurrentBarsTime==TimeToLookFor) { return(SearchCount); // *** If current bar is what we are after than lets get out. // *** without mucking about with the rest of the checks. } // ********************************** // Check that previous bar doesn't // lay on a different day. // Adjust if it is // ********************************** if(PreviousBarsTime>CurrentBarsTime) { PreviousBarsTime=PreviousBarsTime-1440; } // ********************************** // Check that following bar doesn't // lay on a different day. // Adjust if it is. // ********************************** if(NextBarsTime