How to code to read value from first indicator's data inside Expert Advisor?

 

Help needed ,

I have a Expert advisor that need to read the crossing of Moving Average from a CCI[14] . I have two Moving average of 2 and 7 which i applied using  first indicator's data to the CCI[14].

From this link https://forum.mql4.com/55157 the only way to read the MA value is to create a custoCCIm indicator and then use iCustom to read the value.

I having problem creating the custom indicator where the lines draw not the same as original. Refer to the diagram below

 

 

 

 I have attached my custom indicator coding below. Anyone can enlighten me what is wrong. How come my Moving average value not the same as the built in original which i drag from Navigator 


 

 

//+------------------------------------------------------------------+

//|                                                       CCI_MA.mq4 |

//|                      Copyright © 2009, MetaQuotes Software Corp. |

//|                                        http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2009, MetaQuotes Software Corp."

#property link      "http://www.metaquotes.net"


#property indicator_separate_window

#property indicator_buffers 3

#property indicator_color1 MediumSpringGreen

#property indicator_color2 Red

#property indicator_color3 Yellow

#property indicator_level1 -100

#property indicator_level2 100

 

//---- input parameters

extern int cci_p = 14;

extern int ma = 7;

extern int ma2 = 2;

int NumberOfBarsToCalculate = Bars-IndicatorCounted();

 

//---- indicator buffers

double Buffer0[];

double Buffer1[];

double Buffer2[];

double Ma[];

double Ma2[];

double Cci[];

 

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

  int init()

  {

   Comment("");

   IndicatorBuffers(6);

//---- indicator line

   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);

   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);

   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);

   SetIndexStyle(3,DRAW_NONE);

   SetIndexStyle(4,DRAW_NONE);

   SetIndexStyle(5,DRAW_NONE);

 

   SetIndexBuffer(0,Buffer0);

   SetIndexBuffer(1,Buffer1);

   SetIndexBuffer(2,Buffer2);

   SetIndexBuffer(3,Cci);

   SetIndexBuffer(4,Ma);

   SetIndexBuffer(5,Ma2);

   

 

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));

//----

 

   SetIndexEmptyValue(0,0);

   SetIndexEmptyValue(1,0);

   SetIndexEmptyValue(2,0);

   SetIndexEmptyValue(3,0);

   SetIndexEmptyValue(4,0);

   SetIndexEmptyValue(5,0);


//----

   return(0);

  }

 

 

int start() {

      string short_name;

      NumberOfBarsToCalculate = Bars-IndicatorCounted();


      short_name = "MyCustom CCI with MA2MA7["+cci_p+"] "; 

      IndicatorShortName(short_name);



        int shift;

         int limit;

         int counted_bars=IndicatorCounted();

         

         //---- check for possible errors

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

         

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

         if(counted_bars>0) counted_bars--;

         limit=Bars-counted_bars;

       

         //--- main loops 1 and 2

         for(shift=0; shift < limit; shift++)

            {

              Cci[shift] = iCCI(NULL,0,cci_p,PRICE_TYPICAL,shift);    

              Buffer0[shift] = Cci[shift];

            }

        

         for(shift=0; shift < limit; shift++)

            {

               Ma[shift] = iMAOnArray(Cci,0,ma,0,MODE_EMA,shift);

               Ma2[shift] = iMAOnArray(Cci,0,ma2,0,MODE_EMA,shift);

               Buffer1[shift] = Ma[shift];

               Buffer2[shift] = Ma2[shift];

            }



  

      return(0);

}

 

Ignore the above.. The reading is tally now  .

 
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.
Reason: