how can i edit the following ea to make an opposite trade ie when it is to take a buy trade it makes a sell and when it should take a sell trade it takes a buy.
E.A


//+------------------------------------------------------------------+
//|                                               BreakoutScalper.mq5|
//|                        Scalper EA - trades quick price breakouts|
//+------------------------------------------------------------------+
#property copyright "Ch"
#property link      ""
#property version   "1.09"
#property strict

input double  Lots                  = 0.01;                 // Lot size
input int     PointsThreshold       = 30;                  // Move in points to trigger trade
input int     CheckInterval         = 10;                   // Seconds to check price movement(10,5))
input int     TrailingStopPoints    = 0;                  // Trailing stop in points (0=off)
input int     EAStartHour           = 2;                   // EA start hour (server time)(2>)
input int     EAStopHour            = 20;                  // EA stop hour (server time)
input ENUM_TIMEFRAMES PriceTF       = PERIOD_M1;           // Timeframe for reference (for convenience)
input int     TradesPerSignal       = 1;                   // Number of orders to open per breakout signal
input int     InitialStopLossPoints = 0;                  // Initial stop loss in points at trade open (0=off)
input int     InitialTakeProfitPoints  = 100;              // Initial take profit in points at trade open (0=off)

//--- Global variables
datetime lastCheckTime = 0;
double   priceAtLastCheck = 0.0;

string priceMoveLineName       = "PriceMoveLine";
string priceMoveTextName       = "PriceMoveText";      // current move stats label

string maxPosMoveTextName      = "MaxPosMoveText";     // max positive move label
string maxNegMoveTextName      = "MaxNegMoveText";     // max negative move label

string breakoutArrowNameBuy    = "BreakoutBuy";
string breakoutArrowNameSell   = "BreakoutSell";

// Tracking max positive and negative moves (points and rates)
double maxPosPointsMoved      = 0.0;
double maxPosRatePointsPerSec = 0.0;

double maxNegPointsMoved      = 0.0;  // store positive number of max negative move absolute
double maxNegRatePointsPerSec = 0.0;

//--- ADDED for 5-min wait after trade close
int prevPositionsCount = 0;
datetime lastTradeCloseTime = 0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
   {
    PrintFormat("EA started with InitialStopLossPoints=%d, TrailingStopPoints=%d", InitialStopLossPoints, TrailingStopPoints);
    
    lastCheckTime = TimeCurrent();
    priceAtLastCheck = SymbolInfoDouble(_Symbol, SYMBOL_BID);
      
    prevPositionsCount = 0; // initialize for position count tracking
    
    return(INIT_SUCCEEDED);
   }

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   CleanOldObjects();
  }

//+------------------------------------------------------------------+
//| Check if current time is inside operation window                 |
//+------------------------------------------------------------------+
bool IsWithinTradingTime()
  {
   datetime now = TimeCurrent();
   MqlDateTime tm;
   TimeToStruct(now, tm);

   if(tm.hour >= EAStartHour && tm.hour < EAStopHour)
     return true;
   else
     return false;
  }

//+------------------------------------------------------------------+
//| Check if EA has any open positions on current symbol             |
//+------------------------------------------------------------------+
bool HasOpenPositions()
  {
   for(int i=0; i<PositionsTotal(); i++)
     {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
        {
         if(PositionGetInteger(POSITION_MAGIC) == ExpertHandle() &&
            PositionGetString(POSITION_SYMBOL) == _Symbol)
           return true; // EA has open position(s) on symbol
        }
     }
   return false; // no open position found for EA
  }

