#property copyright "TRENDPOWER"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

//
//
//
//
//

extern int Lb = 6;

double hi[];
double lo[];
double Hlv[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//
//
//
//
//

int init()
{
   IndicatorBuffers(3);
   SetIndexBuffer(0,hi); SetIndexDrawBegin(0,Lb+1); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,lo); SetIndexDrawBegin(1,Lb+1); SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,Hlv);
   return(0);
}

//
//
//
//
//

int start()
{
   int counted_bars=IndicatorCounted();
   int i,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit=Bars-counted_bars;

   //
   //
   //
   //
   //

   for(i=limit;i>=0;i--)
   {
      Hlv[i] = Hlv[i+1];
         if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1)) Hlv[i] =  1;
         if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1))  Hlv[i] = -1;
      
         if(Hlv[i] == -1)
              { lo[i] = High[i]; hi[i] = Low[i]; }
         else { hi[i] = High[i]; lo[i] = Low[i]; }
   }
   return(0);
}