Store information and compare in the future

 
Hello guys,

I'm new to programming, I need help with a situation. I have an indicator that appears arrows when a certain condition is reached.
When a new arrow is created, I need to store the candle close price in a variable and after 3 candles compare if the price stored is higher or lower than the current candle close price. Regardless of the timeframe the comparison is always made after 3 candles later.

How do I store the candle close price and compare the stored variable after 3 candles closed time?

Code attached

//+--------- ---------------------------------------------------------+
//|                                                     DS B.O.A.mq4 |
//|                                   Copyright 2018, DS Trade Corp. |
//|                                       https://www.dstrade.com.br |
//+------------------------------------------------------------------+
#property copyright     "Copyright 2018, DS Trade Corp."
#property link          "https://www.dstrade.com.br"
#property version       "1.05"
#property description   "DS Trade "
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Orange
#property indicator_color2 DarkGray
#property indicator_color3 Orange
#property indicator_color4 LimeGreen
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_style4 STYLE_DOT

//
//
//
//
//

enum enTmaKind
{
   tma_cen, // Centered (recalculating) TMA
   tma_tma  // Regular (non-recalculating) TMA
};
extern int    RsiLength  = 14;
extern int    RsiPrice   = PRICE_CLOSE;
extern int    HalfLength = 12;
extern int    DevPeriod  = 100;
extern double Deviations = 1.5;
extern enTmaKind TmaKind = tma_cen; 
extern bool   AlertOn    = true;

double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];

datetime AlertLast;

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//

int init()
{
   HalfLength=MathMax(HalfLength,1);
         SetIndexBuffer(0,buffer1); 
         SetIndexBuffer(1,buffer2);
         SetIndexBuffer(2,buffer3); 
         SetIndexBuffer(3,buffer4);
   return(0);
}
int deinit() { return(0); }

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int start()
{
   int i,j,k,counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-1,Bars-counted_bars+HalfLength);

   //
   //
   //
   //
   //
   
   for (i=limit; i>=0; i--) buffer1[i] = iRSI(NULL,0,RsiLength,RsiPrice,i);
   for (i=limit; i>=0; i--)
   {
      double dev  = iStdDevOnArray(buffer1,0,DevPeriod,0,MODE_SMA,i);
      if (TmaKind==tma_cen)
      {
         double sum  = (HalfLength+1)*buffer1[i];
         double sumw = (HalfLength+1);
         for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
         {
            sum  += k*buffer1[i+j];
            sumw += k;
            if (j<=i)
            {
               sum  += k*buffer1[i-j];
               sumw += k;
            }
         }
         buffer2[i] = sum/sumw;
      }
      else buffer2[i] = iTma(buffer1[i],HalfLength*2+1,i);
      buffer3[i] = buffer2[i]+dev*Deviations;
      buffer4[i] = buffer2[i]-dev*Deviations;
   }
   
   //---
   
   if (AlertOn && AlertLast != Time[0]) {
       if (buffer1[0] > buffer3[0] && buffer1[1] < buffer3[1]) {
            AlertLast = Time[0];
            Alert("RSI-TMA :: ", _Symbol, " :: ", eGetPeriodString(), "  >  Touch TOP Band");
       } else if (buffer1[0] < buffer4[0] && buffer1[1] > buffer4[1]) {
            AlertLast = Time[0];
            Alert("RSI-TMA :: ", _Symbol, " :: ", eGetPeriodString(), "  >  Touch BOTTOM Band");
       }
    }   
   
   //---
   
   return(0);
}

string eGetPeriodString()
{
    string periodStr = "??";
    if      (_Period == PERIOD_M1)  { periodStr = "M1";  }
    else if (_Period == PERIOD_M5)  { periodStr = "M5";  }
    else if (_Period == PERIOD_M15) { periodStr = "M15"; }
    else if (_Period == PERIOD_M30) { periodStr = "M30"; }
    else if (_Period == PERIOD_H1)  { periodStr = "H1";  }
    else if (_Period == PERIOD_H4)  { periodStr = "H4";  }
    else if (_Period == PERIOD_D1)  { periodStr = "D1";  }
    else if (_Period == PERIOD_W1)  { periodStr = "W1";  }
    else if (_Period == PERIOD_MN1) { periodStr = "MN1"; }
    //---
    return(periodStr);
}

double workTma[][1];
double iTma(double price, double period, int r, int instanceNo=0)
{
   if (period<=1) return(price);
   if (ArrayRange(workTma,0)!= Bars) ArrayResize(workTma,Bars); r=Bars-r-1;
   
   //
   //
   //
   //
   //
   
   workTma[r][instanceNo] = price;

      double half = (period+1.0)/2.0;
      double sum  = price;
      double sumw = 1;

      for(int k=1; k<period && (r-k)>=0; k++)
      {
         double weight = k+1; if (weight > half) weight = period-k;
                sumw  += weight;
                sum   += weight*workTma[r-k][instanceNo];  
      }             
      return(sum/sumw);
}