Limitation de trades par jour

MQL5 Experts

Specification

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   // Initialisation des paramètres
   Print("Expert Advisor initialisé.");
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Fonction principale de l'EA                                      |
//+------------------------------------------------------------------+
void OnTick()
  {
   // Vérifier si le nombre maximum de trades est atteint
   if(TradesCountToday() >= 2)
     {
      Print("Nombre maximum de trades atteint pour aujourd'hui.");
      return;
     }

   // Logique pour ouvrir un trade (exemple : simple achat)
   if(ConditionToTrade()) // Remplacez cette condition par votre logique
     {
      double lotSize = 0.1; // Taille du lot
      if(OrderSend(Symbol(), OP_BUY, lotSize, Ask, 2, 0, 0, "Trade Limit EA") > 0)
        {
         Print("Trade exécuté avec succès.");
        }
      else
        {
         Print("Erreur lors de l'exécution du trade : ", GetLastError());
        }
     }
  }

//+------------------------------------------------------------------+
//| Fonction pour compter les trades effectués aujourd'hui           |
//+------------------------------------------------------------------+
int TradesCountToday()
  {
   int count = 0;
   datetime startOfDay = iTime(Symbol(), PERIOD_D1, 0); // Heure début de la journée
   for(int i = OrdersHistoryTotal() - 1; i >= 0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
        {
         if(OrderType() <= OP_SELL && OrderCloseTime() >= startOfDay)
           {
            count++;
           }
        }
     }
   return count;
  }

//+------------------------------------------------------------------+
//| Fonction pour votre logique de trading                           |
//+------------------------------------------------------------------+
bool ConditionToTrade()
  {
   // Exemple : vérifier si le RSI est inférieur à 30
   double rsi = iRSI(Symbol(), PERIOD_H1, 14, PRICE_CLOSE, 0);
   return rsi < 30;
  }
ton

Responded

1
Developer 1
Rating
(144)
Projects
219
32%
Arbitration
16
44% / 25%
Overdue
0
Free
2
Developer 2
Rating
(535)
Projects
613
34%
Arbitration
33
39% / 45%
Overdue
9
1%
Busy
3
Developer 3
Rating
(39)
Projects
65
34%
Arbitration
4
25% / 50%
Overdue
9
14%
Working
4
Developer 4
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
5
Developer 5
Rating
(1)
Projects
1
0%
Arbitration
0
Overdue
0
Free

Project information

Budget
30+ USD
VAT (17%): 5.1 USD
Total: 35.1 USD
For the developer
27 USD