//+------------------------------------------------------------------+
//| Place buy order with initial stop loss and take profit           |
//+------------------------------------------------------------------+
bool PlaceBuy()
  {
   MqlTradeRequest request;
   MqlTradeResult  result;
   ZeroMemory(request);
   ZeroMemory(result);

   double price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

   // Calculate SL if input > 0
   double sl_price = 0.0;
   if(InitialStopLossPoints > 0)
     {
      sl_price = NormalizeDouble(price - InitialStopLossPoints * _Point, _Digits);
      if(sl_price <= 0.0)
        {
         Print("Invalid SL price calculated for buy.");
         sl_price = 0.0; // Disable SL if invalid
        }
     }

   // Calculate TP if input > 0
   double tp_price = 0.0;
   if(InitialTakeProfitPoints > 0)
     {
      tp_price = NormalizeDouble(price + InitialTakeProfitPoints * _Point, _Digits);
     }

   request.action = TRADE_ACTION_DEAL;
   request.symbol = _Symbol;
   request.volume = Lots;
   request.type   = ORDER_TYPE_BUY;
   request.price  = price;
   request.sl     = sl_price;
   request.tp     = tp_price;
   request.deviation = 10;
   request.magic = ExpertHandle();

   if(!OrderSend(request, result))
     {
      PrintFormat("Buy order failed: %s", result.comment);
      return false;
     }
   else
     {
      PrintFormat("Buy order placed at price %.5f with SL at %.5f and TP at %.5f", price, sl_price, tp_price);
      return true;
     }
  }

//+------------------------------------------------------------------+
//| Place sell order with initial stop loss and take profit          |
//+------------------------------------------------------------------+
bool PlaceSell()
  {
   MqlTradeRequest request;
   MqlTradeResult  result;
   ZeroMemory(request);
   ZeroMemory(result);

   double price = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   // Calculate SL if input > 0
   double sl_price = 0.0;
   if(InitialStopLossPoints > 0)
     {
      sl_price = NormalizeDouble(price + InitialStopLossPoints * _Point, _Digits);
      if(sl_price <= 0.0)
        {
         Print("Invalid SL price calculated for sell.");
         sl_price = 0.0; // Disable SL if invalid
        }
     }

   // Calculate TP if input > 0
   double tp_price = 0.0;
   if(InitialTakeProfitPoints > 0)
     {
      tp_price = NormalizeDouble(price - InitialTakeProfitPoints * _Point, _Digits);
     }

   request.action = TRADE_ACTION_DEAL;
   request.symbol = _Symbol;
   request.volume = Lots;
   request.type   = ORDER_TYPE_SELL;
   request.price  = price;
   request.sl     = sl_price;
   request.tp     = tp_price;
   request.deviation = 10;
   request.magic = ExpertHandle();

   if(!OrderSend(request, result))
     {
      PrintFormat("Sell order failed: %s", result.comment);
      return false;
     }
   else
     {
      PrintFormat("Sell order placed at price %.5f with SL at %.5f and TP at %.5f", price, sl_price, tp_price);
      return true;
     }
  }

