Navigation´╝ÜHome > Content >

cci_histogram2.mq4

Time: 2012-09-13 | Download file:cci_histogram2.mq4

//+------------------------------------------------------------------+
//|                                                CCI_Histogram.mq4 |
//|                                                      Robert Hill |
//| CCI as a histogram                                               |
//+------------------------------------------------------------------+
#property  copyright "Robert Hill"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Green
#property  indicator_color2  Red
#property indicator_color3 Yellow
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

//---- indicator parameters
extern int CCI_Period=14;
extern int ThreshHoldLevel = 50;
//---- indicator buffers
double High_CCI[];
double Low_CCI[];
double Mid_CCI[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 3 additional buffers are used for counting.
//   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexDrawBegin(0,CCI_Period);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 2 indicator buffers mapping
   if(!SetIndexBuffer(0,High_CCI) &&
      !SetIndexBuffer(1,Low_CCI) &&
      !SetIndexBuffer(2,Mid_CCI))
      Print("cannot set indicator buffers!");
      
   IndicatorDigits(4);
   
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("CCI("+CCI_Period+","+ThreshHoldLevel+")");

//---- initialization done
   return(0);
  }


//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
int start()
{
   int limit,i;
   int counted_bars=IndicatorCounted();
   double CCI;
   int barToCheck;
   
//---- 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=ThreshHoldLevel){
         High_CCI[i]=CCI;
         Low_CCI[i]=0;
         Mid_CCI[i]=0;
      }else if(CCI<-ThreshHoldLevel){
         Low_CCI[i]=CCI;
         High_CCI[i]=0;
         Mid_CCI[i] = 0;
      }else{
         Mid_CCI[i] = CCI;
         Low_CCI[i]=0;
         High_CCI[i]=0;
      }
   }
   
      
//---- done
   return(0);
  }

//+------------------------------------------------------------------+

Recommend