Navigation:Home > Content >

CCI_EMA.mq4

Time: 2012-11-21 | Download file:CCI_EMA.mq4

#property copyright "Copyright © 2009, Lakshmi Inc"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Blue


extern int MA_Period=7;
extern int MA_Shift=0;
double ExtMapBuffer[];

extern int CCI_Period=12;
extern int CCI_Timeframe=0;
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
int    draw_begin;
   string short_name="CCI EMA (";
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,MA_Shift);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   if(MA_Period<2) MA_Period=13;
   draw_begin=MA_Period-1;
//---- indicator short name
   IndicatorShortName(short_name+MA_Period+")"+"CCI Period("+CCI_Period+")");
   SetIndexDrawBegin(0,draw_begin);
//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer);


//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double pr=2.0/(MA_Period+1);
   int    pos=Bars-2;
   if(ExtCountedBars>2) pos=Bars-ExtCountedBars-1;
//---- main calculation loop
   while(pos>=0)
     {
      if(pos==Bars-2) 
      ExtMapBuffer[pos+1]=iCCI(Symbol(),CCI_Timeframe,8,PRICE_CLOSE,pos+1);
      ExtMapBuffer[pos]=iCCI(Symbol(),CCI_Timeframe,CCI_Period,PRICE_CLOSE,pos)*pr+ExtMapBuffer[pos+1]*(1-pr);
 	   pos--;
 	  }
  }
//+------------------------------------------------------------------+

Recommend