//+------------------------------------------------------------------+
//|                                                ThreePipTrader.mq5 |
//|                                      Created by OpenAI Assistant |
//+------------------------------------------------------------------+
#property copyright "OpenAI"
#property link      "https://openai.com/"
#property version   "1.00"
#property strict

// Inputs
input double Lots = 0.1;         // Lot size
input int    PipDistance = 3;    // Distance in pips to trigger orders
input int    ReversePips = 6;    // Pips reversal to open opposite trade
input int    TakeProfitPips = 3; // Take Profit in pips

// Global variables
double BuyTriggerPrice;
double SellTriggerPrice;
bool   BuyOrderOpen = false;
bool   SellOrderOpen = false;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   // Initialize trigger prices to current Bid price
   double price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   BuyTriggerPrice  = price + (PipDistance * _Point);
   SellTriggerPrice = price - (PipDistance * _Point);
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);

   // Check if there are open orders
   BuyOrderOpen = IsOrderOpen(ORDER_TYPE_BUY);
   SellOrderOpen = IsOrderOpen(ORDER_TYPE_SELL);

   // If no orders are open, check for new trade conditions
   if(!BuyOrderOpen && !SellOrderOpen)
   {
      // Check for buy condition
      if(bid >= BuyTriggerPrice)
      {
         OpenOrder(ORDER_TYPE_BUY);
         // Set new trigger prices
         BuyTriggerPrice = bid + (ReversePips * _Point);
         SellTriggerPrice = bid - (ReversePips * _Point);
      }
      // Check for sell condition
      else if(bid <= SellTriggerPrice)
      {
         OpenOrder(ORDER_TYPE_SELL);
         // Set new trigger prices
         BuyTriggerPrice = bid + (ReversePips * _Point);
         SellTriggerPrice = bid - (ReversePips * _Point);
      }
   }
   else
   {
      // If a buy order is open and price reverses by ReversePips, open a sell trade with TP
      if(BuyOrderOpen && bid <= (BuyTriggerPrice - (ReversePips * _Point)))
      {
         OpenOrder(ORDER_TYPE_SELL, TakeProfitPips);
         BuyOrderOpen = false; // Close the buy order status
      }
      // If a sell order is open and price reverses by ReversePips, open a buy trade with TP
      else if(SellOrderOpen && bid >= (SellTriggerPrice + (ReversePips * _Point)))
      {
         OpenOrder(ORDER_TYPE_BUY, TakeProfitPips);
         SellOrderOpen = false; // Close the sell order status
      }
   }
}

//+------------------------------------------------------------------+
//| Function to check if there is an open order of a specific type   |
//+------------------------------------------------------------------+
bool IsOrderOpen(ENUM_ORDER_TYPE type)
{
   ulong ticket = PositionGetTicket(0);
   if(ticket != 0)
   {
      if(PositionGetInteger(POSITION_TYPE) == type)
         return true;
   }
   return false;
}

//+------------------------------------------------------------------+
//| Function to open an order                                        |
//+------------------------------------------------------------------+
void OpenOrder(ENUM_ORDER_TYPE type, int tp_pips=0)
{
   MqlTradeRequest request;
   MqlTradeResult  result;
   ZeroMemory(request);
   ZeroMemory(result);

   request.action   = TRADE_ACTION_DEAL;
   request.symbol   = _Symbol;
   request.volume   = Lots;
   request.type     = type;
   request.price    = (type == ORDER_TYPE_BUY) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK)
                                               : SymbolInfoDouble(_Symbol, SYMBOL_BID);
   request.deviation = 10;

   // Set Take Profit if specified
   if(tp_pips > 0)
   {
      double tp_price = (type == ORDER_TYPE_BUY) ? request.price + (tp_pips * _Point)
                                                 : request.price - (tp_pips * _Point);
      request.tp = NormalizeDouble(tp_price, _Digits);
   }

   // Send the order
   if(!OrderSend(request, result))
   {
      Print("OrderSend failed: ", GetLastError());
   }
   else
   {
      if(result.retcode != TRADE_RETCODE_DONE)
      {
         Print("OrderSend failed, retcode=", result.retcode);
      }
   }
}

//+------------------------------------------------------------------+
it is not executing any order can you fix it