//+------------------------------------------------------------------+
//|                                       Sniper + MA                |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004, Fx Sniper."
#property  link      "http://www.dunno.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 8
#property  indicator_color1  Yellow
#property  indicator_color2  DarkOrchid
#property  indicator_color3  DarkOrchid
#property  indicator_color4  Orange
#property  indicator_color5  Lime
#property  indicator_color6  Red
#property  indicator_color7  Red
#property  indicator_color8  Blue


extern int CCI_period=15;
extern int Bollinger_period=13;
extern int Bollinger_deviation = 2;
extern int Bollinger_shift = 0;
//----
extern string MA1            = "The input parameters of the 1st Moving Average";
//----
extern int    MA1_Period     = 5;                // Averaging period.
extern int    MA1_Mode       = MODE_EMA;          // Averaging method.
extern int    MA1_Price      = PRICE_MEDIAN;      // The type of the price used for calculaton of Moving Average.
//----
extern string MA2            = "The input parameters of the 2nd Moving Average";
//----
extern int    MA2_Period     = 13;
extern int    MA2_Mode       = MODE_EMA;
extern int    MA2_Price      = PRICE_MEDIAN;


//---- indicator buffers
double MainCCI[];
double BUpper[];
double BLower[];
double BMain[];
double cciHup[];
double cciHdn[];

double MAshort[];
double MAlong[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(10);
   
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_LINE,STYLE_DOT,1);
   SetIndexStyle(4,DRAW_HISTOGRAM,0,1);
   SetIndexStyle(5,DRAW_HISTOGRAM,0,1);  
   SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,2);
   SetIndexStyle(7,DRAW_LINE,STYLE_SOLID,2);

   
   SetIndexBuffer(0,MainCCI);
   SetIndexLabel(0,"CCI Indicator");
   SetIndexBuffer(1,BUpper);
   SetIndexBuffer(2,BLower);
   SetIndexBuffer(3,BMain);
   SetIndexLabel(3,"Bollinger Median Line");
   SetIndexBuffer(4,cciHup);
   SetIndexBuffer(5,cciHdn);   
   SetIndexBuffer(6,MAshort);
   SetIndexLabel(6, "MAshort");
   SetIndexBuffer(7,MAlong);  
   SetIndexLabel(7, "MAlong");


     
   
//---- name for DataWindow and indicator subwindow label
 IndicatorShortName("FX Sniper CCI with Bollinger Bands MA ");
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int i;
   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;
 
//---- main loop
   for(i=0; i<Bars; i++)
   {
     MainCCI[i]= iCCI(NULL,0,CCI_period,PRICE_TYPICAL,i);
    }
    
    
     for(i=0; i<Bars; i++)
     {
      MAshort[i]=iMAOnArray(MainCCI,i,MA1_Period,0,MODE_SMA,bar);
      MAlong[i]=iMAOnArray(MainCCI,i,MA2_Period,0,MODE_SMA,bar);
     }
     
     
//---- done

   for(i=0; i<Bars; i++)
   {  
     BLower[i] = iBandsOnArray(MainCCI,0,Bollinger_period,Bollinger_deviation,Bollinger_shift,MODE_LOWER,i); 
     BUpper[i] = iBandsOnArray(MainCCI,0,Bollinger_period,Bollinger_deviation,Bollinger_shift,MODE_UPPER,i); 
     BMain[i] = iBandsOnArray(MainCCI,0,Bollinger_period,Bollinger_deviation,Bollinger_shift,MODE_MAIN,i); 
   }
   
     for(i=0; i<Bars; i++)
   {
     if (MainCCI[i] >= 0 )
      cciHup[i] = MainCCI[i];
     else
      cciHup[i] = 0;
      
       }
    for(i=0; i<Bars; i++)
   {
      
     if (MainCCI[i] < 0 )
      cciHdn[i] = MainCCI[i];
     else
      cciHdn[i]=0; 
   }
   
   
   return(0);
  }
  
