Navigation:Home > Content >

OnChart_cci.mq4

Time: 2010-08-11 | Download file:OnChart_cci.mq4

//------------------------------------------------------------------
//
//------------------------------------------------------------------
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1  clrDodgerBlue
#property indicator_color2  clrGray
#property indicator_color3  clrSandyBrown
#property indicator_color4  clrDodgerBlue
#property indicator_color5  clrSandyBrown
#property indicator_color6  clrSandyBrown
#property indicator_style1  STYLE_DOT
#property indicator_style2  STYLE_DOT
#property indicator_style3  STYLE_DOT
#property indicator_width4  2
#property indicator_width5  2
#property indicator_width6  2
#property strict

//
//
//
//
//

extern int                 CCIPeriod    = 50;             // CCI period
extern ENUM_APPLIED_PRICE  CCIPrice     = PRICE_TYPICAL;  // CCI price
extern double              CCILevel     = 200;            // CCI levels (+ and -, entyer as +)
extern int                 minMaxPeriod = 10;             // Channel period

double upper[], middle[], lower[], value[], valueda[], valuedb[], slope[], orvalue[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//

int init()
{
   IndicatorBuffers(8);
   SetIndexBuffer(0,upper);
   SetIndexBuffer(1,middle);
   SetIndexBuffer(2,lower);
   SetIndexBuffer(3,value);
   SetIndexBuffer(4,valueda);
   SetIndexBuffer(5,valuedb);
   SetIndexBuffer(6,orvalue);
   SetIndexBuffer(7,slope);
   return(0);
}
int deinit() { return(0);  }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//

int start() 
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(Bars-counted_bars,Bars-1);

   if (slope[limit]==-1) CleanPoint(limit,valueda,valuedb);
   for(int i=limit; i>=0; i--)
   {
      double min = Low [ArrayMinimum(Low ,minMaxPeriod,i)];
      double max = High[ArrayMaximum(High,minMaxPeriod,i)];
      double rng = max-min;
      
      upper[i]   =  max;
      lower[i]   =  min;
      middle[i]  = (min+max)/2.0;
      orvalue[i] = iCCI(NULL,0,CCIPeriod,CCIPrice,i);
      value[i]   = middle[i]+rng*(orvalue[i]/(2*CCILevel));
      valueda[i] = EMPTY_VALUE;
      valuedb[i] = EMPTY_VALUE;
      if (iorvalue[i+1]) slope[i] =  1;
            if (orvalue[i]=Bars-3) return;
   if ((second[i]  != EMPTY_VALUE) && (second[i+1] != EMPTY_VALUE))
        second[i+1] = EMPTY_VALUE;
   else
      if ((first[i] != EMPTY_VALUE) && (first[i+1] != EMPTY_VALUE) && (first[i+2] == EMPTY_VALUE))
          first[i+1] = EMPTY_VALUE;
}

void PlotPoint(int i,double& first[],double& second[],double& from[])
{
   if (i>=Bars-2) return;
   if (first[i+1] == EMPTY_VALUE)
      if (first[i+2] == EMPTY_VALUE) 
            { first[i]  = from[i];  first[i+1]  = from[i+1]; second[i] = EMPTY_VALUE; }
      else  { second[i] =  from[i]; second[i+1] = from[i+1]; first[i]  = EMPTY_VALUE; }
   else     { first[i]  = from[i];                           second[i] = EMPTY_VALUE; }
}

Recommend