same indicator , different output

 

Hi,

I've noticed a very strange thing happening when backtesting my EA that call a indicator I've wrote using icustom.

below is the chart i have backtested

2nd is the chart with the same indicator called from the EA

If you have noticed the green line are different . how can it be the 2 same indicator be different?

Indicator code:

//+------------------------------------------------------------------+
//|                                         trendrojak indicator.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, TS Lau"
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Green
#define look_back 30
static datetime time0;
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

double countma=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel (0, "mafilter");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel (1, "trendstrength");
   SetIndexStyle(2,DRAW_LINE);
  SetIndexBuffer(2,ExtMapBuffer3);
  SetIndexLabel (2, "macount");

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()  {
 
   int counted_bars=IndicatorCounted();
   if(counted_bars<look_back) counted_bars = look_back;
for(int i=Bars-1-counted_bars; i>=0; i--){
//ExtMapBuffer1[i]=macount[i];
ExtMapBuffer1[i]=mafilter (i+1);
ExtMapBuffer2[i]=trendstrength (i+1);
ExtMapBuffer3[i]=macount (i+1);
} //end for
Comment ("i is " , i, "mafilter is ", mafilter(i+1) ,"trendstrength is ", trendstrength(i+1) ," mcount is ", macount(i) );

   return(0);
  }// end start

double mafilter(double shift) {
double ma5,ma10,ma30;
double shiftma=shift+1;
ma5= iMA (NULL,0,5,0,MODE_EMA,PRICE_MEDIAN,shiftma);
ma10= iMA (NULL,0,10,0,MODE_EMA,PRICE_MEDIAN,shiftma);
ma30= iMA (NULL,0,30,0,MODE_EMA,PRICE_MEDIAN,shiftma);
   if (ma5 >ma30 && ma10>ma30 && ma5> ma10 ) {
      return(1); //trend intact
                               } //end if 
   else return (-1); //trend change
          } //end mafilter 

double trendstrength(double shifttrend) {
// iADX( string symbol, int timeframe, int period, int applied_price, int mode, int shift) 

if (iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,shifttrend) > 25) {
  
   if (iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,shifttrend) >iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,shifttrend+1)) {
   return (1); //trend picking up strength
   }//end if
   else {
   return (-1);
         }//end else
         
   }//end if >25
else {
return (-1);
}//end else
}//end trendstrength*/ 

double macount (double ped) {
int count = ped;
//if (mafilter(count)==1) {
    if (mafilter(count)==1 &&time0 != Time[0]) {
         countma++;
      return (countma);
                                                   }//end if
      if (mafilter(count)==-1) {
      countma =0; 
      return (countma);
                                }//end if
      }//end macount

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

EA code:

int start()
  {
  static datetime start;
//if ( start == Time[0]) {
double mafilter= iCustom(NULL,0,"trendrojak indicator_v2",0,0);
double trendstrength= iCustom(NULL,0,"trendrojak indicator_v2",1,0);
//}//end static datetime

If I were to compile the indicator again, both chart will be identical as expected. could someone help to demystify this ?