Yearly_Pivots

Yearly_Pivots
Price Data Components
Series array that contains open time of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each barSeries array that contains close prices for each bar
0 Views
0 Downloads
0 Favorites
Yearly_Pivots
//+------------------------------------------------------------------+
//|                                                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)<low)
            low=iLow(NULL,PERIOD_MN1,pos);
         if(TimeMonth(iTime(NULL, PERIOD_MN1, pos))==12)
            close=iClose(NULL,PERIOD_MN1,pos);
      }
      

      

      
      pos++;
    }
    
    P=(high+low+close)/3;
    R1 = (2*P)-low;
    S1 = (2*P)-high;
    R2 = P + (R1-S1);
    S2 = P - (R1-S1);
    R3 = high+2*(P-low);
    S3 = low-2*(high-P); 
    
    MR1=(P+R1)/2;
    MR2=(R1+R2)/2;
    MR3=(R2+R3)/2;
    MS1=(P+S1)/2;
    MS2=(S1+S2)/2;
    MS3=(S2+S3)/2;
        
    //**************************PIVOTS!!!********************************
    ObjectCreate("Yearly_Pivot_P", OBJ_HLINE, 0, 0, P);
    ObjectSet("Yearly_Pivot_P", OBJPROP_COLOR, P_color);
    ObjectSet("Yearly_Pivot_P", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_P", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_R1", OBJ_HLINE, 0, 0, R1);
    ObjectSet("Yearly_Pivot_R1", OBJPROP_COLOR, R_color);
    ObjectSet("Yearly_Pivot_R1", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_R1", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_R2", OBJ_HLINE, 0, 0, R2);
    ObjectSet("Yearly_Pivot_R2", OBJPROP_COLOR, R_color);
    ObjectSet("Yearly_Pivot_R2", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_R2", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_R3", OBJ_HLINE, 0, 0, R3);
    ObjectSet("Yearly_Pivot_R3", OBJPROP_COLOR, R_color);
    ObjectSet("Yearly_Pivot_R3", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_R3", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_S1", OBJ_HLINE, 0, 0, S1);
    ObjectSet("Yearly_Pivot_S1", OBJPROP_COLOR, S_color);
    ObjectSet("Yearly_Pivot_S1", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_S1", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_S2", OBJ_HLINE, 0, 0, S2);
    ObjectSet("Yearly_Pivot_S2", OBJPROP_COLOR, S_color);
    ObjectSet("Yearly_Pivot_S2", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_S2", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_S3", OBJ_HLINE, 0, 0, S3);
    ObjectSet("Yearly_Pivot_S3", OBJPROP_COLOR, S_color);
    ObjectSet("Yearly_Pivot_S3", OBJPROP_STYLE, LineStyle);
    ObjectSet("Yearly_Pivot_S3", OBJPROP_WIDTH, LineWidth);
    
    ObjectCreate("Yearly_Pivot_LABEL_P", OBJ_TEXT, 0, Time[0], P);
    ObjectSet("Yearly_Pivot_LABEL_P", OBJPROP_COLOR, P_color);
    ObjectSetText("Yearly_Pivot_LABEL_P", "Pivot:"+DoubleToStr(P,Digits));
    
    ObjectCreate("Yearly_Pivot_LABEL_R1", OBJ_TEXT, 0, Time[0], R1);
    ObjectSet("Yearly_Pivot_LABEL_R1", OBJPROP_COLOR, R_color);
    ObjectSetText("Yearly_Pivot_LABEL_R1", "R1:"+DoubleToStr(R1,Digits));
    
    ObjectCreate("Yearly_Pivot_LABEL_R2", OBJ_TEXT, 0, Time[0], R2);
    ObjectSet("Yearly_Pivot_LABEL_R2", OBJPROP_COLOR, R_color);
    ObjectSetText("Yearly_Pivot_LABEL_R2", "R2:"+DoubleToStr(R2,Digits));
    
    ObjectCreate("Yearly_Pivot_LABEL_R3", OBJ_TEXT, 0, Time[0], R3);
    ObjectSet("Yearly_Pivot_LABEL_R3", OBJPROP_COLOR, R_color);
    ObjectSetText("Yearly_Pivot_LABEL_R3", "R3:"+DoubleToStr(R3,Digits));
    
    ObjectCreate("Yearly_Pivot_LABEL_S1", OBJ_TEXT, 0, Time[0], S1);
    ObjectSet("Yearly_Pivot_LABEL_S1", OBJPROP_COLOR, S_color);
    ObjectSetText("Yearly_Pivot_LABEL_S1", "S1:"+DoubleToStr(S1,Digits));
    
    ObjectCreate("Yearly_Pivot_LABEL_S2", OBJ_TEXT, 0, Time[0], S2);
    ObjectSet("Yearly_Pivot_LABEL_S2", OBJPROP_COLOR, S_color);
    ObjectSetText("Yearly_Pivot_LABEL_S2", "S2:"+DoubleToStr(S2,Digits));
    
    ObjectCreate("Yearly_Pivot_LABEL_S3", OBJ_TEXT, 0, Time[0], S3);
    ObjectSet("Yearly_Pivot_LABEL_S3", OBJPROP_COLOR, S_color);
    ObjectSetText("Yearly_Pivot_LABEL_S3", "S3:"+DoubleToStr(S3,Digits));
    //***********************************************************************
    
    //****************************Midpivots*************************************
    if(ShowMidPivots==true)
    {
       ObjectCreate("Yearly_Pivot_MR1", OBJ_HLINE, 0, 0, MR1);
       ObjectSet("Yearly_Pivot_MR1", OBJPROP_COLOR, MR_color);
       ObjectSet("Yearly_Pivot_MR1", OBJPROP_STYLE, MidLineStyle);
       ObjectSet("Yearly_Pivot_MR1", OBJPROP_WIDTH, MidLineWidth);
       ObjectCreate("Yearly_Pivot_MR2", OBJ_HLINE, 0, 0, MR2);
       ObjectSet("Yearly_Pivot_MR2", OBJPROP_COLOR, MR_color);
       ObjectSet("Yearly_Pivot_MR2", OBJPROP_STYLE, MidLineStyle);
       ObjectSet("Yearly_Pivot_MR2", OBJPROP_WIDTH, MidLineWidth);
       ObjectCreate("Yearly_Pivot_MR3", OBJ_HLINE, 0, 0, MR3);
       ObjectSet("Yearly_Pivot_MR3", OBJPROP_COLOR, MR_color);
       ObjectSet("Yearly_Pivot_MR3", OBJPROP_STYLE, MidLineStyle);
       ObjectSet("Yearly_Pivot_MR3", OBJPROP_WIDTH, MidLineWidth);
       ObjectCreate("Yearly_Pivot_MS1", OBJ_HLINE, 0, 0, MS1);
       ObjectSet("Yearly_Pivot_MS1", OBJPROP_COLOR, MS_color);
       ObjectSet("Yearly_Pivot_MS1", OBJPROP_STYLE, MidLineStyle);
       ObjectSet("Yearly_Pivot_MS1", OBJPROP_WIDTH, MidLineWidth);
       ObjectCreate("Yearly_Pivot_MS2", OBJ_HLINE, 0, 0, MS2);
       ObjectSet("Yearly_Pivot_MS2", OBJPROP_COLOR, MS_color);
       ObjectSet("Yearly_Pivot_MS2", OBJPROP_STYLE, MidLineStyle);
       ObjectSet("Yearly_Pivot_MS2", OBJPROP_WIDTH, MidLineWidth);
       ObjectCreate("Yearly_Pivot_MS3", OBJ_HLINE, 0, 0, MS3);
       ObjectSet("Yearly_Pivot_MS3", OBJPROP_COLOR, MS_color);
       ObjectSet("Yearly_Pivot_MS3", OBJPROP_STYLE, MidLineStyle);
       ObjectSet("Yearly_Pivot_MS3", OBJPROP_WIDTH, MidLineWidth);
       
       ObjectCreate("Yearly_Pivot_LABEL_MR1", OBJ_TEXT, 0, Time[0], MR1);
       ObjectSet("Yearly_Pivot_LABEL_MR1", OBJPROP_COLOR, MR_color);
       ObjectSetText("Yearly_Pivot_LABEL_MR1", "MR1:"+DoubleToStr(MR1,Digits));
       ObjectCreate("Yearly_Pivot_LABEL_MR2", OBJ_TEXT, 0, Time[0], MR2);
       ObjectSet("Yearly_Pivot_LABEL_MR2", OBJPROP_COLOR, MR_color);
       ObjectSetText("Yearly_Pivot_LABEL_MR2", "MR2:"+DoubleToStr(MR2,Digits));
       ObjectCreate("Yearly_Pivot_LABEL_MR3", OBJ_TEXT, 0, Time[0], MR3);
       ObjectSet("Yearly_Pivot_LABEL_MR3", OBJPROP_COLOR, MR_color);
       ObjectSetText("Yearly_Pivot_LABEL_MR3", "MR3:"+DoubleToStr(MR3,Digits));
       ObjectCreate("Yearly_Pivot_LABEL_MS1", OBJ_TEXT, 0, Time[0], MS1);
       ObjectSet("Yearly_Pivot_LABEL_MS1", OBJPROP_COLOR, MS_color);
       ObjectSetText("Yearly_Pivot_LABEL_MS1", "MS1:"+DoubleToStr(MS1,Digits));
       ObjectCreate("Yearly_Pivot_LABEL_MS2", OBJ_TEXT, 0, Time[0], MS2);
       ObjectSet("Yearly_Pivot_LABEL_MS2", OBJPROP_COLOR, MS_color);
       ObjectSetText("Yearly_Pivot_LABEL_MS2", "MS2:"+DoubleToStr(MS2,Digits));
       ObjectCreate("Yearly_Pivot_LABEL_MS3", OBJ_TEXT, 0, Time[0], MS3);
       ObjectSet("Yearly_Pivot_LABEL_MS3", OBJPROP_COLOR, MS_color);
       ObjectSetText("Yearly_Pivot_LABEL_MS3", "MS3:"+DoubleToStr(MS3,Digits));
   
    }
    //**************************************************************************
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---