Navigation:Home > Content >

Pivots_Daily_SR.mq4

Time: 2014-09-13 | Download file:Pivots_Daily_SR.mq4

//+------------------------------------------------------------------+
//|   Original Indicator Auto-Pivot Plotter Labels.mq4 Elton Treloar |
//|               I called this one Pivot Point S&R + GMT correction |
//|                                         and was made by Linuxser |
//|  Thanks to Rosh form metaquotes forum for fix the redraw problem |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#define IND_NAME "Pivot Point S&R"
#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Gold
#property indicator_color2 Blue
#property indicator_color3 Maroon
#property indicator_color4 Blue
#property indicator_color5 Maroon
#property indicator_color6 Blue
#property indicator_color7 Maroon

//---- input parameters
extern int       StartHour=2;
extern int       StartMinute=0;
extern int       DaysToPlot=10;
extern color     SupportLabelColor=MidnightBlue;
extern color     ResistanceLabelColor=MidnightBlue;
extern color     PivotLabelColor=AliceBlue;
extern int       fontsize=8;
extern int       LabelShift = 0;
extern int		Level=30; // уровень предупреждения вокруг уровня
extern bool		mAlert=false;// пригрывать сигналы или нет
extern int		Wait=100000; // время между сигналами (зависит также от времени прихода котировки)
//---- buffers
double R3Buffer[];
double R2Buffer[];
double R1Buffer[];
double PBuffer[];
double S1Buffer[];
double S2Buffer[];
double S3Buffer[];


string Pivot="Pivot",Sup1="S 1", Res1="R 1";
string Sup2="S 2", Res2="R 2", Sup3="S 3", Res3="R 3";

datetime LabelShiftTime;

double P,S1,R1,S2,R2,S3,R3;
int start_time;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE,0,2);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexStyle(6,DRAW_LINE);
   SetIndexBuffer(0,PBuffer);
   SetIndexBuffer(1,S1Buffer);
   SetIndexBuffer(2,R1Buffer);
   SetIndexBuffer(3,S2Buffer);
   SetIndexBuffer(4,R2Buffer);
   SetIndexBuffer(5,S3Buffer);
   SetIndexBuffer(6,R3Buffer);
   
   IndicatorShortName(IND_NAME);
//----
start_time = GetTickCount();
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----

   ObjectDelete("Res3");
   ObjectDelete("Res2");
   ObjectDelete("Res1");
   ObjectDelete("Pivot");
   ObjectDelete("Sup1");
   ObjectDelete("Sup2");
   ObjectDelete("Sup3");   
   
  ObjectDelete("H4 Label");
  ObjectDelete("H4 Line");
  ObjectDelete("H3 Label");
  ObjectDelete("H3 Line");
  ObjectDelete("L3 Label");
  ObjectDelete("L3 Line");
  ObjectDelete("L4 Label");
  ObjectDelete("L4 Line");

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(); 
  
//---- exit if period is greater than daily charts
    if(Period() > 240)
   {
   Print("Error - Chart period is greater than 1 day.");
   return(-1); // then exit
   }
  
//---- 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]Wait)
	{
		start_time = cur;  
      u = PBuffer[0]+Level*Point; d = PBuffer[0]-Level*Point; 
		if ((mAlert) && (Bid>=d && Bid<=u))
      Alert(Symbol()," ",DoubleToStr(Bid, Digits)," Pivot");		
	
      us1 = S1Buffer[0]+Level*Point; ds1 = S1Buffer[0]-Level*Point; 
		if ((mAlert) && (Bid>=ds1 && Bid<=us1))
      Alert(Symbol()," ",DoubleToStr(Bid, Digits)," S1");
      
      us2 = S2Buffer[0]+Level*Point; ds2 = S2Buffer[0]-Level*Point; 
		if ((mAlert) && (Bid>=ds2 && Bid<=us2))
      Alert(Symbol()," ",DoubleToStr(Bid, Digits)," S2");
      
      ur1 = R1Buffer[0]+Level*Point; dr1 = R1Buffer[0]-Level*Point; 
		if ((mAlert) && (Bid>=dr1 && Bid<=ur1))
      Alert(Symbol()," ",DoubleToStr(Bid, Digits)," R1");
      
      ur2 = R2Buffer[0]+Level*Point; dr2 = R2Buffer[0]-Level*Point; 
		if ((mAlert) && (Bid>=dr2 && Bid<=ur2))
      Alert(Symbol()," ",DoubleToStr(Bid, Digits)," R2");                  	
	}	
   // *****************************************
   //    Return from Start() (Main Routine)
   return(0);
  
  }
//+-------------------------------------------------------------------------------------------------------+
//  END Custom indicator iteration function
//+-------------------------------------------------------------------------------------------------------+


// *****************************************************************************************
// *****************************************************************************************
// -----------------------------------------------------------------------------------------
//    The following routine will use "StartingBar"'s time and use it to find the 
//    general area that SHOULD contain the bar that matches "TimeToLookFor"
// -----------------------------------------------------------------------------------------
int FindLastTimeMatchFast(int TimeToLookFor,int StartingBar)
   {
   int StartingBarsTime=(TimeHour(Time[StartingBar])*60)+TimeMinute(Time[StartingBar]);
   
   // ***************************************************
   //    Check that our search isn't on the otherside of 
   //    the midnight boundary and correct for calculations
   // ***************************************************
   if (StartingBarsTime0)
      {
        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        

Recommend