MQL5 Errors: unexpected token and others, pls help TT

 

Hi I am a newbie who doesn't know how to write the code properly and found this kind of error using ai, please help fixing this I am hopeless TT

Error logs & MQL5 Respectively

Description     File Name       Line    Column
'SELECT_BY_POS' - undeclared identifier Lastone.mq5     168     29
'OrderSelect' - wrong parameters count  Lastone.mq5     168     14
built-in: bool OrderSelect(ulong)       Lastone.mq5     168     14
'ORDER_PROFIT' - undeclared identifier  Lastone.mq5     176     50
'OrderGetDouble' - no one of the overloads can be applied to the function call  Lastone.mq5     176     35
could be one of 2 function(s)   Lastone.mq5     176     35
built-in: double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE)     Lastone.mq5     176     35
built-in: bool OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE, double&)      Lastone.mq5     176     35
'TimeMinute' - undeclared identifier    Lastone.mq5     26      8
'current_time' - some operator expected Lastone.mq5     26      19
'(' - unbalanced left parenthesis       Lastone.mq5     26      7
'==' - operand expected Lastone.mq5     26      33
'TimeSeconds' - undeclared identifier   Lastone.mq5     26      41
'current_time' - some operator expected Lastone.mq5     26      53
expression has no effect        Lastone.mq5     26      38
')' - unexpected token  Lastone.mq5     26      71
expression has no effect        Lastone.mq5     26      70
'iMAOnArray' - undeclared identifier    Lastone.mq5     55      21
',' - unexpected token  Lastone.mq5     55      42
'atr_buffer' - some operator expected   Lastone.mq5     55      32
'period' - semicolon expected   Lastone.mq5     55      43
',' - unexpected token  Lastone.mq5     55      49
expression has no effect        Lastone.mq5     55      43
',' - unexpected token  Lastone.mq5     55      51
expression has no effect        Lastone.mq5     55      50
',' - unexpected token  Lastone.mq5     55      53
expression has no effect        Lastone.mq5     55      52
')' - unexpected token  Lastone.mq5     55      62
expression has no effect        Lastone.mq5     55      54
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
input double lot_multiplier = 1.0;   // User input, number with two decimal digits
input int time_multiplier = 7;       // User input, integer
input double min_lot_size = 0.01;    // User input, number with two decimal digits

int OnInit()
  {
   EventSetTimer(60); // Set timer to check every minute
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   EventKillTimer();
  }
//+------------------------------------------------------------------+
//| Expert timer function                                            |
//+------------------------------------------------------------------+
void OnTimer()
  {
   datetime current_time = TimeCurrent();
   if (TimeMinute(current_time) == 0 && TimeSeconds(current_time) == 0)
     {
      double ema_atr_div_3 = CalculateEMAATR(Symbol(), PERIOD_H4, 1) / 3;
      Print("EMA of ATR / 3: ", ema_atr_div_3);
      if (ema_atr_div_3 < 0.0009)  // 90 points in fractional form (assuming 5-digit broker)
        {
         Print("EMA of ATR / 3 is less than 90 points, no orders placed");
        }
      else
        {
         double open_price = iOpen(Symbol(), PERIOD_H4, 0);
         PlaceOrders(open_price, ema_atr_div_3, min_lot_size);
        }
     }
  }
//+------------------------------------------------------------------+
//| Calculate EMA of ATR                                             |
//+------------------------------------------------------------------+
double CalculateEMAATR(string symbol, ENUM_TIMEFRAMES timeframe, int period)
  {
   int atr_handle = iATR(symbol, timeframe, period);
   double atr_buffer[];

   if (CopyBuffer(atr_handle, 0, 0, 3, atr_buffer) <= 0)
     {
      Print("Failed to copy ATR buffer");
      return 0.0;
     }

   int ema_handle = iMAOnArray(atr_buffer,period,0,0,MODE_EMA);
   double ema_buffer[];

   if (CopyBuffer(ema_handle, 0, 0, 3, ema_buffer) <= 0)
     {
      Print("Failed to copy EMA buffer");
      return 0.0;
     }

   return ema_buffer[0];
  }
//+------------------------------------------------------------------+
//| Place pending orders                                             |
//+------------------------------------------------------------------+
void PlaceOrders(double open_price, double ema_atr_div_3, double lot_size)
  {
   double buy_stop_price = open_price + ema_atr_div_3;
   double sell_stop_price = open_price - ema_atr_div_3;

   double buy_tp = open_price + ema_atr_div_3 * 2;
   double sell_tp = open_price - ema_atr_div_3 * 2;

   MqlTradeRequest buy_request, sell_request;
   MqlTradeResult buy_result, sell_result;

   ZeroMemory(buy_request);
   ZeroMemory(sell_request);
   ZeroMemory(buy_result);
   ZeroMemory(sell_result);

   buy_request.action = TRADE_ACTION_PENDING;
   buy_request.symbol = Symbol();
   buy_request.volume = lot_size;
   buy_request.type = ORDER_TYPE_BUY_STOP;
   buy_request.price = buy_stop_price;
   buy_request.tp = buy_tp;
   buy_request.sl = open_price;
   buy_request.deviation = 10;
   buy_request.magic = 234000;
   buy_request.comment = "Buy Stop Order";
   buy_request.type_time = ORDER_TIME_GTC;
   buy_request.type_filling = ORDER_FILLING_RETURN;

   sell_request.action = TRADE_ACTION_PENDING;
   sell_request.symbol = Symbol();
   sell_request.volume = lot_size;
   sell_request.type = ORDER_TYPE_SELL_STOP;
   sell_request.price = sell_stop_price;
   sell_request.tp = sell_tp;
   sell_request.sl = open_price;
   sell_request.deviation = 10;
   sell_request.magic = 234000;
   sell_request.comment = "Sell Stop Order";
   sell_request.type_time = ORDER_TIME_GTC;
   sell_request.type_filling = ORDER_FILLING_RETURN;

   if (!OrderSend(buy_request, buy_result))
     {
      Print("Buy Stop Order failed, retcode=", buy_result.retcode);
     }
   else
     {
      Print("Buy Stop Order placed successfully");
     }

   if (!OrderSend(sell_request, sell_result))
     {
      Print("Sell Stop Order failed, retcode=", sell_result.retcode);
     }
   else
     {
      Print("Sell Stop Order placed successfully");
     }
  }
//+------------------------------------------------------------------+
//| Close pending order                                              |
//+------------------------------------------------------------------+
void ClosePendingOrder(ulong ticket)
  {
   MqlTradeRequest request;
   MqlTradeResult result;

   ZeroMemory(request);
   ZeroMemory(result);

   request.action = TRADE_ACTION_REMOVE;
   request.order = ticket;

   if (!OrderSend(request, result))
     {
      Print("Failed to close pending order, retcode=", result.retcode);
     }
   else
     {
      Print("Pending order closed successfully");
     }
  }
//+------------------------------------------------------------------+
//| Main trading logic                                               |
//+------------------------------------------------------------------+
void OnTick()
  {
   static double lot_size = min_lot_size;
   static int trade_count = 0;
   static int max_trade_count = time_multiplier;
   double open_price = iOpen(Symbol(), PERIOD_H4, 0);
   double ema_atr_div_3 = CalculateEMAATR(Symbol(), PERIOD_H4, 1) / 3;

   while (trade_count < max_trade_count)
     {
      int total_orders = OrdersTotal();
      for (int i = 0; i < total_orders; i++)
        {
         if (OrderSelect(i, SELECT_BY_POS))
           {
            int order_type = (int)OrderGetInteger(ORDER_TYPE);
            if (order_type == ORDER_TYPE_BUY_STOP || order_type == ORDER_TYPE_SELL_STOP)
              {
               double close_price = OrderGetDouble(ORDER_PRICE_CURRENT);
               if (close_price != 0)
                 {
                  double profit = OrderGetDouble(ORDER_PROFIT);
                  ulong ticket = OrderGetInteger(ORDER_TICKET);
                  if (profit >= 0)
                    {
                     Print("Take Profit reached for order ", ticket, ", ending flow");
                     return;
                    }
                  else
                    {
                     trade_count++;
                     if (trade_count >= max_trade_count)
                       {
                        Print("Reached maximum number of trades, stopping.");
                        return;
                       }

                     lot_size = lot_size * lot_multiplier;
                     lot_size = MathMax(lot_size, min_lot_size);

                     if (order_type == ORDER_TYPE_BUY_STOP)
                       {
                        Print("Stop Loss hit for Buy order ", ticket, ", opening Sell order");
                        PlaceOrders(close_price, ema_atr_div_3, lot_size);
                       }
                     else
                       {
                        Print("Stop Loss hit for Sell order ", ticket, ", opening Buy order");
                        PlaceOrders(close_price, ema_atr_div_3, lot_size);
                       }
                     ClosePendingOrder(ticket);
                    }
                 }
              }
           }
        }
      Sleep(10000);  // Check every 10 seconds
     }
  }
//+------------------------------------------------------------------+
 
At the moment, the AI ​​is generating nonsense for MQL. You need programming skills to even use AI assistance. The code you generated is useless and does not provide any value. Either learn to program or hire a programmer.
 
Vladislav Boyko #:
At the moment, the AI ​​is generating nonsense for MQL. You need programming skills to even use AI assistance. The code you generated is useless and does not provide any value. Either learn to program or hire a programmer.
Thx for your suggestion sir, I would like to hire a programmer too, do you know where the market place is and what's the price range
 

Freelance section is the page you are looking for. Place your job there with all details, and choose the developer who have the best profile and price.

As already explained, AI for mql is actually useless. 99% of time you will get wrong code, in the other 1% of case you can be lucky but without a proper error handling and coding approach, so using that kind of code with real money can be very dangerous.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.07.17
  • www.mql5.com
The largest freelance service with MQL5 application developers