Navigation:Home > Content >

pollan-indicator.mq4

Time: 2012-06-02 | Download file:pollan-indicator.mq4

//+------------------------------------------------------------------+
//|                                             pollan-indicator.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Red
//---- input parameters
extern int CountBars=1000;//70000
extern int nPeriod=15;
extern int CCI1Period=15;
extern int CCI2Period=15;
extern int RSI1Period=15;
extern int RSI2Period=15;
double CCI1Mul=1;
double CCI2Mul=1;
double RSI1Mul=1;
double RSI2Mul=1;
int CCI1PriceMax=0;
int CCI1PriceMin=0;
int CCI2PriceMax=0;
int CCI2PriceMin=0;
int RSI1PriceMax=0;
int RSI1PriceMin=0;
int RSI2PriceMax=0;
int RSI2PriceMin=0;
string ind1valtype1="max";
string ind1valopr="+";
string ind1valtype2="min";
double ind1valMul=1;
string ind2valtype1="max";
string ind2valopr="+";
string ind2valtype2="min";
double ind2valMul=-1;

double cci[];
double rsi[];
double val[];
double valMin=0;
double valMax=0;
double indval1=0;
double indval2=0;
int i=0, pix=0, StartBar=0;

//---- buffers
double value[];
double value2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(0,value);
   SetIndexBuffer(1,value2);
   ArrayResize(cci,nPeriod);
   ArrayResize(rsi,nPeriod);
   ArrayResize(val,nPeriod);
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start(){
int counted_bars=IndicatorCounted();

indi();


return(0);
}

void CalcVal(int vCCIPeriod=0, int vCCIPrice=0, double vCCIMul=0, int vRSIPeriod=0, int vRSIPrice=0, double vRSIMul=0, int indNo=0){
 for(pix = 0; pix <= nPeriod-1; pix++){
  val[pix]=0;
 }

 cci[0]=(iCCI(Symbol(),0,vCCIPeriod,vCCIPrice,i-1)*vCCIMul)/100;
 rsi[0]=(iRSI(Symbol(),0,vRSIPeriod,vRSIPrice,i+1)*vRSIMul)/100;
 
 val[0]=(cci[0]-rsi[0]);
 
 for(pix = 1; pix <= nPeriod-1; pix++){
  cci[pix]=(iCCI(Symbol(),0,vCCIPeriod,vCCIPrice,i-pix-1)*vCCIMul)/100;
  rsi[pix]=(iRSI(Symbol(),0,vRSIPeriod,vRSIPrice,i+pix+1)*vRSIMul)/100;

  val[pix]=(cci[pix]-rsi[pix]);  
  val[pix]=val[pix]+val[pix-1];
 }
}

double CalcValResult(string valtype1, string valopr, string valtype2, double valMul, int indNo=0){
 double v=0, v1=0, v2=0;
 
 if (valtype1 == "")return(0);
 
 if (valtype1=="max")v1=valMax;else
 if (valtype1=="min")v1=valMin;else v1=0;

 if (valtype2=="max")v2=valMax;else
 if (valtype2=="min")v2=valMin;else v2=0;

 if (valopr != ""){
  if (valopr == "+")v=v1+v2;else
  if (valopr == "-")v=v1-v2;else
  if (valopr == "/")v=v1/v2;else
  if (valopr == "*")v=v1*v2;
 } else v = v1;
 
 v= v*valMul;
 
 return(v);
}

void indi(){
value[i]=0;
value2[i]=0;

int counted_bars=IndicatorCounted();

//---- check for possible errors

if (counted_bars<0) return(-1);

if(Bars<=nPeriod) return(-1);

//---- last counted bar will be recounted

if (counted_bars>0) counted_bars--;

//---- initial zero
if(counted_bars=0; i--){
 //IND1 VAL
 valMax = 0;
 valMin = 0;
 CalcVal(CCI1Period, CCI1PriceMax, CCI1Mul, RSI1Period, RSI1PriceMax, RSI1Mul, 1);

 valMax = val[0];
 valMin = val[0];
 for(pix = 1; pix <= nPeriod-1; pix++) if (val[pix] > valMax) valMax = val[pix];
 for(pix = 1; pix <= nPeriod-1; pix++) if (val[pix] < valMin) valMin = val[pix];
 indval1=CalcValResult(ind1valtype1, ind1valopr, ind1valtype2, ind1valMul, 1);
 //END: IND1 VAL
 
 //IND2 VAL
 valMax = 0;
 valMin = 0;
 CalcVal(CCI2Period, CCI2PriceMax, CCI2Mul, RSI2Period, RSI2PriceMax, RSI2Mul, 2);

 valMax = val[0];
 valMin = val[0];
 for(pix = 1; pix <= nPeriod-1; pix++) if (val[pix] > valMax) valMax = val[pix];
 for(pix = 1; pix <= nPeriod-1; pix++) if (val[pix] < valMin) valMin = val[pix];
 indval2=CalcValResult(ind2valtype1, ind2valopr, ind2valtype2, ind2valMul, 2);
 //END: IND2 VAL
 
 value[i]=indval1;
 value2[i]=indval2;
}  
}
//+------------------------------------------------------------------+

Recommend