Take trades depending on the close of the following candle

 

I programmed an EA that opens either buy or sell trades depending on the signal from a custom indicator. The custom indicator gives a signal on candle A then the trade is taken on the following candle B. The problem i have is that, the signal is usually not stable, for example if the indicator gives a BUY signal on candle A, if the following candle B closes above candle A the signal changes to the new candle B for a buy and this keeps happening until a following candle closes below the signal candle. This is a loss assuming my EA took BUY trade on the signal of the initial candle A with the signal.

How can i make my EA take trades only when the following candle after the signal closes below it in the case of a sell signal or closes above it in a buy signal?

What i have currently only takes trades on the open of the new candle that follows the signal candle. but this could be a loss if the signal changes position on the close of the following candle. 

if(checkNewCandle(candleTimes, lastCandleTime))
     {
      int H1 = CopyBuffer(handle, 0, 0, 2, H1Buffer);
      int L1 = CopyBuffer(handle, 1, 0, 2, L1Buffer);

      if(L1Buffer[0] != 0) //buy signal from indicator
        {
         Print("Buy Signal here");
         bool orderSuccess = OrderSend(request, result);
        }
      else
         if(H1Buffer[0] != 0) //sell signal from indicator
           {
            Print("Sell Signal here");
            bool orderSuccess = OrderSend(sellRequest, sellResult);
           }
}