Помогите исправить робот ( написанный ИИ Capilot из EDGE браузера )

 

Вот код робота. Нужно чтобы робот открыл сделку, подождал 12 часов ( переменная что я задам ), и закрыл сделку, и опять открыл сделку новую. 


#property copyright "MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

// параметры робота
extern int NumberOfTrades = 10;
extern int DuplicateTrades = 1;
extern double Profit = 77;
extern double Stop = 77;
extern double Lot = 1;
extern int TradeDirection1 = 0;
extern int TradeDirection2 = 0;
extern int TradeDirection3 = 0;
extern int TradeDirection4 = 0;
extern int TradeDirection5 = 1;
extern int TradeDirection6 = 1;
extern int TradeDirection7 = 1;
extern int TradeDirection8 = 1;
extern int TradeDirection9 = 0;
extern int TradeDirection10 = 1;

int totalTrades = 0;
datetime tradeOpenTime; // добавлено

int start()
{
   if(totalTrades < NumberOfTrades && OrdersTotal() == 0)
   {
      int currentDirection;
      switch(totalTrades) {
         case 0: currentDirection = TradeDirection1; break;
         case 1: currentDirection = TradeDirection2; break;
         case 2: currentDirection = TradeDirection3; break;
         case 3: currentDirection = TradeDirection4; break;
         case 4: currentDirection = TradeDirection5; break;
         case 5: currentDirection = TradeDirection6; break;
         case 6: currentDirection = TradeDirection7; break;
         case 7: currentDirection = TradeDirection8; break;
         case 8: currentDirection = TradeDirection9; break;
         case 9: currentDirection = TradeDirection10; break;
      }
      for(int i=0; i<DuplicateTrades; i++)
      {
         int ticket;
         if(currentDirection == 0)
            ticket = OrderSend(Symbol(), OP_BUY, Lot, Ask, 3, Ask - Stop*Point, Ask + Profit*Point);
         else if(currentDirection == 1)
            ticket = OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, Bid + Stop*Point, Bid - Profit*Point);
         
         if(ticket < 0)
         {
            Print("OrderSend failed with error #", GetLastError());
         }
      }
      
      totalTrades++;
      tradeOpenTime = TimeCurrent(); // добавлено
   }

   // добавлено
   if (totalTrades > 0 && TimeCurrent() - tradeOpenTime >= 12 * 60 * 60) // проверка на прошедшие 12 часов
   {
      for(int i=OrdersTotal()-1; i>=0; i--)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
            if(OrderSymbol() == Symbol())
            {
               if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, clrNONE))
               {
                  Print("OrderClose failed with error #", GetLastError());
               }
            }
         }
         else
         {
            Print("OrderSelect failed with error #", GetLastError());
         }
      }
      // Сброс времени открытия сделки после закрытия
      tradeOpenTime = 0;
   }
   return(0);
}


Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2024.03.20
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
А помочь чем?
 
Aleksey Radzisheuski:
Вот код робота. Нужно чтобы робот открыл сделку, подождал 12 часов ( переменная что я задам ), и закрыл сделку, и опять открыл сделку новую. 
Sergey Gridnev #:
А помочь чем?

Нужно чтобы робот открыл сделку, подождал 12 часов ( переменная что я задам ), и закрыл сделку, и опять открыл сделку новую. 


Робот только в тестере открывает и закрывает через каждые 12 часов. А в реальной торговле только открывает первую сделку. 

 
Aleksey Radzisheuski #:

Нужно чтобы робот открыл сделку, подождал 12 часов ( переменная что я задам ), и закрыл сделку, и опять открыл сделку новую. 


Робот только в тестере открывает и закрывает через каждые 12 часов. А в реальной торговле только открывает первую сделку. 

Укажите об этом упущении ИИ. Интересно, как справится.

Сейчас эксперт рассчитан только на непрерывную работу. Если в онлайн выполнить это условие, то будет как в тестере. 

 
Ihor Herasko #:

Укажите об этом упущении ИИ. Интересно, как справится.

Сейчас эксперт рассчитан только на непрерывную работу. Если в онлайн выполнить это условие, то будет как в тестере. 

Не компилируется файл робота. ( ИИ исправно исправляет код робота. Но есть недочёты, когда ИИ даже при разных формулировках не может сделать и исправить нюансы в коде, например не может учесть спред в выставлении ордеров и т.д. В любом случае пока что нужен кодер который сможет хотя бы прочитать и до править код ). 



 

Так будет компилироваться, но ошибку желательно понять.

#property copyright "MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

// параметры робота
extern int NumberOfTrades = 10;
extern int DuplicateTrades = 1;
extern double Profit = 77;
extern double Stop = 77;
extern double Lot = 1;
extern int TradeDirection1 = 0;
extern int TradeDirection2 = 0;
extern int TradeDirection3 = 0;
extern int TradeDirection4 = 0;
extern int TradeDirection5 = 1;
extern int TradeDirection6 = 1;
extern int TradeDirection7 = 1;
extern int TradeDirection8 = 1;
extern int TradeDirection9 = 0;
extern int TradeDirection10 = 1;

int totalTrades = 0, i;
datetime tradeOpenTime; // добавлено

int start()
{
   if(totalTrades < NumberOfTrades && OrdersTotal() == 0)
   {
      int currentDirection;
      switch(totalTrades) {
         case 0: currentDirection = TradeDirection1; break;
         case 1: currentDirection = TradeDirection2; break;
         case 2: currentDirection = TradeDirection3; break;
         case 3: currentDirection = TradeDirection4; break;
         case 4: currentDirection = TradeDirection5; break;
         case 5: currentDirection = TradeDirection6; break;
         case 6: currentDirection = TradeDirection7; break;
         case 7: currentDirection = TradeDirection8; break;
         case 8: currentDirection = TradeDirection9; break;
         case 9: currentDirection = TradeDirection10; break;
      }
      for(i=0; i<DuplicateTrades; i++)
      {
         int ticket;
         if(currentDirection == 0)
            ticket = OrderSend(Symbol(), OP_BUY, Lot, Ask, 3, Ask - Stop*Point, Ask + Profit*Point);
         else if(currentDirection == 1)
            ticket = OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, Bid + Stop*Point, Bid - Profit*Point);
         
         if(ticket < 0)
         {
            Print("OrderSend failed with error #", GetLastError());
         }
      }
      
      totalTrades++;
      tradeOpenTime = TimeCurrent(); // добавлено
   }

   // добавлено
   if (totalTrades > 0 && TimeCurrent() - tradeOpenTime >= 12 * 60 * 60) // проверка на прошедшие 12 часов
   {
      for(i=OrdersTotal()-1; i>=0; i--)
      {
         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
            if(OrderSymbol() == Symbol())
            {
               if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, clrNONE))
               {
                  Print("OrderClose failed with error #", GetLastError());
               }
            }
         }
         else
         {
            Print("OrderSelect failed with error #", GetLastError());
         }
      }
      // Сброс времени открытия сделки после закрытия
      tradeOpenTime = 0;
   }
   return(0);
}



 
Renat Akhtyamov #:
#property copyright "MetaQuotes Software Corp." #property link      "https://www.mql5.com" #property version   "1.00" // параметры робота extern int NumberOfTrades = 10; extern int DuplicateTrades = 1; extern double Profit = 77; extern double Stop = 77; extern double Lot = 1; extern int TradeDirection1 = 0; extern int TradeDirection2 = 0; extern int TradeDirection3 = 0; extern int TradeDirection4 = 0; extern int TradeDirection5 = 1; extern int TradeDirection6 = 1; extern int TradeDirection7 = 1; extern int TradeDirection8 = 1; extern int TradeDirection9 = 0; extern int TradeDirection10 = 1; int totalTrades = 0, i; datetime tradeOpenTime; // добавлено int start() {    if(totalTrades < NumberOfTrades && OrdersTotal() == 0)    {       int currentDirection;       switch(totalTrades) {          case 0: currentDirection = TradeDirection1; break;          case 1: currentDirection = TradeDirection2; break;          case 2: currentDirection = TradeDirection3; break;          case 3: currentDirection = TradeDirection4; break;          case 4: currentDirection = TradeDirection5; break;          case 5: currentDirection = TradeDirection6; break;          case 6: currentDirection = TradeDirection7; break;          case 7: currentDirection = TradeDirection8; break;          case 8: currentDirection = TradeDirection9; break;          case 9: currentDirection = TradeDirection10; break;       }       for(i=0; i<DuplicateTrades; i++)       {          int ticket;          if(currentDirection == 0)             ticket = OrderSend(Symbol(), OP_BUY, Lot, Ask, 3, Ask - Stop*Point, Ask + Profit*Point);          else if(currentDirection == 1)             ticket = OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, Bid + Stop*Point, Bid - Profit*Point);                   if(ticket < 0)          {             Print("OrderSend failed with error #", GetLastError());          }       }              totalTrades++;       tradeOpenTime = TimeCurrent(); // добавлено    }    // добавлено    if (totalTrades > 0 && TimeCurrent() - tradeOpenTime >= 12 * 60 * 60) // проверка на прошедшие 12 часов    {       for(i=OrdersTotal()-1; i>=0; i--)       {          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))          {             if(OrderSymbol() == Symbol())             {                if(!OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, clrNONE))                {                   Print("OrderClose failed with error #", GetLastError());                }             }          }          else          {             Print("OrderSelect failed with error #", GetLastError());          }       }       // Сброс времени открытия сделки после закрытия       tradeOpenTime = 0;    }    return(0); }


