Code:
//+------------------------------------------------------------------+
//| CCI Bar.mq4 |
//| Par Remjie |
//| |
//+------------------------------------------------------------------+
#property copyright "By Remjie"
#property indicator_separate_window
#property indicator_buffers 8
#property indicator_minimum 0
#property indicator_maximum 5
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_color5 Green
#property indicator_color6 Red
#property indicator_color7 Green
#property indicator_color8 Red
//---- input parameters
extern int CCIPeriod=8;
extern int TimeFrame1=5;
extern int TimeFrame2=15;
extern int TimeFrame3=30;
extern int TimeFrame4=60;
int TF1;
int TF2;
int TF3;
int TF4;
int PTF1;
int PTF2;
int PTF3;
int PTF4;
double CCI1;
double CCI2;
double CCI3;
double CCI4;
//---- buffers
double CCI1up[];
double CCI2up[];
double CCI3up[];
double CCI4up[];
double CCI1dn[];
double CCI2dn[];
double CCI3dn[];
double CCI4dn[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicateurs
IndicatorBuffers(4);
//---- additional buffers
SetIndexStyle(0, DRAW_ARROW);
SetIndexBuffer(0, CCI1up);
SetIndexArrow(0,110);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1, DRAW_ARROW);
SetIndexBuffer(1, CCI1dn);
SetIndexArrow(1,110);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2, DRAW_ARROW);
SetIndexBuffer(2, CCI2up);
SetIndexArrow(2,110);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3, DRAW_ARROW);
SetIndexBuffer(3, CCI2dn);
SetIndexArrow(3,110);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4, DRAW_ARROW);
SetIndexBuffer(4, CCI3up);
SetIndexArrow(4,110);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5, DRAW_ARROW);
SetIndexBuffer(5, CCI3dn);
SetIndexArrow(5,110);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6, DRAW_ARROW);
SetIndexBuffer(6, CCI4up);
SetIndexArrow(6,110);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7, DRAW_ARROW);
SetIndexBuffer(7, CCI4dn);
SetIndexArrow(7,110);
SetIndexEmptyValue(7,0.0);
//---- nom
string short_name = "CCI("+CCIPeriod+")";
IndicatorShortName(short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i;
int counted_bars = IndicatorCounted();
// verif erreurs
if (counted_bars < 0) return (-1);
// recompte la derniere barre
if (counted_bars > 0) counted_bars--;
limit = Bars - counted_bars;
// -- Boucle principale
TF1=TimeFrame1/Period();
TF2=TimeFrame2/Period();
TF3=TimeFrame3/Period();
TF4=TimeFrame4/Period();
PTF1=TF1*CCIPeriod;
PTF2=TF2*CCIPeriod;
PTF3=TF3*CCIPeriod;
PTF4=TF4*CCIPeriod;
for(i = 0; i < limit ; i++)
{
CCI1=iCCI(Symbol(),0,PTF1,0,i);
CCI2=iCCI(Symbol(),0,PTF2,0,i);
CCI3=iCCI(Symbol(),0,PTF3,0,i);
CCI4=iCCI(Symbol(),0,PTF4,0,i);
if (CCI1>0)
{CCI1up[i]=1; CCI1dn[i]=-1;}
if (CCI1<0)
{CCI1dn[i]=1; CCI1up[i]=-1;}
if (CCI2>0)
{CCI2up[i]=2; CCI2dn[i]=-1;}
if (CCI2<0)
{CCI2dn[i]=2; CCI2up[i]=-1;}
if (CCI3>0)
{CCI3up[i]=3; CCI3dn[i]=-1;}
if (CCI3<0)
{CCI3dn[i]=3; CCI3up[i]=-1;}
if (CCI4>0)
{CCI4up[i]=4; CCI4dn[i]=-1;}
if (CCI4<0)
{CCI4dn[i]=4; CCI4up[i]=-1;}
}
//---- fin
return(0);
}
//+------------------------------------------------------------------+