TEST1

MQL5 Эксперты

Техническое задание

//+------------------------------------------------------------------+
//|                        TrailGrid_EA.mq5                          |
//|               Stratégie Trailing Grid - XAUUSD M1                |
//|          Logique : Sell/Buy avec Stop Suiveur Automatique         |
//+------------------------------------------------------------------+
#property copyright "TrailGrid EA"
#property version   "1.00"
#property description "Trailing Grid EA - Stop suiveur double sens"

#include <Trade\Trade.mqh>

//--- Paramètres d'entrée
input group "=== GESTION DES TRADES ==="
input double InpLotSize         = 0.10;   // Taille de lot
input double InpTrailingUSD     = 0.70;   // Écart trailing en USD (ex: 0.70)
input ENUM_ORDER_TYPE InpStart  = ORDER_TYPE_SELL; // Direction du 1er trade

input group "=== SÉCURITÉ ==="
input double InpMaxLossUSD      = 100.0;  // Perte max en USD avant arrêt (0 = désactivé)
input bool   InpTradeOnlyM1     = true;   // Vérifier que le TF est M1

input group "=== IDENTIFICATION ==="
input ulong  InpMagic           = 99901;  // Magic Number
input string InpComment         = "TrailGrid"; // Commentaire des ordres

//--- Variables globales
CTrade  trade;
double  trailLevel  = 0;   // Niveau du stop suiveur actuel
int     direction   = 0;   // 1 = BUY actif | -1 = SELL actif | 0 = inactif
double  pointSize   = 0;   // Taille d'un point pour le symbole

//+------------------------------------------------------------------+
//| Initialisation de l'EA                                           |
//+------------------------------------------------------------------+
int OnInit()
{
   // Vérification du timeframe si activé
   if(InpTradeOnlyM1 && Period() != PERIOD_M1)
   {
      Alert("⚠️ TrailGrid : Ce robot est conçu pour le M1 !");
      return INIT_FAILED;
   }

   // Récupération de la taille du point
   pointSize = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
   if(pointSize == 0)
   {
      Alert("⚠️ Impossible de récupérer la taille du point.");
      return INIT_FAILED;
   }

   trade.SetExpertMagicNumber(InpMagic);
   trade.SetDeviationInPoints(10); // Slippage toléré

   Print("✅ TrailGrid EA démarré | Lot: ", InpLotSize, 
         " | Trailing: ", InpTrailingUSD, " USD | Magic: ", InpMagic);

   // Si aucune position existante, ouvrir le premier trade
   if(!HasPosition())
      OpenFirstTrade();
   else
      RecoverState(); // Récupérer l'état si le robot redémarre

   return INIT_SUCCEEDED;
}

//+------------------------------------------------------------------+
//| Logique principale exécutée à chaque tick                        |
//+------------------------------------------------------------------+
void OnTick()
{
   // Vérification de la perte maximale
   if(InpMaxLossUSD > 0 && GetTotalProfit() <= -InpMaxLossUSD)
   {
      Print("🛑 Perte maximale atteinte (", InpMaxLossUSD, " USD). Arrêt du robot.");
      CloseAllPositions();
      ExpertRemove();
      return;
   }

   // Si aucune position, ouvrir un nouveau trade
   if(!HasPosition())
   {
      OpenFirstTrade();
      return;
   }

   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   //--- SELL actif : le BUY STOP suit le prix à la baisse
   if(direction == -1)
   {
      double newTrail = ask + InpTrailingUSD;

      // Le trail level ne peut que DESCENDRE (jamais remonter)
      if(newTrail < trailLevel)
      {
         trailLevel = newTrail;
         //Print("📉 Trail SELL mis à jour : BUY STOP à ", trailLevel);
      }

      // Le prix remonte et touche le BUY STOP → clôture SELL + ouverture BUY
      if(ask >= trailLevel)
      {
         double profit = GetTotalProfit();
         Print("🔄 Retournement ! SELL clôturé. Profit: +", DoubleToString(profit, 2), " USD");
         CloseAllPositions();
         Sleep(100);
         OpenBuy();
      }
   }

   //--- BUY actif : le SELL STOP suit le prix à la hausse
   else if(direction == 1)
   {
      double newTrail = bid - InpTrailingUSD;

      // Le trail level ne peut que MONTER (jamais redescendre)
      if(newTrail > trailLevel)
      {
         trailLevel = newTrail;
         //Print("📈 Trail BUY mis à jour : SELL STOP à ", trailLevel);
      }

      // Le prix descend et touche le SELL STOP → clôture BUY + ouverture SELL
      if(bid <= trailLevel)
      {
         double profit = GetTotalProfit();
         Print("🔄 Retournement ! BUY clôturé. Profit: +", DoubleToString(profit, 2), " USD");
         CloseAllPositions();
         Sleep(100);
         OpenSell();
      }
   }
}

//+------------------------------------------------------------------+
//| Ouvrir le premier trade selon la direction choisie               |
//+------------------------------------------------------------------+
void OpenFirstTrade()
{
   if(InpStart == ORDER_TYPE_SELL)
      OpenSell();
   else
      OpenBuy();
}

//+------------------------------------------------------------------+
//| Ouvrir un SELL + initialiser le trail level (BUY STOP au-dessus) |
//+------------------------------------------------------------------+
void OpenSell()
{
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   if(trade.Sell(InpLotSize, _Symbol, bid, 0, 0, InpComment))
   {
      direction  = -1;
      trailLevel = ask + InpTrailingUSD; // BUY STOP initial au-dessus
      Print("📥 SELL ouvert à ", bid, " | BUY STOP trailing à ", trailLevel);
   }
   else
   {
      Print("❌ Erreur ouverture SELL : ", trade.ResultRetcodeDescription());
   }
}

//+------------------------------------------------------------------+
//| Ouvrir un BUY + initialiser le trail level (SELL STOP en-dessous)|
//+------------------------------------------------------------------+
void OpenBuy()
{
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   if(trade.Buy(InpLotSize, _Symbol, ask, 0, 0, InpComment))
   {
      direction  = 1;
      trailLevel = bid - InpTrailingUSD; // SELL STOP initial en-dessous
      Print("📥 BUY ouvert à ", ask, " | SELL STOP trailing à ", trailLevel);
   }
   else
   {
      Print("❌ Erreur ouverture BUY : ", trade.ResultRetcodeDescription());
   }
}

//+------------------------------------------------------------------+
//| Clôturer toutes les positions du robot                           |
//+------------------------------------------------------------------+
void CloseAllPositions()
{
   for(int i = PositionsTotal() - 1; i >= 0; i--)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
      {
         if(PositionGetString(POSITION_SYMBOL) == _Symbol &&
            PositionGetInteger(POSITION_MAGIC) == InpMagic)
         {
            if(!trade.PositionClose(ticket))
               Print("❌ Erreur clôture position #", ticket, " : ", trade.ResultRetcodeDescription());
         }
      }
   }
}

//+------------------------------------------------------------------+
//| Vérifier si une position du robot est ouverte                    |
//+------------------------------------------------------------------+
bool HasPosition()
{
   for(int i = 0; i < PositionsTotal(); i++)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
      {
         if(PositionGetString(POSITION_SYMBOL) == _Symbol &&
            PositionGetInteger(POSITION_MAGIC) == InpMagic)
            return true;
      }
   }
   return false;
}

//+------------------------------------------------------------------+
//| Récupérer l'état si le robot redémarre avec une position ouverte |
//+------------------------------------------------------------------+
void RecoverState()
{
   double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);

   for(int i = 0; i < PositionsTotal(); i++)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
      {
         if(PositionGetString(POSITION_SYMBOL) == _Symbol &&
            PositionGetInteger(POSITION_MAGIC) == InpMagic)
         {
            ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE);
            if(type == POSITION_TYPE_SELL)
            {
               direction  = -1;
               trailLevel = ask + InpTrailingUSD;
               Print("♻️ Récupération : SELL actif | BUY STOP à ", trailLevel);
            }
            else if(type == POSITION_TYPE_BUY)
            {
               direction  = 1;
               trailLevel = bid - InpTrailingUSD;
               Print("♻️ Récupération : BUY actif | SELL STOP à ", trailLevel);
            }
            break;
         }
      }
   }
}

//+------------------------------------------------------------------+
//| Calculer le profit total des positions ouvertes du robot         |
//+------------------------------------------------------------------+
double GetTotalProfit()
{
   double total = 0;
   for(int i = 0; i < PositionsTotal(); i++)
   {
      ulong ticket = PositionGetTicket(i);
      if(PositionSelectByTicket(ticket))
      {
         if(PositionGetString(POSITION_SYMBOL) == _Symbol &&
            PositionGetInteger(POSITION_MAGIC) == InpMagic)
         {
            total += PositionGetDouble(POSITION_PROFIT);
         }
      }
   }
   return total;
}

//+------------------------------------------------------------------+
//| Nettoyage à la désactivation                                     |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   Print("🛑 TrailGrid EA arrêté. Raison : ", reason);
}
//+------------------------------------------------------------------+

Откликнулись

1
Разработчик 1
Оценка
(257)
Проекты
320
29%
Арбитраж
34
26% / 65%
Просрочено
10
3%
Свободен
2
Разработчик 2
Оценка
(15)
Проекты
19
16%
Арбитраж
5
40% / 40%
Просрочено
0
Свободен
3
Разработчик 3
Оценка
Проекты
1
0%
Арбитраж
0
Просрочено
1
100%
Работает
4
Разработчик 4
Оценка
(61)
Проекты
89
28%
Арбитраж
24
13% / 58%
Просрочено
7
8%
Работает
5
Разработчик 5
Оценка
(1)
Проекты
1
0%
Арбитраж
0
Просрочено
0
Свободен
6
Разработчик 6
Оценка
(6)
Проекты
7
86%
Арбитраж
0
Просрочено
0
Свободен
7
Разработчик 7
Оценка
(7)
Проекты
7
0%
Арбитраж
2
50% / 0%
Просрочено
1
14%
Работает
8
Разработчик 8
Оценка
Проекты
0
0%
Арбитраж
0
Просрочено
0
Работает
9
Разработчик 9
Оценка
Проекты
0
0%
Арбитраж
0
Просрочено
0
Свободен
Похожие заказы
Need an trailing SL manager which can work with my all open trades (trades may be multiple), Put a fix SL based on entry price and then trail my strictly in my favoured direction, Initial SL shud be confiurable via a small dashboard
Pip killer ntt 100+ USD
Create a forex robot especially for sculping using the 3 ema strategy which consists of the following moving average levels of the 15 ma ,30 ema , 60 ema and 90 which enter potentially on a retest into the ema and targets opposite direction after the retest .Potentially bringing into account that the number of retested emas controlls the number of entreis which for eg. retest of the 15 ema single 0.01 trade is
Need to improve logic in existing coding for Range breakout/breakin EA 1) for timing range like 1am-10am Asian Range with max entry per session like London 1-2 times max entry 10-4pm & US session timings 1-2 entry 4pm - 8pm or 2) candle high low range eg 4pm to 4:30pm - entry logic eg mark 30min candle high low range as given in attached picture with buffer if required to show entry , SL & TP in trade/backtest mode
Make a Robot for mt5 using supertrend indicator for entry in trade with period 2 and multiplier 1.1 using Heiken Ashi candle also with martingle of 2 with maximum step for martingle is 15 step until profit reaches double of total loss. Select time frame 1 minute.Always close the previous trade if in loss then take next trade with martingle of 2 of previous lot in loss. All parameter have the option to change it
Robot que combine 2 indicadores en la ejecución automatica: 1 el Gann High Low y el Donchian Channel (DC) ACTIVO: XAU/USD EN UNA HORA PARA EL DC: período DC = 55 velas displacement/shift = 1 Mas Detalles en este video : https://youtu.be/3jI3cZY89T4?si=YEZAkMvWiq9O8-u9
Hello, I need an Expert Advisor for both MT4 and MT5 based on a recovery/grid trading strategy. Strategy Logic: User manually opens either a Buy or Sell market order. Once the first trade is opened, the EA automatically places an opposite pending order at a user-defined distance. If the pending order gets triggered, the EA places another opposite pending order at the original order price. This cycle continues
📌 Project Overview: I need a full Smart Trade Management System for MetaTrader 4/5. This is a complete trading ecosystem, not a simple EA. 📌 Core Features: Smart Money Management (risk-based lot calculation) Advanced Trading Toolbox (TradingView-style drawing tools) Central Master Dashboard (risk, filters, account control) Multi-account monitoring (MT4/MT5 synchronization) Real-time monitoring (spread, equity
We are seeking an experienced MQL5 developer to build the Guardian EA, a focused circuit-breaker module for MetaTrader 5. Objective Protect capital during adverse moves by temporarily exiting positions at a defined drawdown threshold, while virtually tracking those positions as open. Re-establish the positions only when market conditions stabilize (via ADX) and drawdown recovers to a lower threshold. The goal is full
Hi basically I'm wanting an already made EA scalper that's constantly in and out of trades on the M1 time frame that has good risk management. It knows what it's doing. Most of its trades are profitable and that can start with £100. I am willing to pay up to £1000 for the right scalping bot. If you please have one and you're very confident in it, please allow me to use a live version to see how it does and if I'm
hello good evening All professional programmers! I'd like to request a special services I need a Gold and Silver trading bot like the one in the video, one that works on real accounts. My only request is that I don't pay any money until the bot is built and tested. Thank you very much please contact me as soon as possible for more information

Информация о проекте

Бюджет
50 - 300 USD

Заказчик

Размещено заказов1
Количество арбитражей0