Благодарю за правку робота. 

Смысл робота таков. 

Робот открывает сделки по порядку как я укажу из направлений бай и селл, переменных 

extern int TradeDirection1 = 0;

И через каждые 12 часов принудительно закрывает сделку и открывает её. 



Пользуясь моментом. Возможно есть время добавить учёт спреда в робот код ниже. Тоже написанный ИИ. 


//+------------------------------------------------------------------+
//|                                                      Robot.mq4   |
//|                        Copyright 2024, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+

#property copyright "MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

// параметры робота
extern int NumberOfTrades = 10;
extern double Profit = 44;
extern double Stop = 44;
extern double Lot = 1;
extern string TradeDirection1 = "BUY";
extern string TradeDirection2 = "BUY";
extern string TradeDirection3 = "BUY";
extern string TradeDirection4 = "BUY";
extern string TradeDirection5 = "SELL";
extern string TradeDirection6 = "SELL";
extern string TradeDirection7 = "SELL";
extern string TradeDirection8 = "SELL";
extern string TradeDirection9 = "BUY";
extern string TradeDirection10 = "SELL";
extern int DuplicateTrades = 1; // добавлено

int totalTrades = 0; // добавлено

int start()
{
   if(totalTrades < NumberOfTrades && OrdersTotal() == 0) // проверка на наличие открытых сделок
   {
      string currentDirection;
      switch(totalTrades) {
         case 0: currentDirection = TradeDirection1; break;
         case 1: currentDirection = TradeDirection2; break;
         case 2: currentDirection = TradeDirection3; break;
         case 3: currentDirection = TradeDirection4; break;
         case 4: currentDirection = TradeDirection5; break;
         case 5: currentDirection = TradeDirection6; break;
         case 6: currentDirection = TradeDirection7; break;
         case 7: currentDirection = TradeDirection8; break;
         case 8: currentDirection = TradeDirection9; break;
         case 9: currentDirection = TradeDirection10; break;
      }
      for(int i=0; i<DuplicateTrades; i++) // добавлено
      {
         if(currentDirection == "BUY" || currentDirection == "БАЙ" || currentDirection == "Бай" || currentDirection == "бай")
            OrderSend(Symbol(), OP_BUY, Lot, Ask, 3, Ask - Stop*Point, Ask + Profit*Point);
         else if(currentDirection == "SELL" || currentDirection == "СЕЛЛ" || currentDirection == "Селл" || currentDirection == "селл")
            OrderSend(Symbol(), OP_SELL, Lot, Bid, 3, Bid + Stop*Point, Bid - Profit*Point);
      }
      
      totalTrades++; // добавлено
   }
   return(0);
}
//+------------------------------------------------------------------+
Причина обращения: