//+------------------------------------------------------------------+ //| CACD.mq4 | //| Fedor Igumnov | //| igumnovfedor@yandex.ru | //+------------------------------------------------------------------+ #property copyright "Fedor Igumnov" #property link "igumnovfedor@yandex.ru" #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 DodgerBlue #property indicator_level1 0 //#property indicator_minimum -0.1 //#property indicator_maximum 0.1 extern int CacdPeriod=30; //--- buffers double Cacd[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string short_name; //---- indicators IndicatorBuffers(1); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(0,Cacd); short_name="CACD("+CacdPeriod+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- SetIndexDrawBegin(0,CacdPeriod); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i,k; double a,b,c,d=0; //--- if(Bars0) counted_bars--; k=Bars-counted_bars; if(counted_bars==0) k-=1+CacdPeriod; if (k=0) { for(i=CacdPeriod;i>0;i--) { if(Close[k+i]Open[k+i]) { b++; d+=MathAbs(Close[k+i]-Open[k+i]); } } if (b!=0 && d!=0) Cacd[k]=(a/b)-(c/d); else Cacd[k]=0; k--; // a=0; // b=0; // c=0; // d=0; } //---- return(0); } //+------------------------------------------------------------------+