this indicator code runs too slow in testing. how it become faster without affect results of it?

 
#property link "https://www.mql5.com"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_label1 "mColorLine"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 clrRed, clrGreen, clrGray, clrBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2

double ColorLineBuffer[];
double ColorLineColors[];

input int SmoothingPeriod =21;
input double ConstantD = 0.4;
input bool ColorBars = false;


double iStores[];
int OnInit()
{
  SetIndexBuffer(0, ColorLineBuffer, INDICATOR_DATA);
  SetIndexBuffer(1, ColorLineColors, INDICATOR_COLOR_INDEX);
  ArrayResize(iStores,6);
 
  return INIT_SUCCEEDED;
}

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 j = 0; j < 6; ++j)
  {
    iStores[j] = 0;
  }
  double src, di, c1, c2, c3, c4, c5, cd;
  cd = ConstantD;
  for (int i = 0; i <= rates_total - 1; i++)
  {
    src = close[i];
    di = (SmoothingPeriod - 1.0) / 2.0 + 1.0;
    c1 = 2 / (di + 1.0);
    c2 = 1 - c1;
    c3 = 3.0 * (cd * cd + cd * cd * cd);
    c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd);
    c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd;
    iStores[0] = c1 * src + c2 * iStores[0];
    iStores[1] = c1 * iStores[0] + c2 * iStores[1];
    iStores[2] = c1 * iStores[1] + c2 * iStores[2];
    iStores[3] = c1 * iStores[2] + c2 * iStores[3];
    iStores[4] = c1 * iStores[3] + c2 * iStores[4];
    iStores[5] = c1 * iStores[4] + c2 * iStores[5];
    ColorLineBuffer[i] = -1.0 * cd * cd * cd * iStores[5] + c3 * (iStores[4]) + c4 * (iStores[3]) + c5 * (iStores[2]);
    double rz = 0;
    if (i != 0)
    {
      rz = ColorLineBuffer[i - 1];
    }
    if (ColorLineBuffer[i] > rz)
    {
      ColorLineColors[i] = 1;
    }
    else if (ColorLineColors[i] < rz)
    {
      ColorLineColors[i] = 0;
    }
    else
    {
      ColorLineColors[i] = 3;
    }
    if (ColorBars)
    {
      ColorLineColors[i] = 2;
    }

  }

  return rates_total;
}

 

Learn math and fix your code

c3 = 3.0 * (cd * cd + cd * cd * cd);
    c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd);
    c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd;

What that should be?

 
this is a code of coral trend indicator in tradingview that converted to mql5 file.
 
12 minuteaffiliate: this indicator code runs too slow in testing. how it become faster without affect results of it?
  for (int i = 0; i <= rates_total - 1; i++)
Stop computing all bars every tick.
          How to do your lookbacks correctly #9#14 & #19 (2016)
Reason: