 //+------------------------------------------------------------------+
//| HighLow_Custom.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Black
#property indicator_color2 Black
#property indicator_color3 Black
#property indicator_color4 Red
#property indicator_color5 Blue

//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];

extern string Time_Frame_value = "0,M1,M5,M15,M30,H1,H4,D1,W1,MN1";
extern string Time_Frame = "W1";

int timeFrame;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {

   if (Time_Frame == "M1") {

      timeFrame = PERIOD_M1;

   } else if (Time_Frame == "M5") {

      timeFrame = PERIOD_M5;

   } else if (Time_Frame == "M15") {

      timeFrame = PERIOD_M15;

   } else if (Time_Frame == "M30") {

      timeFrame = PERIOD_M30;

   } else if (Time_Frame == "H1") {

      timeFrame = PERIOD_H1;

   } else if (Time_Frame == "H4") {

      timeFrame = PERIOD_H4;

   } else if (Time_Frame == "D1") {

      timeFrame = PERIOD_D1;

   } else if (Time_Frame == "W1") {

      timeFrame = PERIOD_W1;

   } else if (Time_Frame == "MN1") {

      timeFrame = PERIOD_MN1;

   } else {

      timeFrame = 0;

   }

   if (timeFrame < Period()) {

      Alert("The timeframe must be higher than the current");
      deinit();

   }

   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(3, ExtMapBuffer4);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexBuffer(4, ExtMapBuffer5);
   SetIndexStyle(4, DRAW_LINE);
   
   return(0);
   
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {

   Comment("");
   return(0);
   
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {

   int shift, i, CurDay, BarCount;
   double DayMax, DayMin;
   double DayOpen, DayClose, Avg,Avg1,Avg2;

   for (shift=Bars-1; shift>=0; shift--) {
   
      int timeFrameIndex = iBarShift(NULL, timeFrame, Time[shift], true);
   
      if (CurDay != iTime(NULL, timeFrame, timeFrameIndex)) {
      
         for (i=BarCount; i>=0; i--) {
         
        {  Avg = (DayMax+DayMin)/2;
          Avg1 = (DayMax+Avg)/2;
          Avg2 = (Avg+DayMin)/2;}
          
          
          
            ExtMapBuffer1[shift+i] = DayMax;
            ExtMapBuffer2[shift+i] = Avg;
            ExtMapBuffer3[shift+i] = DayMin;
            ExtMapBuffer4[shift+i] =Avg1;
            ExtMapBuffer5[shift+i] =Avg2;
            
         }
         
         CurDay = iTime(NULL, timeFrame, timeFrameIndex);
         BarCount = 0;
         DayMax = 0;
         DayMin = 10000;
         DayOpen = Open[shift];
         
      }

      if (DayMax < High[shift]) {
      
         DayMax = High[shift];
         
      }
      
      if (DayMin > Low[shift]) {
      
            DayMin = Low[shift];
            
      }
      
      BarCount = BarCount + 1;
   }

   for (i=BarCount; i>=0; i--) {
    {  Avg = (DayMax+DayMin)/2;
          Avg1 = (DayMax+Avg)/2;
          Avg2 = (Avg+DayMin)/2;}
   
            ExtMapBuffer1[shift+i] = DayMax;
            ExtMapBuffer2[shift+i] = (DayMax+DayMin)/2;
            ExtMapBuffer3[shift+i] = DayMin;
            ExtMapBuffer4[shift+i] =Avg1;
            ExtMapBuffer5[shift+i] =Avg2;
     
   }
   
   DayClose = Close[0];
   Avg = (DayMax+DayMin)/2;
 Comment("   50% ----=  ",Avg,
       "   25%---=  ",Avg1,
        "  75%  ---=  ",Avg2);
   return(0);
   
}
//+------------------------------------------------------------------+ 