//+------------------------------------------------------------------+
//| HiLoAvg.mq4                                                         
//| Shows yesterday's Hi, Lo and Avg on the chart
//+------------------------------------------------------------------+
/*
Name := HiLoAvg
Author := Rob Judd
Link := 
*/

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 SkyBlue
#property indicator_color3 Yellow

//---- input parameters
extern bool show_comment=true;
extern int length=1000;         // bars to be counted (0 = all bars)

//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

int init()
{
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetIndexStyle(2, DRAW_LINE);
   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   int count, num_bars, prev_day, cur_day = 0;
   double day_high, day_low, H, A, L = 0;

   if (Period() >= PERIOD_D1) {
      return(0);
   }

   if ((length == 0) || (length > Bars))
      num_bars = Bars;
   else
      num_bars = length;

   for (count=num_bars;count>=0;count--) {
      cur_day = TimeDay(Time[count]);

      if (prev_day != cur_day) {

         H = day_high;
         A = (day_high + day_low) * 0.5;
         L = day_low;

         day_high = High[count];
         day_low = Low[count];

         prev_day = cur_day;
      }

      day_high = MathMax(day_high, High[count]);
      day_low = MathMin(day_low, Low[count]);

      ExtMapBuffer1[count] = H;
      ExtMapBuffer2[count] = A;
      ExtMapBuffer3[count] = L;
   }

   if (show_comment)
      Comment("Yesterday\'s Hi=", H, ", Mid=", A, ", Lo=", L, ", Range=", (H-L)/Point, " pips" );

   return(0);
}


