Custom Indicator Problem.

 

I have been working with iCustom and have tested a number of iterations of the parameters of this function and now understand how this function works. In other words, I have tied out the chart results with the EA called results. I though cannot explain why the following indicator does not give me the same results on a chart versus an EA. The call to this iCustom indicator named AccumDistEval#3 is giving me numbers in the neighborhood of 8,000 in the EA while the indicator itself on the chart is giving me numbers in the 40,000 neighborhood. The code has been edited for illustration but has some irrelvant lines. The following is the indicator code:

#property indicator_separate_window    
#property indicator_buffers 2       
#property indicator_color1 Red    
#property indicator_color2 Lime

extern int fastma=2;
extern int slowma=5;

double Buf_0[100];
//--------------------------------------------------------------------
int init()                         
  {
   IndicatorBuffers(2);
//--------------------------------------------------------------------
   IndicatorShortName("");
//--------------------------------------------------------------------
   SetIndexBuffer(0,Buf_0);        
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexDrawBegin(0,slowma);
   return;                         
  }
//--------------------------------------------------------------------
int start()                        
  {
   int i;
   for(i=0;i<Bars;i++)          
      {            
      RefreshRates();
      Buf_0[i]=iAD(NULL,1,i);
      }
  return(0);
  }
//-------------------------------------------------------------------

The following is the EA call to this indicator:

int init()
{
return(0);
}

int deinit()
{
return(0);
}

//===========================================================================================================================================================
//    Start Section
//===========================================================================================================================================================

int start()
  {
   double Accum_0 = iCustom("EURUSD_fx",PERIOD_M1,"AccumDistEval#3",2,5,0,0);                       
   Print(DoubleToStr(Accum_0,5));
   
   return;                                      // Exit start()  
  }

 

I have noted this issue with the indicator Accumulation/Distribution as well. The EA is reporting in the neighborhood of 3.5 times less than the indicator for Accumulation/Distribution. In other words, if the EA reports 15,000, the chart shows 52,500.

 
ForexSurfr:

I have noted this issue with the indicator Accumulation/Distribution as well. The EA is reporting in the neighborhood of 3.5 times less than the indicator for Accumulation/Distribution. In other words, if the EA reports 15,000, the chart shows 52,500.


There apparently is a difference between a live chart and a tester chart. When I run the EA in the tester with "Visual Mode" turned on, the chart window values are now matching the values being called through the EA. I do not understand why the chart window (non-tester mode) is different from the in tester mode chart window.
 
ForexSurfr:

There apparently is a difference between a live chart and a tester chart. When I run the EA in the tester with "Visual Mode" turned on, the chart window values are now matching the values being called through the EA. I do not understand why the chart window (non-tester mode) is different from the in tester mode chart window.
  1. // iAD(NULL,1,i);
    iAD(NULL,PERIOD_M1,i);
    You can NOT get bar zero data in the tester for other TF/pairs - Testing Features and Limits in MetaTrader 4 - MQL4 Articles Don't hard code numbers, self document your code.
  2. There is no reason for refreshRates in indicators, as indicators can NOT sleep or perform long calculations.
  3. for(i=0;i<Bars;i++)
    Do it correctly, recalculating every candle is unnecessary.
    int counted = indicatorCounted();
    // if indicator contains A[i+x] then DRAWBEGIN == x
    // if indicator calls others with moving averages of period x, DRAWBEGIN == x
    // if (counted < DRAWBEGIN) counted = DRAWBEGIN; // Need if DRAWBEGIN is nonzero
       for(i= Bars - 1 - counted; i >= 0;Bars; i--)      
Reason: