How to Stop EA after a candle condition is met and Reactivate after a buy Signal

I’m trying to make the EA trigger once there’s a sell position and closes after a couple number of candlesticks.
EA should stop after that condition is met.
wait for a buy position, then Trigger again once the signal changes to Sell.

The problem is this, I don’t seem to get how I’m supposed to let it trigger after a buy signal.
Please HELP!!

> void OnTick()
  {
     
      
      double Bid= NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

      
      string signal ="";
      
      MqlRates PriceArray[];
      
      ArraySetAsSeries(PriceArray,true);
      
      int Data = CopyRates(Symbol(),Period(),0,3,PriceArray); 
      
      double mySARArray[];
      
      int SARDefinition =iSAR(Symbol(),Period(),0.02,0.2);
      
      ArraySetAsSeries(mySARArray,true);
      
      CopyBuffer(SARDefinition,0,0,3,mySARArray);
      
      double LastSARValue = NormalizeDouble(mySARArray[1],5);
      
      
      if(LastSARValue <PriceArray[1].low)
      {
         signal="buy";
         //Increment the check control
         sellCheck= 0;
         Print("Check SELL check in BUY :", sellCheck);
         
         candleCounter = 0;
         Print("Check Control: ", check);
         //check = 0;
      }
      // check = check + 1; //Increment the check control
      
      if(LastSARValue > PriceArray[1].high)
      {
      signal ="sell";
      }
      
   
       if(signal=="sell" && PositionsTotal() <2 )
         //trade.Sell(num_lots,NULL,Bid,0,0,NULL);
         if(sellCheck==0)
           {
            trade.Sell(Lot_Size,NULL,Bid,(Bid+(Stop_Loss*10 ) *_Point),(Bid-(Take_Profit*10 ) *_Point),NULL);
           }
         
    
         sellCheck = sellCheck + 1;
         CalculateCandle(signal);
        //Print("Check SELL STRL :", ctrl);
       
     
     
     
      
      
      
      Comment("The Signal is :", signal);  
       
   
  }



 void CalculateCandle(string signal)
 {
   MqlRates priceData[]; //Create Price Array
      
      //Sort the array from the current candle downwards
      ArraySetAsSeries(priceData,true);
      
      //copy candle price for 3 candles into array
      CopyRates(_Symbol, _Period,0,3,priceData);
      
      //Create a counter for the candle
      static int candleCounter;
      
      //Create Datetime Variable for the last time stamp
      static datetime timeStampLastCheck;
      
      //Variable for current candle
      datetime timeStampCurrentCandle;
      
       //Read the time stamp of current candle in array 
       timeStampCurrentCandle = priceData[0].time;
       
       //if the current time stamp is different from the last time 
       if(timeStampCurrentCandle!= timeStampLastCheck)
         {
            //Remember the Candle time stamp for later
            timeStampLastCheck = timeStampCurrentCandle;
            
            //Increment the candleCounter
            candleCounter = candleCounter +1;
            
          
         }
      
      Print("Counted Candles :", candleCounter);
   
      if(candleCounter == duration && signal == "sell")
        {
          ClosePosition();
          candleCounter = 1;
          
        }
     
 }
 
 
 void ClosePosition()
{
   for(int i=PositionsTotal()-1; i>=0; i--)
     {
     
     int ticket= PositionGetTicket(i);
     
     //Get Position Direction
     int PositionDirection=PositionGetInteger(POSITION_TYPE);
     
          
     if(PositionDirection==POSITION_TYPE_SELL)
     trade.PositionClose(ticket);
      
     }

}