//+------------------------------------------------------------------+
//| Implement trailing stop for each position                        |
//+------------------------------------------------------------------+
void ManageTrailingStop()
{
   if(TrailingStopPoints <= 0)
      return; // Trailing stop disabled

   for(int i = PositionsTotal() - 1; i >= 0; i--)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionGetInteger(POSITION_MAGIC) != ExpertHandle())
         continue; // Only handle EA's own trades

      if(!PositionSelectByTicket(ticket))
         continue;

      ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
      double position_sl = PositionGetDouble(POSITION_SL);
      double position_open_price = PositionGetDouble(POSITION_PRICE_OPEN);
      double current_price = 0.0;
      double new_sl = 0.0;

      if(type == POSITION_TYPE_BUY)
         current_price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
      else if(type == POSITION_TYPE_SELL)
         current_price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
      else
         continue;

      // Check if the position is in profit
      bool is_profit = false;
      if(type == POSITION_TYPE_BUY && current_price > position_open_price)
         is_profit = true;
      else if(type == POSITION_TYPE_SELL && current_price < position_open_price)
         is_profit = true;

      if(!is_profit)
         continue; // Skip if the position is not in profit

      MqlTradeRequest request;
      MqlTradeResult result;
      ZeroMemory(request);
      ZeroMemory(result);

      if(type == POSITION_TYPE_BUY)
      {
         new_sl = current_price - TrailingStopPoints * _Point;
         if(position_sl < new_sl)
         {
            request.action = TRADE_ACTION_SLTP;
            request.position = ticket;
            request.sl = NormalizeDouble(new_sl, _Digits);
            request.tp = PositionGetDouble(POSITION_TP);
            if(!OrderSend(request, result))
            {
               PrintFormat("Trailing stop modification failed (buy): %s", result.comment);
            }
            else
            {
               PrintFormat("Trailing Stop moved up for Buy to %.5f", request.sl);
            }
         }
      }
      else if(type == POSITION_TYPE_SELL)
      {
         new_sl = current_price + TrailingStopPoints * _Point;
         if(position_sl > new_sl || position_sl == 0.0)
         {
            request.action = TRADE_ACTION_SLTP;
            request.position = ticket;
            request.sl = NormalizeDouble(new_sl, _Digits);
            request.tp = PositionGetDouble(POSITION_TP);
            if(!OrderSend(request, result))
            {
               PrintFormat("Trailing stop modification failed (sell): %s", result.comment);
            }
            else
            {
               PrintFormat("Trailing Stop moved down for Sell to %.5f", request.sl);
            }
         }
      }
   }
}

//+------------------------------------------------------------------+
//| Remove old chart objects to keep the chart clean                 |
//+------------------------------------------------------------------+
void CleanOldObjects()
  {
   if(ObjectFind(0, priceMoveLineName) != -1)
      ObjectDelete(0, priceMoveLineName);
   if(ObjectFind(0, priceMoveTextName) != -1)
      ObjectDelete(0, priceMoveTextName);
   if(ObjectFind(0, maxPosMoveTextName) != -1)
      ObjectDelete(0, maxPosMoveTextName);
   if(ObjectFind(0, maxNegMoveTextName) != -1)
      ObjectDelete(0, maxNegMoveTextName);
   if(ObjectFind(0, breakoutArrowNameBuy) != -1)
      ObjectDelete(0, breakoutArrowNameBuy);
   if(ObjectFind(0, breakoutArrowNameSell) != -1)
      ObjectDelete(0, breakoutArrowNameSell);
  }

//+------------------------------------------------------------------+
//| Draw line showing price movement                                 |
//+------------------------------------------------------------------+
void DrawPriceMoveLine(datetime time1, double price1, datetime time2, double price2)
  {
   if(ObjectFind(0, priceMoveLineName) == -1)
     {
      ObjectCreate(0, priceMoveLineName, OBJ_TREND, 0, time1, price1, time2, price2);
     }
   else
     {
      ObjectMove(0, priceMoveLineName, 0, time1, price1);
      ObjectMove(0, priceMoveLineName, 1, time2, price2);
     }

   ObjectSetInteger(0, priceMoveLineName, OBJPROP_COLOR, clrDodgerBlue);
   ObjectSetInteger(0, priceMoveLineName, OBJPROP_WIDTH, 2);
   ObjectSetInteger(0, priceMoveLineName, OBJPROP_RAY_RIGHT, false);
  }

//+------------------------------------------------------------------+
//| Draw current move speed and rate in top-left corner             |
//+------------------------------------------------------------------+
void DrawSpeedText(double pointsMoved, int secondsPassed)
  {
   string text = StringFormat("Move: %.1f pts\nTime: %d sec\nRate: %.2f pts/sec",
                              pointsMoved, secondsPassed, pointsMoved / secondsPassed);

   if(ObjectFind(0, priceMoveTextName) == -1)
     {
      ObjectCreate(0, priceMoveTextName, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, priceMoveTextName, OBJPROP_CORNER, 0);      // Top-left corner
      ObjectSetInteger(0, priceMoveTextName, OBJPROP_XDISTANCE, 10);  // 10 pixels from left
      ObjectSetInteger(0, priceMoveTextName, OBJPROP_YDISTANCE, 20);  // 10 pixels from top
      ObjectSetInteger(0, priceMoveTextName, OBJPROP_FONTSIZE, 12);
      ObjectSetInteger(0, priceMoveTextName, OBJPROP_COLOR, clrWhite);
      ObjectSetInteger(0, priceMoveTextName, OBJPROP_BACK, true);
     }

   ObjectSetString(0, priceMoveTextName, OBJPROP_TEXT, text);
  }

