//+------------------------------------------------------------------+ //| Custom CCI.mq4 | //| Copyright © 2010, MetaQuotes Software Corp. | //| http://codebase.mql4.com/ | //| Made in Russia. Modification by Victor Lukashuk aka lukas1 | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, MetaQuotes Software Corp." #property link "lukas1@ngs.ru" //---- indicator settings #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 LightSeaGreen #property indicator_color2 Black #property indicator_maximum 300 #property indicator_minimum -300 #property indicator_level1 -100 #property indicator_level2 0 #property indicator_level3 100 #property indicator_levelcolor LightSlateGray //---- indicator parameters extern int MA=6; extern int mode =3; /*MODE_SMA 0 Простое скользящее среднее MODE_EMA 1 Экспоненциальное скользящее среднее MODE_SMMA 2 Сглаженное скользящее среднее MODE_LWMA 3 Линейно-взвешенное скользящее среднее */ extern int price=5; /*PRICE_CLOSE 0 Цена закрытия PRICE_OPEN 1 Цена открытия PRICE_HIGH 2 Максимальная цена PRICE_LOW 3 Минимальная цена PRICE_MEDIAN 4 Средняя цена, (high+low)/2 PRICE_TYPICAL 5 Типичная цена, (high+low+close)/3 PRICE_WEIGHTED 6 Взвешенная цена закрытия, (high+low+close+close)/4 */ extern int CCI=14; //---- indicator buffers double Buf0[]; double Buf1[]; double Buf2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { if(MA<1) MA=1; IndicatorDigits(1); IndicatorBuffers(3); //---- indicator buffers mapping SetIndexBuffer(0,Buf0); SetIndexBuffer(1,Buf1); SetIndexBuffer(2,Buf2); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(0,MA+CCI); SetIndexDrawBegin(1,MA+CCI); SetIndexDrawBegin(2,MA+CCI); //---- name for DataWindow and indicator subwindow label IndicatorShortName("CCI-OnArray (CCI("+CCI+"),Ma("+MA+") ) "); SetIndexLabel(0,"CCI("+CCI+"),Ma("+MA+") \n"); SetIndexLabel(1,NULL); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| Moving Averages Convergence/Divergence | //+------------------------------------------------------------------+ int start() { int limit,i; int counted_bars = IndicatorCounted(); if(counted_bars < 0) return(-1); if(counted_bars > 0) counted_bars--; limit = Bars - counted_bars; if(counted_bars==0) limit--; //---- MA counted in the last buffer for(i=limit; i>=0; i--) Buf2[i]=iMA(NULL,0,MA,0,mode,price,i); //---- CCI counted in the free buffer for(i=limit; i>=0; i--){ Buf0[i]=iCCIOnArray(Buf2,Bars,CCI,i); Buf1[i]=iCCIOnArray(Buf2,Bars,CCI,i); } //---- done return(0); } //+------------------------------------------------------------------+