Custom Indicator Stops Working in Strategy Tester after a few days

 

Hello forum, good day.

I'm using a Custom Indicator in the Strategy Tester using visual mode to see the behaviour, and after several days pass, suddenly it stops showing the indicator buffers and the Expert Advisor stops working as well because I'm using the iCustom() function to get the data from the Custom Indicator. There are some months that works okay for the first 3 days for example and then stops working, but another months it doesn't even last 1 day. What could be the reasons for this?

Your help will be much appreciated. 


Best regards and thank you in advance,

Gerardo 

 
How can we know ? Which indicator are you talking about ? What is your code ?
 
Alain Verleyen:
How can we know ? Which indicator are you talking about ? What is your code ?

It is a custom indicator that gets the Moving Average waves.

Here are the OnInit(), OnDeinit() and OnCalculate() functions:

enum YN {No,Yes};

//*------------------------------------------------------------------*
#property indicator_chart_window
#property indicator_buffers 11
#property indicator_color1 clrWhite
#property indicator_style1 0
#property indicator_width1 2
#property indicator_color2 clrBlue
#property indicator_width2 4
#property indicator_color3 clrRed
#property indicator_width3 4
#property indicator_color4 clrBlue
#property indicator_width4 2
#property indicator_color5 clrBlue
#property indicator_width5 2
#property indicator_color6 clrRed
#property indicator_width6 2
#property indicator_color7 clrRed
#property indicator_width7 2
#property indicator_color8 clrRed
#property indicator_style8 2
#property indicator_width8 1
#property indicator_color9 clrBlue
#property indicator_style9 2
#property indicator_width9 1
//*------------------------------------------------------------------*
// INPUTS
extern      string               •••••General_Settings•••••          = "••••••••••••••••••";
input       int                  MaxWaves                            = 25;    
input       int                  Threshold                           = 5;     
input       int                  Range                               = 20;                         
input       int                  MaxBarsBack                         = 1000;                                                       
input       YN                   ShowMovingAverage                   = Yes;                                                        
input       int                  SupportResistanceCount              = 4;                                                            
extern      YN                   ShowSupportResistance               = Yes;                                                       
extern      YN                   DrawTringles                        = No;                                                            
extern      string               •••••Moving_Average_Settings•••••   = "••••••••••••••••••";
input       int                  MA_Period                           = 7;                                                                    
input       ENUM_MA_METHOD       MA_Method                           = MODE_SMA;                                                   
input       ENUM_APPLIED_PRICE   MA_Price                            = PRICE_CLOSE;                                   
input       int                  MA_Shift                            = 0;                                                                     
//*------------------------------------------------------------------*
// BUFFERS
double MA[];
double Peaks[];
double Valleys[];
double PeakA[];
double PeakB[];
double ValleyA[];
double ValleyB[];
double Support[];
double Resistance[];
double PreSupport[];
double PreResistance[];
//*------------------------------------------------------------------*
double mPoint        = 0.0001;
//*------------------------------------------------------------------*
int OnInit()
{ 
        SetIndexBuffer(0,MA);
        SetIndexEmptyValue(0,EMPTY_VALUE);
        if(ShowMovingAverage)
        {
        SetIndexStyle(0,DRAW_LINE);     
        SetIndexLabel(0,"MA");
        }
        else
        {
        SetIndexStyle(0,DRAW_NONE);     
        SetIndexLabel(0,NULL);
        }
        
        SetIndexStyle(1,DRAW_ARROW);    
        SetIndexArrow(1,119);
        SetIndexBuffer(1,Peaks);
        SetIndexLabel(1,"Peak");
        SetIndexEmptyValue(1,EMPTY_VALUE);
        
        SetIndexStyle(2,DRAW_ARROW);
        SetIndexArrow(2,119);
        SetIndexBuffer(2,Valleys);
        SetIndexLabel(2,"Valley");
        SetIndexEmptyValue(2,EMPTY_VALUE);
        
        SetIndexStyle(3,DRAW_ARROW);
        SetIndexArrow(3,140);
        SetIndexBuffer(3,PeakA);
        SetIndexLabel(3,"Peak A Point");
        SetIndexEmptyValue(3,EMPTY_VALUE);
        
        SetIndexStyle(4,DRAW_ARROW);
        SetIndexArrow(4,141);
        SetIndexBuffer(4,PeakB);
        SetIndexLabel(4,"Peak B Point");
        SetIndexEmptyValue(4,EMPTY_VALUE);
        
        SetIndexStyle(5,DRAW_ARROW);
        SetIndexArrow(5,140);
        SetIndexBuffer(5,ValleyA);
        SetIndexLabel(5,"Valley A Point");
        SetIndexEmptyValue(5,EMPTY_VALUE);
        
        SetIndexStyle(6,DRAW_ARROW);
        SetIndexArrow(6,141);
        SetIndexBuffer(6,ValleyB);
        SetIndexLabel(6,"Valley B Point");
        SetIndexEmptyValue(6,EMPTY_VALUE);
        
        SetIndexBuffer(7,Support);
        SetIndexEmptyValue(7,EMPTY_VALUE);
        if(ShowSupportResistance)
        {
        SetIndexStyle(7,DRAW_LINE);     
        SetIndexLabel(7,"Support");
        }
        else
        {
        SetIndexStyle(7,DRAW_NONE);     
        SetIndexLabel(7,NULL);
        }
        
        SetIndexBuffer(8,Resistance);
        SetIndexEmptyValue(8,EMPTY_VALUE);
        if(ShowSupportResistance)
        {
        SetIndexStyle(8,DRAW_LINE);     
        SetIndexLabel(8,"Resistance");
        }
        else
        {
        SetIndexStyle(8,DRAW_NONE);     
        SetIndexLabel(8,NULL);
        }
        
        SetIndexBuffer(9,PreSupport);
        SetIndexStyle(9,DRAW_NONE);
        SetIndexLabel(9,"Pre Support");
        
        SetIndexBuffer(10,PreResistance);
        SetIndexStyle(10,DRAW_NONE);
        SetIndexLabel(10,"Pre Resistance");
        
   mPoint = GetPoint();
   
   Print("========================================");
 
   return(0);
}
//*------------------------------------------------------------------*
void OnDeinit(const int reason)
{
   DelObjs("peak_");
   DelObjs("valley_");
}
//*------------------------------------------------------------------*
int OnCalculate (const int rates_total, const int prev_calculated, const datetime& time[], const double& open[],  const double& high[],                  
                 const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[] )
{   
   if(Bars<MaxBarsBack)
   {
      Print("Not enough bars");
      return(0);
   }
   
   int limit, shift;
   limit=MaxBarsBack;
   
   
   //Moving Average
        for(shift=limit;shift>=0;shift--)
        {
      MA[shift] = iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Price,shift);
      Support[shift] = Resistance[shift] = Peaks[shift] = Valleys[shift] = EMPTY_VALUE;
        }
        
        //Peaks and Valleys
        int WavesCount = 0;
        for(shift=2;shift<=limit;shift++)
        {
      if(GetPeaks(shift)) WavesCount++;
      if(GetValleys(shift)) WavesCount++;
      
      if(WavesCount==MaxWaves) break;
        }
        
   //Get Supports and Resistances
   GetSupRes(SupportResistanceCount);
        
        //Get recent Support & Resistance
        double resistance= EMPTY_VALUE, support = EMPTY_VALUE;
        for(shift=1;shift<=limit;shift++)
        {
          if(resistance==EMPTY_VALUE) resistance = Resistance[shift];
          if(resistance!=EMPTY_VALUE) DrawResistance(0,shift,resistance);
          if(support==EMPTY_VALUE) support = Support[shift];
          if(support!=EMPTY_VALUE) DrawSupport(0,shift,support);          
          if(resistance!=EMPTY_VALUE && support!=EMPTY_VALUE) break;
        } 
        
        string sup, res;
        if(Support[0]==EMPTY_VALUE) sup = "EMPTY"; else sup = DoubleToStr(Support[0],Digits);
        if(Resistance[0]==EMPTY_VALUE) res = "EMPTY"; else res = DoubleToStr(Resistance[0],Digits);
        
        
        //Get previous Support & Resistance     
        for(shift=1;shift<=limit;shift++)
        {
           if(Resistance[shift]!=Resistance[0] && Resistance[shift]!=EMPTY_VALUE) 
           {
           PreResistance[0] = Resistance[shift];
           break;
           }
        }
        for(shift=1;shift<=limit;shift++)
        {
           if(Support[shift]!=Support[0] && Support[shift]!=EMPTY_VALUE) 
           {
           PreSupport[0] = Support[shift];
           break;
           }
        }
        
   string psup, pres;
        if(PreSupport[0]==EMPTY_VALUE) psup = "EMPTY"; else psup = DoubleToStr(PreSupport[0],Digits);
        if(PreResistance[0]==EMPTY_VALUE) pres = "EMPTY"; else pres = DoubleToStr(PreResistance[0],Digits);
        
        
        Comment("Support: " , sup, "\nResistance: " , res, "\nPre Support: " , psup, "\nPre Resistance: " , pres);

   return(0);
}

 

Best regards and thank you, 

Gerardo 

Reason: