Strategy Tester Not Updating Custom Indicator

 

I've been developing custom indicators on MT5 for roughly a month now and am realizing I may be doing something fundamentally incorrect.

I am 99.9% sure that the calculations I am making do not reference future data and they always appear perfectly in the main window.

However, when I try to view them being calculated through time in Strategy Tester, the indicators either do not update or make erratic calculations then flatten to 0.

Below is code from one of my indicators that resides in my OnCalculate() function - I am curious to see if anyone is able to pinpoint exactly what my mistake may be.

Thank you in advance. 

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[])
  {
  for(int i = rates_total-prev_calculated-period; i > -1; i--){
      ArraySetAsSeries(close,true);
      ArraySetAsSeries(avg,true);
      ArraySetAsSeries(avg2,true);
      ArraySetAsSeries(hp,true);
      if (i>rates_total-prev_calculated-period-3){
         hp[i] = 0;
         avg[i] = close[i];
         avg2[i] = avg[i];
      }else{
         hp[i] = (1-alpha1/2)*(1-alpha1/2)*(close[i]-2*close[i+1]+close[i+2])+2*(1-alpha1)*hp[i+1]-(1-alpha1)*(1-alpha1)*hp[i+2];
         avg[i] = (c1*(hp[i]+hp[i+1])/2+c2*avg[i+1]+c3*avg[i+2]);
         avg2[i] = avg[i+lag];
     }
  ChartRedraw();
  }
 return(rates_total);
}
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
The MQL5 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL5 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
Reason: