CCI Indicator and CCI EA values don't Match

 
Hello To All,

What I have here is a Simple Indicator that calls iCCI and when I put that on a Chart it shows the same values each bar as the MT default CCI indicator.

When I call iCCI from an EA and print the values to the Journal every bar has a different value form the Indicator except first bar.

Here is the Simple Indicator
//+------------------------------------------------------------------+
//|                                                     Test CCI.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       Length=14;
//---- buffers
double ExtMapBuffer1[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int i = 0;
   
   i = Bars-Length-1;
   while ( i > 0 )
   {
      ExtMapBuffer1[i] = iCCI(NULL,0,Length,PRICE_TYPICAL,i);   
      i--;
   }
   return(0);
}
//+------------------------------------------------------------------+



And here is the simple EA that is calling iCCI

//+------------------------------------------------------------------+
//|                                                  Test CCI EA.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//---- input parameters
extern int       Length=14;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   double Temp1 = 0.0;
   
   Temp1 = iCCI(NULL,0,Length,PRICE_TYPICAL,0);
   Print(Temp1);
   return(0);
  }
//+------------------------------------------------------------------+



What am I doing wrong?
Thank you for your Time
EK

 
What I am asking here is

1). Am I doing something wrong and thats why the values do not match

2). The Values between the CCI Indicator and CCI EA Should not match

3). There is a Bug in the Software

What is the Answer?
Thank you for your Time
EK
 
What I am asking here is

1). Am I doing something wrong and thats why the values do not match

2). The Values between the CCI Indicator and CCI EA Should not match

3). There is a Bug in the Software

What is the Answer?
Thank you for your Time
EK

If I understand your problem correctly, you are monitoring current bar "0" in both Indicator and Expert Adviser.
In that case the loop while(i>0) will never produce i=0;
So you should modify while(i>-1) to get i=0 same as i=0 in the Expert Adviser.
I would put i into the Print statement because I believe that there will be i=1, i=0, in the indicator and i=0 in the expert only.
 
Hello Sub,

Thanks for taking the time to respond to my post. I have read what you have posted and I have looked at the values using the 'while(i>-1)' suggestion.

My Problems all stem from not calling CCI on the completion of each bar I was calling it on each tick.

Thank you
EK
 
This syntex  Temp1 = iCCI(NULL,0,Length,PRICE_TYPICAL,0);    
How to CAlls Syntex     Temp1 = (Highprice-LowPrice) 
 
Record broken! Answer to a 11 years old topic
 
Alain Verleyen:
Record broken! Answer to a 11 years old topic
MQL5.com was available that time?
 
Mohammad Soubra:
MQL5.com was available that time?
No. Some old forum topics were imported here.
Reason: