Can anybody tell me whats wrong with this indicator

To add comments, please log in or register
hhemmat
30
hhemmat  

Hi

I tried to write an indicator to show two CCI graph on the same window

It works but values are different from single CCI indicators with the same period.

I attached the code. It is very simple but numbers that displays are wrong.

Appreciate your help.

//+------------------------------------------------------------------+
//|                                                 D-PERIOD-CCI.mq4 |
//|                                       Copyright © 2019, H.HEMMAT |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Hojjat Hemmat"
#property link      "http://www.Hojjat Hemmat.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_level1 100
#property indicator_level2 0
#property indicator_level3 -100

extern int CCIperiod1=20;
extern int CCIperiod2=4;
extern int applied_price=0;


double Buffer1[],Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0,Buffer1);
   SetIndexStyle(0,DRAW_LINE,EMPTY,2);
   SetIndexBuffer(1,Buffer2);
   SetIndexStyle(1,DRAW_LINE,EMPTY,2);
   IndicatorShortName("DPCCI("+CCIperiod1+" + "+CCIperiod2+")");
   SetIndexLabel(0,CCIperiod1);
   SetIndexLabel(1,CCIperiod2);
  return(0);
  }

int start()
  {
   int    i,limit,counted_bars=IndicatorCounted();
 
   limit=Bars-counted_bars;
   for(i=0;i<limit;i++)
   {
   Buffer1[i]=iCCI(NULL,PERIOD_CURRENT,CCIperiod1,applied_price,i) ; 
   Buffer2[i]=iCCI(NULL,PERIOD_CURRENT,CCIperiod2,applied_price,i) ;   
   }  
   return(0);
  }
//+------------------------------------------------------------------+
Seng Joo Thio
181
Seng Joo Thio  
hhemmat:

Hi

I tried to write an indicator to show two CCI graph on the same window

It works but values are different from single CCI indicators with the same period.

I attached the code. It is very simple but numbers that displays are wrong.

Appreciate your help.

Er... check the value of your applied_price.

hhemmat
30
hhemmat  
Seng Joo Thio:

Er... check the value of your applied_price.

Thanks for your care.

But I didn't get your point. The value of applied_price is 0 that is equal to PRICE_CLOSE.

CCI uses different applied price or something else?

Seng Joo Thio
181
Seng Joo Thio  
hhemmat:

Thanks for your care.

But I didn't get your point. The value of applied_price is 0 that is equal to PRICE_CLOSE.

CCI uses different applied price or something else?

Well, on my metatrader terminals all CCI uses PRICE_TYPICAL, which is 5.

To add comments, please log in or register