//+------------------------------------------------------------------+
//| Draw max positive move and rate label below current stats        |
//+------------------------------------------------------------------+
void DrawMaxPosMoveText()
  {
   string text = StringFormat("Max +move: %.1f pts\nMax +rate: %.2f pts/sec", maxPosPointsMoved, maxPosRatePointsPerSec);

   if(ObjectFind(0, maxPosMoveTextName) == -1)
     {
      ObjectCreate(0, maxPosMoveTextName, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, maxPosMoveTextName, OBJPROP_CORNER, 0);
      ObjectSetInteger(0, maxPosMoveTextName, OBJPROP_XDISTANCE, 10);
      ObjectSetInteger(0, maxPosMoveTextName, OBJPROP_YDISTANCE, 40); // under current stats label
      ObjectSetInteger(0, maxPosMoveTextName, OBJPROP_FONTSIZE, 12);
      ObjectSetInteger(0, maxPosMoveTextName, OBJPROP_COLOR, clrGreen);
      ObjectSetInteger(0, maxPosMoveTextName, OBJPROP_BACK, true);
     }

   ObjectSetString(0, maxPosMoveTextName, OBJPROP_TEXT, text);
  }

//+------------------------------------------------------------------+
//| Draw max negative move and rate label below positive label       |
//+------------------------------------------------------------------+
void DrawMaxNegMoveText()
  {
   string text = StringFormat("Max -move: %.1f pts\nMax -rate: %.2f pts/sec", maxNegPointsMoved, maxNegRatePointsPerSec);

   if(ObjectFind(0, maxNegMoveTextName) == -1)
     {
      ObjectCreate(0, maxNegMoveTextName, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, maxNegMoveTextName, OBJPROP_CORNER, 0);
      ObjectSetInteger(0, maxNegMoveTextName, OBJPROP_XDISTANCE, 10);
      ObjectSetInteger(0, maxNegMoveTextName, OBJPROP_YDISTANCE, 60); // under positive label
      ObjectSetInteger(0, maxNegMoveTextName, OBJPROP_FONTSIZE, 12);
      ObjectSetInteger(0, maxNegMoveTextName, OBJPROP_COLOR, clrRed);
      ObjectSetInteger(0, maxNegMoveTextName, OBJPROP_BACK, true);
     }

   ObjectSetString(0, maxNegMoveTextName, OBJPROP_TEXT, text);
  }

//+------------------------------------------------------------------+
//| Draw breakout arrow on chart                                     |
//+------------------------------------------------------------------+
void DrawBreakoutArrow(bool isBuy, datetime time_, double price_)
  {
   string name = isBuy ? breakoutArrowNameBuy : breakoutArrowNameSell;
   int arrowCode = isBuy ? 233 : 234; // Wingdings arrows: 233=up, 234=down
   color clrArrow = isBuy ? clrLime : clrRed;

   // Delete old arrow
   if(ObjectFind(0, name) != -1)
      ObjectDelete(0, name);

   ObjectCreate(0, name, OBJ_ARROW, 0, time_, price_);
   ObjectSetInteger(0, name, OBJPROP_ARROWCODE, arrowCode);
   ObjectSetInteger(0, name, OBJPROP_COLOR, clrArrow);
   ObjectSetInteger(0, name, OBJPROP_WIDTH, 3);
  }

