//+------------------------------------------------------------------+
//|                                                    ALL Pivot.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                                  Written by Arul |   
//|                                        http://www.metaquotes.net |                                      
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers   4
#property indicator_color1 clrLightBlue
#property indicator_color2 clrTomato
#property indicator_color3 clrAqua
#property indicator_color4 clrOrange

extern int CountDays= 15;
string  TimePeriod = "D1";
bool    All_pivot = true;
//datetime exp = D'30.06.2018';
   datetime time1, time2, time3;
   double open,close,high,low;
//   double A1,A2,A3,A4,B1,B2,B3,B4,Range;
//   double F,G,I,J,K,L,M,N,O;
   double pstyle, mstyle,cstyle,Hi,Lo;
   int shift, num, period;
 
 

   void ObjDel()
   {
    //  static long chartID = ChartID();         ObjectsDeleteAll(chartID,0, OBJ_TEXT );
      for (  ; num<=CountDays; num++)
      {  
      ObjectDelete("Hi["+num+"]");   ObjectDelete("Lo["+num+"]");   
    }
      
 }

   void PlotLine(string name,double value,double line_color,double style)
   {
   ObjectCreate(name,OBJ_TREND,0,time1,value,time2,value);
   ObjectSet(name, OBJPROP_WIDTH, 1);
   ObjectSet(name, OBJPROP_STYLE, style);
   ObjectSet(name, OBJPROP_RAY, false);
   ObjectSet(name, OBJPROP_BACK, true);
   ObjectSet(name, OBJPROP_COLOR, line_color);
     }        
//========================

//========================
  
   
int init()
  {
   if (TimePeriod=="H1" || TimePeriod=="60") period=PERIOD_H1; 
   else
   if (TimePeriod=="H4" || TimePeriod=="240") period=PERIOD_H4; 
   else
   if (TimePeriod=="D1" || TimePeriod=="1440") period=PERIOD_D1;
   else
   if (TimePeriod=="W1" || TimePeriod=="10080") period=PERIOD_W1; 
   else
   if (TimePeriod=="MN" || TimePeriod=="43200") period=PERIOD_MN1;
   else
   {
   Comment("Wrong TimePeriod. Must be H1, H4, D1, W1 or MN"); 
   return(0);
   }
  return(0);
  }
   
   
int deinit()
  {   ObjDel();   Comment("");   return(0);  }

int start()
  {
  //int i;
 
  ObjDel();  num=0;
  
  for (shift=CountDays-1;shift>=0;shift--) 
  {
  time1=iTime(NULL,period,shift);
             
  high  = iHigh(NULL,period,shift+1);
  low   = iLow(NULL,period,shift+1);
  open  = iOpen(NULL,period,shift+0); //+1
 

   string date=TimeToString(Time[Bars-1],TIME_DATE); 
   for(int i=Bars-1;i>=0;i--){
      
      if(date!=TimeToString(Time[i],TIME_DATE))
      {
         date=TimeToString(Time[i],TIME_DATE);
       double  DH = High[i];
       double  DL  = Low[i];
      }
   
    //do your work with first candle high and low
    }
    Hi= DH; Lo = DL;
  
  //----------------------------------------------------
       
  time2=time1+period*60;
  time3=time2+period*60;
  
         
  pstyle=0;
  mstyle=3;
  cstyle=1;
  num=shift;
         
  if(All_pivot)
  {

PlotLine("Hi["+num+"]",Hi,clrRed,STYLE_SOLID);   
PlotLine("Lo["+num+"]",Lo,clrGreen,STYLE_SOLID);


     }
  }
   return(0);
 }
 
// void Recalc()
// {   if (Time[0] > exp){ Alert("expired"); return; }    }
//+------------------------------------------------------------------+

