Stopping same direction trades after take profit

 
So im new to programmer and just wanted to create a simple EA price crosses and closes above 2 moving averages,  However once a take profit is hit it opens a new buy order on the next bar after take profit which I do not want, so im trying to stop same direction trades until an opposite signal has opened and closed and for some reason I am having great difficulty accomplishing this in MQL5 so I figured I would reach out here for assistance
   if(slowMa<DBL_MAX && fastMa<DBL_MAX){ 
      if(fastMa <= close && slowMa <= close){
         signal = TRADE_SIGNAL_BUY;                  
      }      
   else if(slowMa >= close && fastMa >= close){ 
         signal = TRADE_SIGNAL_SELL;
      }
   }      
   return signal;
}
void OnTick(){
   bool newBar = NewBar();
   if(newBar){
   ENUM_TRADE_SIGNAL signal_entry = signal_entry();
   if(signal_entry==TRADE_SIGNAL_BUY){
      ClosePositions(POSITION_TYPE_SELL);      
      uint count_long = CountPositions(POSITION_TYPE_BUY,magicNumber);
      if(count_long<max_positions){
         TradeRequestMarket(Symbol(),ORDER_TYPE_BUY,Lots,Slippage,StopLoss,TakeProfit,magicNumber);
      }
   }
   else if(signal_entry==TRADE_SIGNAL_SELL){
      ClosePositions(POSITION_TYPE_BUY);      
      uint count_short = CountPositions(POSITION_TYPE_SELL,magicNumber);
      if(count_short<max_positions){
         TradeRequestMarket(Symbol(),ORDER_TYPE_SELL,Lots,Slippage,StopLoss,TakeProfit,magicNumber);
      }
   }
   }
}

Moving Average - Trend Indicators - MetaTrader 5 Help
Moving Average - Trend Indicators - MetaTrader 5 Help
  • www.metatrader5.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 
if(signal_entry==TRADE_SIGNAL_BUY){

You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 (2017)

 
William Roeder #:

You are looking at a signal. Act on a change of signal.
          MQL4 (in Strategy Tester) - double testing of entry conditions - MQL5 programming forum #1 (2017)


thank you so much for the reply William self teaching can be hard sometimes and i really appreciate trying to point me in the right direction!

Also just another question so your saying to change the buy signal to stop same direction trades, so would you have to do that with getting the last position and seeing whether it was a buy or a sale?

Reason: