Download MetaTrader 5

Custom Indicator Stops Working in Strategy Tester after a few days

To add comments, please log in or register allows users to store their source codes in MQL5 Storage. Try it!
Gerardo Bustos
Gerardo Bustos 2015.06.11 18:27 

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,


Alain Verleyen
Alain Verleyen 2015.06.11 18:47  
How can we know ? Which indicator are you talking about ? What is your code ?
Gerardo Bustos
Gerardo Bustos 2015.06.11 18:59  
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
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;                                                                     
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()
        SetIndexLabel(3,"Peak A Point");
        SetIndexLabel(4,"Peak B Point");
        SetIndexLabel(5,"Valley A Point");
        SetIndexLabel(6,"Valley B Point");
        SetIndexLabel(9,"Pre Support");
        SetIndexLabel(10,"Pre Resistance");
   mPoint = GetPoint();
void OnDeinit(const int reason)
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[] )
      Print("Not enough bars");
   int limit, shift;
   //Moving Average
      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;
      if(GetPeaks(shift)) WavesCount++;
      if(GetValleys(shift)) WavesCount++;
      if(WavesCount==MaxWaves) break;
   //Get Supports and Resistances
        //Get recent Support & Resistance
        double resistance= EMPTY_VALUE, support = EMPTY_VALUE;
          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     
           if(Resistance[shift]!=Resistance[0] && Resistance[shift]!=EMPTY_VALUE) 
           PreResistance[0] = Resistance[shift];
           if(Support[shift]!=Support[0] && Support[shift]!=EMPTY_VALUE) 
           PreSupport[0] = Support[shift];
   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);



Best regards and thank you, 


To add comments, please log in or register