//buy MAXOU888

#property copyright "MAXOU888"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 6

#property indicator_color1 Red
#property indicator_color2 Blue    //up band
#property indicator_color3 Blue  //mid band
#property indicator_color4 Blue    //lowband band
#property indicator_color5 Yellow  //mid band
#property indicator_color6 Yellow    //lowband band

extern int     RsiPeriod    =    8;
extern int     BBperiod     =    20;
extern double  Dev          =    2;
int CountBars=500;
int HHLLPeriod=5;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double HighestRsi[];
double LowestRsi[];

int init()
 {

   SetIndexStyle(0,DRAW_LINE);  
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   
   SetIndexBuffer(0,ExtMapBuffer1); // Indic
   SetIndexBuffer(1,ExtMapBuffer2); // BB Up
   SetIndexBuffer(2,ExtMapBuffer3); // BB Mid
   SetIndexBuffer(3,ExtMapBuffer4); // BB LowUp
   SetIndexBuffer(4,HighestRsi);//Max
   SetIndexBuffer(5,LowestRsi);//Min

   return(0);
 }

//----


int start()
 {
   int   counted_bars=IndicatorCounted();
   int   i,limit;
   limit=Bars-counted_bars;
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   
   
   for(i=limit; i>=0; i--)   

   ExtMapBuffer1[i]=iRSI(NULL,0,RsiPeriod,PRICE_CLOSE,i);

   
   for(i=limit; i>=0; i--) 
   {
   ExtMapBuffer2[i]=iBandsOnArray(ExtMapBuffer1,0,BBperiod,Dev,0,MODE_UPPER,i);
   ExtMapBuffer3[i]=iBandsOnArray(ExtMapBuffer1,0,BBperiod,Dev,0,MODE_MAIN, i);
   ExtMapBuffer4[i]=iBandsOnArray(ExtMapBuffer1,0,BBperiod,Dev,0,MODE_LOWER,i);
    
   }



   if(Bars<=100) return(0);
   if (CountBars>Bars-1) CountBars=Bars-1;
   int j=CountBars-MathMax(HHLLPeriod,RsiPeriod);
   while(j>=0)
     {
   ExtMapBuffer1[j]=iRSI(NULL,0,RsiPeriod,PRICE_CLOSE,j);
     
      double max=-1000000;
      double min=1000000;
      int k = j + HHLLPeriod-1;
      while(k>=j)
        {
         if(max<ExtMapBuffer1[k]) max=ExtMapBuffer1[k];
         if(min>ExtMapBuffer1[k]) min=ExtMapBuffer1[k];
         k--;
        }
    
     HighestRsi[j]=max;
     LowestRsi[j]=min;

     j--;
     }








 
   return(0);
 }

//----