//+------------------------------------------------------------------+
//|                                                    Stretched.mq4 |
//|                                                        JMF       |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "JMP"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2  Red
#property indicator_color3  Green 
#property indicator_width1 0
#property indicator_width2 2
#property indicator_width3 2
#property indicator_minimum 0
#property indicator_maximum 1
//----
extern int Stoch_Period = 375;
extern int Signal_Period = 3;
extern int Slowing = 3; 
 int T3_Period = 1;
 double b = 0.618;
extern int Upper_Threshold = 99;
extern int Lower_Threshold = 1; 
//----
double e1, e2, e3, e4, e5, e6;
double c1, c2, c3, c4;
double n, w1, w2, b2, b3;
double cci[];
double cciHup[];
double cciHdn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators setting
    SetIndexBuffer(0, cci);
    SetIndexBuffer(1, cciHup);
    SetIndexBuffer(2, cciHdn);
//----
    SetIndexStyle(0, DRAW_NONE);
    SetIndexStyle(1, DRAW_HISTOGRAM);
    SetIndexStyle(2, DRAW_HISTOGRAM);
//----        
    IndicatorShortName("Stretched");
    SetIndexLabel(0, "Stretched");     
   SetIndexLabel(1, NULL);
   SetIndexLabel(2, NULL);   
   
//----
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;  
//---- indicator calculation
   for(int i = Bars - 1; i >= 0; i--)
     {   
       cci[i] = iStochastic(NULL,0,Stoch_Period,Signal_Period,Slowing,MODE_SMA,0,MODE_MAIN,i);  
       //----
       if(cci[i] >= Upper_Threshold)
           cciHup[i] = 1;//cci[i];
       else
           cciHup[i] = 0;   
       //----
       if(cci[i] <= Lower_Threshold)
           cciHdn[i] = 1;//cci[i];
       else
           cciHdn[i] = 0; 
     }   
//----
   return(0);
  }
//+------------------------------------------------------------------+

