//+------------------------------------------------------------------+
//|                                             Brooky_Rsi_Shade.mq4 |
//|                      Copyright � 2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright � 2010, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 SteelBlue
#property indicator_color2 OrangeRed
#property indicator_color3 Gold


#property indicator_width1 5
#property indicator_width2 5
#property indicator_width3 5
#property indicator_width4 2

#property indicator_level1 50

#import "user32.dll"
   int GetDC(int hwnd);
   int ReleaseDC(int hwnd,int hdc);
#import "gdi32.dll"
   color GetPixel(int hdc,int x,int y);

//---- input parameters
extern string NOTE  = "+--DLL Must Be Allowed--+";
extern string NOTE2 = "+--For Auto Clear Backgound--+";
extern string Coder = "+Forex-Indicators.Weebly.com+";
extern string settings = "+--Select Period & Levels--+";
extern int       Rsi_Period=5;
extern int       OBought=70;
extern int       OSold=30;
extern string colors = "+--Select Colors for Levels--+";
extern color oblevel = Blue;
extern color oslevel = Red;
//---- buffers
double rsibuff[];

double obbuff[];

double osbuff[];

double blankbuff[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
   
   SetIndexBuffer(0,obbuff);SetIndexStyle(0,DRAW_HISTOGRAM);
   
   SetIndexBuffer(1,osbuff); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_DOT);
  
   SetIndexBuffer(2,blankbuff); 
  
   SetIndexStyle(3,DRAW_LINE);SetIndexBuffer(3,rsibuff);
   
   IndicatorShortName("Brooky_Rsi_Shade ("+Rsi_Period+")");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    ObjectDelete("ob");
        ObjectDelete("os");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start()
    {
     int limit;
     int counted_bars=IndicatorCounted();
  //---- check for possible errors
     if(counted_bars<0) return(-1);
  //---- the last counted bar will be recounted
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
     double rsinow;
     
   int hwnd=WindowHandle(Symbol(),Period());
   int hdc=GetDC(hwnd);
   color back_ground=GetPixel(hdc,1,2);
   ReleaseDC(hwnd,hdc);
   SetIndexStyle(2,DRAW_HISTOGRAM,0,EMPTY,back_ground);
  //---- main loop
     for(int i=0; i<limit; i++)
       {
       obbuff[i]   =EMPTY_VALUE;
       osbuff[i]   =EMPTY_VALUE;
       blankbuff[i]=EMPTY_VALUE;
       
       rsinow=iRSI(NULL,0,Rsi_Period,PRICE_CLOSE,i);
       
       rsibuff[i]=rsinow;
       
       if(rsinow<=OSold)
              {
                obbuff[i]   =EMPTY_VALUE;
                osbuff[i]   =OSold;
                blankbuff[i]=rsinow;
              }
       if(rsinow>=OBought)
              {
                obbuff[i]   =rsinow;
                osbuff[i]   =EMPTY_VALUE;
                blankbuff[i]=OBought;
              }
       string obline = "ob";
              int windowIndex=WindowFind("Brooky_Rsi_Shade ("+Rsi_Period+")");
              ObjectDelete("ob"+i);
              ObjectCreate(obline, OBJ_HLINE, windowIndex, Time[i],OBought);
              ObjectSet(obline, OBJPROP_STYLE, 1);
              ObjectSet(obline, OBJPROP_COLOR,oblevel);       
       string osline = "os";
              int windowIndex2=WindowFind("Brooky_Rsi_Shade ("+Rsi_Period+")");
              ObjectDelete("os"+i);
              ObjectCreate(osline, OBJ_HLINE, windowIndex2, Time[i],OSold);
              ObjectSet(osline, OBJPROP_STYLE, 1);
              ObjectSet(osline, OBJPROP_COLOR,oslevel);        
       }
  //---- done
     return(0);
    }
//+------------------------------------------------------------------+