//+------------------------------------------------------------------+
//| Check price speed and trade accordingly                          |
//+------------------------------------------------------------------+
void CheckAndTrade()
  {
   datetime now = TimeCurrent();
   
   // Wait 5 minutes (300 seconds) after trade close before opening new trades
   if(lastTradeCloseTime != 0 && (now - lastTradeCloseTime) < 300)
     {
      PrintFormat("Waiting after trade close. %.0f seconds left.", 300 - (now - lastTradeCloseTime));
      return; // do not attempt a new trade yet
     }

   // Wait for all open EA trades to close before opening new trades
   if(HasOpenPositions())
      return;

   if(!IsWithinTradingTime())
      return;

   double current_price = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   double points_moved = (current_price - priceAtLastCheck) / _Point;
   int time_diff = (int)(now - lastCheckTime);

   if(time_diff < CheckInterval)
      return;

   // Clear old drawings to keep chart clean on each run
   CleanOldObjects();

   // Draw line showing price move between last check and now
   DrawPriceMoveLine(lastCheckTime, priceAtLastCheck, now, current_price);

   // Draw current move stats label
   DrawSpeedText(points_moved, time_diff);

   // Calculate absolute values and rate
   double absPointsMoved = MathAbs(points_moved);
   double rate = absPointsMoved / time_diff;

   // Update max positive move and rate
   if(points_moved > 0)  // positive move
     {
      if(points_moved > maxPosPointsMoved)
         maxPosPointsMoved = points_moved;
      if(rate > maxPosRatePointsPerSec)
         maxPosRatePointsPerSec = rate;
     }
   else if(points_moved < 0) // negative move
     {
      double negMoveAbs = -points_moved; // positive absolute value
      if(negMoveAbs > maxNegPointsMoved)
         maxNegPointsMoved = negMoveAbs;
      if(rate > maxNegRatePointsPerSec)
         maxNegRatePointsPerSec = rate;
     }

   // Draw both max move labels
   DrawMaxPosMoveText();
   DrawMaxNegMoveText();

   if(points_moved >= PointsThreshold)
     {
      PrintFormat("Bullish breakout detected: Moved up %.1f points in %d seconds", points_moved, time_diff);
      DrawBreakoutArrow(true, now, current_price);

      for(int i = 0; i < TradesPerSignal; i++)
         PlaceBuy();
     }
   else if(points_moved <= -PointsThreshold)
     {
      PrintFormat("Bearish breakout detected: Moved down %.1f points in %d seconds", points_moved, time_diff);
      DrawBreakoutArrow(false, now, current_price);

      for(int i = 0; i < TradesPerSignal; i++)
         PlaceSell();
     }

   lastCheckTime = now;
   priceAtLastCheck = current_price;
  }

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   ManageTrailingStop();

   int currentPositionsCount = 0;
   for(int i=0; i<PositionsTotal(); i++)
     {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
        {
         if(PositionGetInteger(POSITION_MAGIC) == ExpertHandle() &&
            PositionGetString(POSITION_SYMBOL) == _Symbol)
           currentPositionsCount++;
        }
     }

   //--- UPDATED for Alternative 1: Reset snapshot when all positions closed
   if(prevPositionsCount > 0 && currentPositionsCount == 0)
     {
      lastTradeCloseTime = TimeCurrent();
      
      lastCheckTime = lastTradeCloseTime;                                  // Reset snapshot time
      priceAtLastCheck = SymbolInfoDouble(_Symbol, SYMBOL_BID);           // Reset snapshot price
      
      PrintFormat("Trade closed at %s - resetting lastCheckTime and priceAtLastCheck", TimeToString(lastTradeCloseTime, TIME_SECONDS));
     }

   prevPositionsCount = currentPositionsCount;

   CheckAndTrade();
  }

//+------------------------------------------------------------------+
//| Helper: return magic number                                       |
//+------------------------------------------------------------------+
uint ExpertHandle()
  {
   return(123456);
  }