How to change this in the indicator?

Blue = 1° Candle [Close] < 2° Candle [Close]

Red = 2° Candle [Close] < 1° Candle [Close]

(up) always [close] greater than the previous one

(down) always [close] lower than the previous

The calculation has to stay the same as I said above, but I try to change and it will not
in the photo my indicator is blue and red
Code:

  if (rates_total<10) return (rates_total);
  int limit = prev_calculated-1;
  if (limit<0) limit = 0;
  if (prev_calculated==0)
  {
    ArrayInitialize(nn, 0);
    for (int i = 0; i < rates_total; i ++)
    {
      up[i] = 0; dn[i] = 0;
      if (close[i]==open[i]) continue; else { limit = i; break; }
    }
  }
  //------------------------------------------------------------------
  //if (prev_calculated!=0) Comment(basePrice);
  int basec = rates_total-iBarShift(NULL, 0, baseCandle)-1;
  if (basec<0) basec = 0;
  for (int i = limit; i < rates_total-1; i++)
  {
    if (basePrice==0 && close[i]>open[i]) { basePrice = close[i]; basec = i; up[i] = (double)(VolumeMode==vl_tick?tick_volume[i]:volume[i]); }
    else if (basePrice==0 && close[i]<open[i]) { basePrice = close[i]; basec = i; dn[i] = (double)(VolumeMode==vl_tick?tick_volume[i]:volume[i]); }
    else if (i!=0)
    {
      if (up[i-1]!=0 && NormalizeDouble(basePrice-close[i], _Digits)>=NormalizeDouble(directionChangeTicks, _Digits))
      {
        up[i] = 0; dn[i] = (double)(VolumeMode==vl_tick?tick_volume[i]:volume[i]); basePrice = close[i]; basec = i; ArrayInitialize(nn, 0);
        continue;
      }
      else if (up[i-1]!=0 && NormalizeDouble(basePrice-close[i], _Digits)<NormalizeDouble(directionChangeTicks, _Digits))
      {
        dn[i] = 0; up[i] = up[i-1]+(double)(VolumeMode==vl_tick?tick_volume[i]:volume[i]); if (close[i]>basePrice) { basePrice = close[i]; basec = i; ArrayInitialize(nn, 0); }
        continue;
      }
      if (dn[i-1]!=0 && NormalizeDouble(close[i]-basePrice, _Digits)>=NormalizeDouble(directionChangeTicks, _Digits))
      {
        dn[i] = 0; up[i] = (double)(VolumeMode==vl_tick?tick_volume[i]:volume[i]); basePrice = close[i]; basec = i; ArrayInitialize(nn, 0);
        continue;
      }
      else if (dn[i-1]!=0 && NormalizeDouble(close[i]-basePrice, _Digits)<NormalizeDouble(directionChangeTicks, _Digits))
      {
        up[i] = 0; dn[i] = dn[i-1]+(double)(VolumeMode==vl_tick?tick_volume[i]:volume[i]); if (close[i]<basePrice) { basePrice = close[i]; basec = i; ArrayInitialize(nn, 0); }
        continue;
      }
    }
  }
  //------------------------------------------------------------------
  for (int i = basec+1; i < rates_total-1; i ++)
  {
    if (up[i]!=0 && close[i]<=basePrice) nn[i] = up[i];
    if (dn[i]!=0 && close[i]>=basePrice) nn[i] = dn[i];
  }
  //------------------------------------------------------------------
  if (basec<rates_total-1 && basec>=0) baseCandle = time[basec]; else return (0);
  up[rates_total-1] = 0; dn[rates_total-1] = 0;

Screenshot_11