Navigation´╝ÜHome > Content >

laguerre_cci.mq4

Time: 2010-02-01 | Download file:laguerre_cci.mq4

//+------------------------------------------------------------------+
//|                                                 laguerre cci.mq4 |
//|                       Copyright ?2010, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Aqua
#property indicator_width1 3



extern double Gama          = 0.70;
extern int     Price             = 4; 
extern int     T3Period          = 14;
extern bool    T3Average         = false;
extern double  T3Hot             = 0.70;
extern bool    T3Original        = false;



double cci[];
double emas[][6];
double alpha;
double c1;
double c2;
double c3;
double c4;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators setting
    SetIndexBuffer(0,cci);
    SetIndexStyle(0,DRAW_LINE);
    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
    IndicatorShortName("T3_ CCI "+"laguerre");
    
    

//---- variable reset

    double a  = T3Hot;
             c1 = -a*a*a;
             c2 =  3*(a*a+a*a*a);
             c3 = -3*(2*a*a+a+a*a*a);
             c4 = 1+3*a+a*a*a+3*a*a;

      T3Period = MathMax(1,T3Period);
      if (T3Original)
           alpha = 2.0/(1.0 + T3Period);
      else alpha = 2.0/(2.0 + (T3Period-1.0)/2.0);

   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

  int start()
{
   int    counted_bars=IndicatorCounted();
   int    pos,limit;

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
         limit = Bars-counted_bars;
         if (ArrayRange(emas,0) != Bars) ArrayResize(emas,Bars);
          
   //
   //
   //
   //
   //
   
   for(int i = limit; i >= 0; i--)
     {   
     cci[i] = iT3(iCCI(NULL,0,Gama,Price,i),i);   
     }   
   return(0);
}
//+------------------------------------------------------------------+

double iT3(double price,int shift)
{
   int i = Bars-shift-1;
   if (i < 1)
      {
         emas[i][0] = price;
         emas[i][1] = price;
         emas[i][2] = price;
         emas[i][3] = price;
         emas[i][4] = price;
         emas[i][5] = price;
      }
   else
      {
         emas[i][0] = emas[i-1][0]+alpha*(price     -emas[i-1][0]);
         emas[i][1] = emas[i-1][1]+alpha*(emas[i][0]-emas[i-1][1]);
         emas[i][2] = emas[i-1][2]+alpha*(emas[i][1]-emas[i-1][2]);
         emas[i][3] = emas[i-1][3]+alpha*(emas[i][2]-emas[i-1][3]);
         emas[i][4] = emas[i-1][4]+alpha*(emas[i][3]-emas[i-1][4]);
         emas[i][5] = emas[i-1][5]+alpha*(emas[i][4]-emas[i-1][5]);
      }
   return(c1*emas[i][5] + c2*emas[i][4] + c3*emas[i][3] + c4*emas[i][2]);
}

Recommend