//------------------------------------------------------------------
//
//------------------------------------------------------------------

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 clrDarkSeaGreen
#property indicator_color2 clrDarkSeaGreen
#property indicator_color3 clrDarkSeaGreen
#property indicator_color4 clrAqua
#property indicator_color5 clrLime

#property indicator_level1 20
#property indicator_level2 30
#property indicator_level3 50
#property indicator_level4 70
#property indicator_level5 80

#property indicator_levelcolor Red


extern int    RSIPeriod     = 14;
extern int    BandPeriod    = 20;
extern double BandDeviation = 2;//1.3185;

double RSIBuf[],RSIBuf1[],UpZone[],DnZone[],Ma[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int init()
{
    //for (int i=0; i<indicator_buffers; i++) 
      
   SetIndexStyle(0,DRAW_LINE,2,0);
   SetIndexBuffer(0,UpZone);
   SetIndexStyle(1,DRAW_LINE,2,0);
   SetIndexBuffer(1,DnZone);
   SetIndexStyle(2,DRAW_LINE,2,0);
   SetIndexBuffer(2,Ma);
   
   SetIndexStyle(3,DRAW_LINE,0,3);
   SetIndexBuffer(3,RSIBuf);
   SetIndexStyle(4,DRAW_LINE,2,0);
   SetIndexBuffer(4,RSIBuf1);

   
   
   SetLevelStyle(0,0);
   SetLevelStyle(1,0);
   SetLevelStyle(2,0);
   SetLevelStyle(3,0);
   SetLevelStyle(4,0);
   
   return(0);
}
int deinit() { return(0); }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int start()
  
{
   
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);
   
   for(int i=limit; i>=0; i--) RSIBuf[i]  = iRSI(NULL,0,RSIPeriod,PRICE_WEIGHTED,i);
   for(    i=limit; i>=0; i--)
   {
      
      double dev = iStdDevOnArray(RSIBuf,0,BandPeriod,0,MODE_SMA,i);
         Ma[i]     = iMAOnArray(RSIBuf,0,BandPeriod,0,MODE_SMA,i);
         UpZone[i] = Ma[i] + BandDeviation * dev;
         DnZone[i] = Ma[i] - BandDeviation * dev;
         RSIBuf1[i] =RSIBuf[i];
    
     
   }
   return(0);
}