//+------------------------------------------------------------------+
//|                                           Brooky_Stoch_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 5
#property indicator_color1 SteelBlue
#property indicator_color2 OrangeRed
#property indicator_color3 Gold
#property indicator_color4 Blue

#property indicator_width1 5
#property indicator_width2 5
#property indicator_width3 5
#property indicator_width4 2
#property indicator_width5 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 = "+Brooky-Indicators.com+";
extern string settings = "+--Select Period & Levels--+";
extern int       Stoch_k=14;
extern int       Stoch_s=5;
extern int       Stoch_d=5;
extern int       Rsi=14;

extern int       OBought=80;
extern int       OSold=20;
extern string colors = "+--Select Colors for Levels--+";
extern color oblevel = Blue;
extern color oslevel = Red;
//---- buffers
double stochbuff[];
double sigbuff[];
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,stochbuff);

   SetIndexStyle(4,DRAW_LINE);SetIndexBuffer(4,sigbuff);
      
   IndicatorShortName("Brooky_StochRsi_Shade ("+Stoch_k+")");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
    ObjectDelete("stob");
        ObjectDelete("stos");
//----
   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;
     
     
   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;
       stochbuff[i]=EMPTY_VALUE;
       sigbuff[i]=EMPTY_VALUE;
       
       double rsinow=iRSI(NULL,0,Rsi,PRICE_CLOSE,i);
       double stochnow=iStochastic(NULL,0,Stoch_k,Stoch_s,Stoch_d,MODE_SMA,0,MODE_MAIN,i);
       sigbuff[i]=iStochastic(NULL,0,Stoch_k,Stoch_s,Stoch_d,MODE_SMA,0,MODE_SIGNAL,i);
       
       
       stochbuff[i]=(stochnow+rsinow)/2;
       
       if(stochnow<=OSold)
              {
                obbuff[i]   =EMPTY_VALUE;
                osbuff[i]   =OSold;
                blankbuff[i]=stochnow;
              }
       if(stochnow>=OBought)
              {
                obbuff[i]   =stochnow;
                osbuff[i]   =EMPTY_VALUE;
                blankbuff[i]=OBought;
              }
       string obline = "stob";
              int windowIndex=WindowFind("Brooky_StochRsi_Shade ("+Stoch_k+")");
              ObjectDelete("stob"+i);
              ObjectCreate(obline, OBJ_HLINE, windowIndex, Time[i],OBought);
              ObjectSet(obline, OBJPROP_STYLE, 1);
              ObjectSet(obline, OBJPROP_COLOR,oblevel);       
       string osline = "stos";
              int windowIndex2=WindowFind("Brooky_StochRsi_Shade ("+Stoch_k+")");
              ObjectDelete("stos"+i);
              ObjectCreate(osline, OBJ_HLINE, windowIndex2, Time[i],OSold);
              ObjectSet(osline, OBJPROP_STYLE, 1);
              ObjectSet(osline, OBJPROP_COLOR,oslevel);        
       }
  //---- done
     return(0);
    }
//+------------------------------------------------------------------+