//+------------------------------------------------------------------+
//|                                          Day_High_Low_Median.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 MediumBlue
#property indicator_color2 Red
#property indicator_color3 DeepSkyBlue
//---- input parameters
extern int OpenTime=0;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexLabel(0,"High");
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(1,"Low");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(2,"Median");
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(),lastbar,i;
   if (counted_bars>0) {counted_bars--;}
   lastbar= Bars - counted_bars;
   for (i=lastbar; i>=0; i--)
     {
      ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
      ExtMapBuffer2[i]=ExtMapBuffer2[i+1];
      ExtMapBuffer3[i]=ExtMapBuffer3[i+1];
     if (TimeHour (Time[i])==OpenTime) 
      {
         ExtMapBuffer1[i]=High[i];
         ExtMapBuffer2[i]=Low[i];
      }
      ExtMapBuffer1[i]=MathMax(ExtMapBuffer1[i],High[i]);
      ExtMapBuffer2[i]=MathMin(ExtMapBuffer2[i],Low[i]);
      ExtMapBuffer3[i]=(ExtMapBuffer1[i]+ExtMapBuffer2[i])/2;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+