I have 2 EAs working on a pair, I want to open just one

 
//+------------------------------------------------------------------+
//| ReverseTrade.mq4                                                  |
//| A fully functioning EA that opens a reverse trade when price hits |
//| -50% of SL of an existing trade, and keeps original trade open.   |
//+------------------------------------------------------------------+

// Input Parameters
extern double AccountRiskPercent = 2.5;  // Account risk percentage for reverse trade
extern double Slippage = 3;              // Slippage allowance
extern int reverseMagic = 12345;         // Magic number for reverse trades

// Initialization function
int OnInit()
{
   Print("Reverse Trade EA Initialized");
   return(INIT_SUCCEEDED);
}

// Function that runs on each tick
void OnTick()
{
   ManageReverseTrades();
}

// Function to manage reverse trades
void ManageReverseTrades()
{
   for (int i = OrdersTotal() - 1; i >= 0; i--)
   {
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
      {
         // Skip trades that are not of the current symbol or magic number
         if (OrderSymbol() != Symbol()) continue;
         if (OrderMagicNumber() == reverseMagic) continue;

         // Handle both buy and sell orders
         if (OrderType() == OP_BUY || OrderType() == OP_SELL)
         {
            double entryPrice = OrderOpenPrice();
            double sl = OrderStopLoss();
            if (sl <= 0) continue;

            double currentPrice = (OrderType() == OP_BUY) ? Bid : Ask;
            double midSL = (OrderType() == OP_BUY) ? entryPrice - 0.5 * (entryPrice - sl)
                                                   : entryPrice + 0.5 * (sl - entryPrice);

            // Check if price has reached 50% toward SL
            bool triggerReverse = (OrderType() == OP_BUY && currentPrice <= midSL) ||
                                  (OrderType() == OP_SELL && currentPrice >= midSL);

            if (triggerReverse)
            {
               // Calculate TP and SL for reverse trade
               double reverseEntryPrice = currentPrice;
               double reverseTP = sl;
               double reverseSL;
               double tpDistance = MathAbs(sl - currentPrice);
               reverseSL = (OrderType() == OP_BUY) ? reverseTP + 4 * tpDistance
                                                   : reverseTP - 4 * tpDistance;

               // Risk calculation
               double SL_Pips = MathAbs(reverseSL - reverseTP) / Point;
               double TickValue = MarketInfo(Symbol(), MODE_TICKVALUE);
               double RiskAmount = AccountBalance() * (AccountRiskPercent / 100.0);
               double LotSize = RiskAmount / (SL_Pips * TickValue);
               LotSize = NormalizeDouble(LotSize, 2);

               // Normalize prices
               reverseEntryPrice = NormalizeDouble(reverseEntryPrice, Digits);
               reverseTP = NormalizeDouble(reverseTP, Digits);
               reverseSL = NormalizeDouble(reverseSL, Digits);

               // Check limits
               double minLot = MarketInfo(Symbol(), MODE_MINLOT);
               double maxLot = MarketInfo(Symbol(), MODE_MAXLOT);
               LotSize = MathMax(minLot, MathMin(maxLot, LotSize));

               int newTicket;
               if (OrderType() == OP_BUY)
               {
                  // Open reverse SELL
                  newTicket = OrderSend(Symbol(), OP_SELL, LotSize, reverseEntryPrice, Slippage,
                                        reverseSL, reverseTP, "Reverse from BUY", reverseMagic, 0, clrRed);
               }
               else
               {
                  // Open reverse BUY
                  newTicket = OrderSend(Symbol(), OP_BUY, LotSize, reverseEntryPrice, Slippage,
                                        reverseSL, reverseTP, "Reverse from SELL", reverseMagic, 0, clrBlue);
               }

               if (newTicket < 0)
                  Print("Reverse order failed: ", GetLastError());
               else
                  Print("Reverse trade opened. Ticket: ", newTicket);
            }
         }
      }
   }
}

 
IT Opens alot of trades, i just need one reversal, only one
 
Rami Khattab #:
IT Opens alot of trades, i just need one reversal, only one

i recommend that you look in codebase for eas. There is many eas in there with examples of how to limit opening of trades to 1 and different ways that may be more suited to your liking. Otherwise, you will only get responses if someone finds your request challenging. Not many questions get answered unless the op has shown initiative, which you haven not. The code you have above has bits missing. Even if it was limited to a single trade, i doubt that the code would do what you want for at least 3 reasons that I can see. 2 of them may work, despite giving errors.

 
Rami Khattab #:
IT Opens alot of trades, i just need one reversal, only one

the reason for that is because when it opens a trade, it then opens the opposite trade, and then a trad in the opposite direction of the new trade, and another and another. what do you mean by limiting to 1 trade? if 1 trade is already open, then, the code above would never open a 2nd.

 
Rami Khattab #:
IT Opens alot of trades, i just need one reversal, only one

look in codebase for scripts. There is several that do exactly what you have done above. You attached the script to chart, then, it waits until it is XX distance from the open price of a trade, and then opens a trade in reverse, and then the script detaches itself from the chart, normally, but you could modify it as an EA or keep it as script and not detach itself.