//+------------------------------------------------------------------+
//|                                   Woodie Pivots  |
//|                               Copyright © 2008,  |
//|                                    By Darkkiller |
//|                   Original code from Waddah Attar|
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008"
#property link      ""
//----

#property indicator_chart_window
#property indicator_buffers 15
#property indicator_color1 Red
#property indicator_color2 DimGray
#property indicator_color3 DimGray
#property indicator_color4 DimGray
#property indicator_color5 DimGray
#property indicator_color6 DimGray
#property indicator_color7 DimGray
#property indicator_color8 DimGray

extern bool backtest = true;
extern bool showtitle = true;
extern int position = 1;
extern int labelsize = 1;
extern int textsize = 7;
extern color colorpivot = Red;
extern color colorresistance = DimGray;
extern color colorsupport = DimGray;

//---- buffers
double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
double P5Buffer[];
double P6Buffer[];
double P7Buffer[];
double P8Buffer[];
double P9Buffer[];



//----
int myPeriod = PERIOD_D1;
//----
double open, close;
double WPP,WR1,WR2,WR3,WS1,WS2,WS3;
double YesterdaysHigh,YesterdaysLow,TodaysOpen;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0, P1Buffer);
   SetIndexBuffer(1, P2Buffer);
   SetIndexBuffer(2, P3Buffer);
   SetIndexBuffer(3, P4Buffer);
   SetIndexBuffer(4, P5Buffer);
   SetIndexBuffer(5, P6Buffer);
   SetIndexBuffer(6, P7Buffer);
   SetIndexBuffer(7, P8Buffer);
   SetIndexBuffer(8, P9Buffer);


//----
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(2, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(3, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(4, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(5, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(6, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(7, DRAW_LINE, STYLE_SOLID, 0);
   SetIndexStyle(8, DRAW_LINE, STYLE_SOLID, 0);
//----
   Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("WPP");
   ObjectDelete("txtWPP");
   ObjectDelete("WR1");
   ObjectDelete("txtWR1");
   ObjectDelete("WR2");
   ObjectDelete("txtWR2");
   ObjectDelete("WR3");
   ObjectDelete("txtWR3");
    ObjectDelete("WS1");
   ObjectDelete("txtWS1");
   ObjectDelete("WS2");
   ObjectDelete("txtWS2");
   ObjectDelete("WS3");
   ObjectDelete("txtWS3");
   
   ObjectDelete("Woodietext");
   ObjectDelete("Woodiebg");
   //---
   
   
   
   Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, dayi, counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;  
   int limit = Bars - counted_bars;
//----   
   for(i = limit - 1; i >= 0; i--)
     {
     if(backtest)
     {
       dayi = iBarShift(Symbol(), myPeriod, Time[i], false);
       }
       open = iOpen(Symbol(), myPeriod,dayi+1);
       close = iClose(Symbol(), myPeriod,dayi+1);
       YesterdaysHigh = iHigh(Symbol(), myPeriod,dayi+1);
       YesterdaysLow = iClose(Symbol(), myPeriod,dayi+1);
       TodaysOpen = iOpen(Symbol(), myPeriod,dayi+0);
       
       
       
       //Woodie PIVOT calculation//
             WPP = (YesterdaysHigh + YesterdaysLow + (TodaysOpen * 2)) / 4;

                WR1 = (WPP * 2) - YesterdaysLow;

                WS1 = (WPP * 2) - YesterdaysHigh;

                WR2 = WPP + WR1 - WS1;

                WS2 = WPP - WR1 + WS1;

                WR3 = WPP + WR2 - WS2;

                WS3 = WPP - WR2 + WS2;

       //=SHOW WOODIE PIVOT=
       P1Buffer[i] = WPP;
       SetPrice("WPP", Time[i], WPP, colorpivot);
       SetText("txtWPP", "WoodiePIVOT                        ", Time[i], WPP, colorpivot);
 
       P2Buffer[i] = WR1;
       SetPrice("WR1", Time[i], WR1, colorresistance);
       SetText("txtWR1", "WoodieR1                 ", Time[i], WR1, colorresistance);
      
       P3Buffer[i] = WR2;
       SetPrice("WR2", Time[i], WR2, colorresistance);
       SetText("txtWR2", "WoodieR2                 ", Time[i], WR2, colorresistance);
       
        P4Buffer[i] = WR3;
       SetPrice("WR3", Time[i], WR3, colorresistance);
       SetText("txtWR3", "WoodieR3                 ", Time[i], WR3, colorresistance);
  
  
       P5Buffer[i] = WS1;
       SetPrice("WS1", Time[i], WS1, colorsupport);
       SetText("txtWS1", "WoodieS1                 ", Time[i], WS1, colorsupport);
      
       P6Buffer[i] = WS2;
       SetPrice("WS2", Time[i], WS2, colorsupport);
       SetText("txtWS2", "WoodieS2                 ", Time[i], WS2, colorsupport);
       
        P7Buffer[i] = WS3;
       SetPrice("WS3", Time[i], WS3, colorsupport);
       SetText("txtWS3", "WoodieS3                 ", Time[i], WS3, colorsupport);
       
       //=END SHOW WOODIE PIVOT=
       
       
         //=SHOW WOODIE PIVOT TITLE=
         if (showtitle) 
         {
         ObjectCreate("Woodietext", OBJ_LABEL, 0, 0, 0);
        ObjectSetText("Woodietext","WOODIE PIVOTS", 18, "Arial Bold", White);
        ObjectSet("Woodietext", OBJPROP_CORNER, position);
        ObjectSet("Woodietext", OBJPROP_XDISTANCE, 25);
        ObjectSet("Woodietext", OBJPROP_YDISTANCE, 8);
       
        
        ObjectCreate("Woodiebg", OBJ_LABEL, 0, 0, 0);
        ObjectSetText("Woodiebg", "_________", 28, "Arial", DimGray);
        ObjectSet("Woodiebg", OBJPROP_CORNER, position);
        ObjectSet("Woodiebg", OBJPROP_XDISTANCE, 25);
        ObjectSet("Woodiebg", OBJPROP_YDISTANCE, 1);
        }
       //=END SHOW WOODIE PIVOT TITLE=
     
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetPrice(string name, datetime Tm, double Prc, color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_ARROW, 0, Tm, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, labelsize);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, labelsize);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     } 
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetText(string name, string txt, datetime Tm, double Prc, color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_TEXT, 0, Tm, Prc);
       ObjectSetText(name, txt, textsize, "Verdana", clr);
       ObjectSet(name, OBJPROP_CORNER, 2);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1, Prc);
       ObjectSetText(name, txt, textsize, "Verdana", clr);
       ObjectSet(name, OBJPROP_CORNER, 2);
     } 
  }
//+------------------------------------------------------------------+