//+------------------------------------------------------------------+
//| 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(Bars<CacdPeriod) return(0);
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
k=Bars-counted_bars;
if(counted_bars==0) k-=1+CacdPeriod;
if (k<CacdPeriod) return;
while(k>=0)
{
for(i=CacdPeriod;i>0;i--)
{
if(Close[k+i]<Open[k+i])
{
a++;
c+=MathAbs(Close[k+i]-Open[k+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);
}
//+------------------------------------------------------------------+
Comments