Navigation:Home > Content >

Yearly_Pivots.mq4

Time: 2010-08-04 | Download file:Yearly_Pivots.mq4

//+------------------------------------------------------------------+
//|                                                Yearly_Pivots.mq4 |
//|                                          Copyright © 2008,  Siro |
//+------------------------------------------------------------------+

#property indicator_chart_window


extern int LineWidth=2;
extern int MidLineWidth=0;
extern string Style="LineStyle should be 0-5";
extern int LineStyle=0;
extern int MidLineStyle=3;
extern color P_color=Navy;
extern color S_color=Blue;
extern color MS_color=Blue;
extern color R_color=Red;
extern color MR_color=Red;
extern bool ShowMidPivots=true;





double P,R1,R2,R3,S1,S2,S3;
double MR1,MR2,MR3,MS1,MS2,MS3;
int actualyear;
double high=-999999,low=999999,close;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   if(ObjectFind("Yearly_Pivot_P")!=-1)
      ObjectDelete("Yearly_Pivot_P");
   if(ObjectFind("Yearly_Pivot_R1")!=-1)
      ObjectDelete("Yearly_Pivot_R1");
   if(ObjectFind("Yearly_Pivot_R2")!=-1)
      ObjectDelete("Yearly_Pivot_R2");
   if(ObjectFind("Yearly_Pivot_R3")!=-1)
      ObjectDelete("Yearly_Pivot_R3");
   if(ObjectFind("Yearly_Pivot_S1")!=-1)
      ObjectDelete("Yearly_Pivot_S1");
   if(ObjectFind("Yearly_Pivot_S2")!=-1)
      ObjectDelete("Yearly_Pivot_S2");
   if(ObjectFind("Yearly_Pivot_S3")!=-1)
      ObjectDelete("Yearly_Pivot_S3");
   if(ObjectFind("Yearly_Pivot_LABEL_P")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_P");
   if(ObjectFind("Yearly_Pivot_LABEL_R1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_R1");
   if(ObjectFind("Yearly_Pivot_LABEL_R2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_R2");
   if(ObjectFind("Yearly_Pivot_LABEL_R3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_R3");
   if(ObjectFind("Yearly_Pivot_LABEL_S1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_S1");
   if(ObjectFind("Yearly_Pivot_LABEL_S2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_S2");
   if(ObjectFind("Yearly_Pivot_LABEL_S3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_S3");
      
   if(ObjectFind("Yearly_Pivot_MR1")!=-1)
      ObjectDelete("Yearly_Pivot_MR1");
   if(ObjectFind("Yearly_Pivot_MR2")!=-1)
      ObjectDelete("Yearly_Pivot_MR2");
   if(ObjectFind("Yearly_Pivot_MR3")!=-1)
      ObjectDelete("Yearly_Pivot_MR3");
   if(ObjectFind("Yearly_Pivot_MS1")!=-1)
      ObjectDelete("Yearly_Pivot_MS1");
   if(ObjectFind("Yearly_Pivot_MS2")!=-1)
      ObjectDelete("Yearly_Pivot_MS2");
   if(ObjectFind("Yearly_Pivot_MS3")!=-1)
      ObjectDelete("Yearly_Pivot_MS3");
   if(ObjectFind("Yearly_Pivot_LABEL_MR1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MR1");
   if(ObjectFind("Yearly_Pivot_LABEL_MR2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MR2");
   if(ObjectFind("Yearly_Pivot_LABEL_MR3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MR3");
   if(ObjectFind("Yearly_Pivot_LABEL_MS1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MS1");
   if(ObjectFind("Yearly_Pivot_LABEL_MS2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MS2");
   if(ObjectFind("Yearly_Pivot_LABEL_MS3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MS3");
   IndicatorShortName("Yearly Pivots");
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
      if(ObjectFind("Yearly_Pivot_P")!=-1)
      ObjectDelete("Yearly_Pivot_P");
   if(ObjectFind("Yearly_Pivot_R1")!=-1)
      ObjectDelete("Yearly_Pivot_R1");
   if(ObjectFind("Yearly_Pivot_R2")!=-1)
      ObjectDelete("Yearly_Pivot_R2");
   if(ObjectFind("Yearly_Pivot_R3")!=-1)
      ObjectDelete("Yearly_Pivot_R3");
   if(ObjectFind("Yearly_Pivot_S1")!=-1)
      ObjectDelete("Yearly_Pivot_S1");
   if(ObjectFind("Yearly_Pivot_S2")!=-1)
      ObjectDelete("Yearly_Pivot_S2");
   if(ObjectFind("Yearly_Pivot_S3")!=-1)
      ObjectDelete("Yearly_Pivot_S3");
   if(ObjectFind("Yearly_Pivot_LABEL_P")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_P");
   if(ObjectFind("Yearly_Pivot_LABEL_R1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_R1");
   if(ObjectFind("Yearly_Pivot_LABEL_R2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_R2");
   if(ObjectFind("Yearly_Pivot_LABEL_R3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_R3");
   if(ObjectFind("Yearly_Pivot_LABEL_S1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_S1");
   if(ObjectFind("Yearly_Pivot_LABEL_S2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_S2");
   if(ObjectFind("Yearly_Pivot_LABEL_S3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_S3");
      
   if(ObjectFind("Yearly_Pivot_MR1")!=-1)
      ObjectDelete("Yearly_Pivot_MR1");
   if(ObjectFind("Yearly_Pivot_MR2")!=-1)
      ObjectDelete("Yearly_Pivot_MR2");
   if(ObjectFind("Yearly_Pivot_MR3")!=-1)
      ObjectDelete("Yearly_Pivot_MR3");
   if(ObjectFind("Yearly_Pivot_MS1")!=-1)
      ObjectDelete("Yearly_Pivot_MS1");
   if(ObjectFind("Yearly_Pivot_MS2")!=-1)
      ObjectDelete("Yearly_Pivot_MS2");
   if(ObjectFind("Yearly_Pivot_MS3")!=-1)
      ObjectDelete("Yearly_Pivot_MS3");
   if(ObjectFind("Yearly_Pivot_LABEL_MR1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MR1");
   if(ObjectFind("Yearly_Pivot_LABEL_MR2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MR2");
   if(ObjectFind("Yearly_Pivot_LABEL_MR3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MR3");
   if(ObjectFind("Yearly_Pivot_LABEL_MS1")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MS1");
   if(ObjectFind("Yearly_Pivot_LABEL_MS2")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MS2");
   if(ObjectFind("Yearly_Pivot_LABEL_MS3")!=-1)
      ObjectDelete("Yearly_Pivot_LABEL_MS3");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    pos=0;
   int    counted_bars=IndicatorCounted();
   actualyear=TimeYear(iTime(NULL,PERIOD_MN1,0));
   if(counted_bars < 0) 
        return(-1);
//---- last counted bar will be recounted
    if(counted_bars > 0) 
        counted_bars--;
    pos = 0;
    
    while(actualyear-TimeYear(iTime(NULL, PERIOD_MN1, pos))<=1)
    {
      if(actualyear-TimeYear(iTime(NULL, PERIOD_MN1, pos))==1)
      {
         if(iHigh(NULL,PERIOD_MN1,pos)>high)
            high=iHigh(NULL,PERIOD_MN1,pos);
         if(iLow(NULL,PERIOD_MN1,pos)        

Recommend