Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek-v3-0324· DeepSeekHugging Face Arena Expert 5K

//+------------------------------------------------------------------+ // AGENTDALOA //…

  1. User

    //+------------------------------------------------------------------+ //| AGENT_DALOA | //| Copyright 2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property strict

    #include <Trade\Trade.mqh>

    // --- Paramètres d'entrée --- input double LotSize = 0.01; input long MagicNumber = 7777777; input int MaxOpenTrades = 1; // Max 1 trade par symbole input bool CloseAfter60s = true; // Activer/désactiver fermeture à 60s

    // --- Objets globaux --- CTrade trade;

    // --- Symboles et timeframes --- string symboles[] = {"EURUSD", "GBPUSD", "XAUUSD", "USOIL", "WHEAT"}; ENUM_TIMEFRAMES timeframes[] = {PERIOD_M1, PERIOD_H1, PERIOD_D1};

    //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { trade.SetExpertMagicNumber(MagicNumber); trade.SetTypeFilling(ORDER_FILLING_IOC); Print("✅ AGENT_DALOA initialisé !"); return(INIT_SUCCEEDED); }

    //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // --- 1. Analyse des signaux --- for(int s = 0; s < ArraySize(symboles); s++) { string symbole = symboles[s]; if(!SymbolInfoInteger(symbole, SYMBOL_TRADE_MODE)) continue;

        for(int tf = 0; tf < ArraySize(timeframes); tf++)
        {
            ENUM_TIMEFRAMES tf_curr = timeframes[tf];
    
            // RSI
            int rsiHandle = iRSI(symbole, tf_curr, 14, PRICE_CLOSE);
            double rsiVal[1];
            if(rsiHandle == INVALID_HANDLE || CopyBuffer(rsiHandle, 0, 0, 1, rsiVal) != 1) continue;
    
            // MACD
            int macdHandle = iMACD(symbole, tf_curr, 12, 26, 9, PRICE_CLOSE);
            double macdMain[1], macdSig[1];
            if(macdHandle == INVALID_HANDLE ||
               CopyBuffer(macdHandle, 0, 0, 1, macdMain) != 1 ||
               CopyBuffer(macdHandle, 1, 0, 1, macdSig) != 1) continue;
    
            // Ichimoku
            int ichiHandle = iIchimoku(symbole, tf_curr, 9, 26, 52);
            double tenkan[1], kijun[1], spanA[1], spanB[1];
            if(ichiHandle == INVALID_HANDLE ||
               CopyBuffer(ichiHandle, 0, 0, 1, tenkan) != 1 ||
               CopyBuffer(ichiHandle, 1, 0, 1, kijun) != 1 ||
               CopyBuffer(ichiHandle, 2, 0, 1, spanA) != 1 ||
               CopyBuffer(ichiHandle, 3, 0, 1, spanB) != 1) continue;
    
            MqlTick price;
            if(!SymbolInfoTick(symbole, price)) continue;
    
            // Conditions d'achat
            if(tenkan[0] > spanA[0] &&
               tenkan[0] > spanB[0] &&
               rsiVal[0] > 50 &&
               macdMain[0] > macdSig[0] &&
               price.ask > spanA[0])
            {
                if(CountPositions(symbole) < MaxOpenTrades)
                {
                    double sl = price.bid * 0.99;
                    double tp = price.ask * 1.02;
                    if(trade.Buy(LotSize, symbole, price.ask, sl, tp, "AGENT_DALOA"))
                    {
                        Print("✅ Achat sur ", symbole, " | TF: ", EnumToString(tf_curr));
                        ObjectCreate(0, "Buy_"+symbole+"_"+(string)TimeCurrent(), OBJ_ARROW_BUY, 0, TimeCurrent(), price.ask);
                    }
                }
            }
        }
    }
    
    // --- 2. Gestion des positions existantes ---
    for(int i = PositionsTotal() - 1; i >= 0; i--)
    {
        if(!PositionSelectByIndex(i)) continue;
        if(PositionGetInteger(POSITION_MAGIC) != MagicNumber) continue;
    
        string sym = PositionGetString(POSITION_SYMBOL);
        ulong ticket = PositionGetInteger(POSITION_TICKET);
        datetime openTime = (datetime)PositionGetInteger(POSITION_TIME);
    
        // Fermeture après 60 secondes (optionnel)
        if(CloseAfter60s && (TimeCurrent() - openTime > 60))
        {
            if(trade.PositionClose(ticket))
            {
                Print("CloseOperation: ", ticket, " fermée après 60s");
            }
            continue; // Pas besoin de modifier SL/TP si on ferme
        }
    
        // Mise à jour SL/TP
        double bid = SymbolInfoDouble(sym, SYMBOL_BID);
        double ask = SymbolInfoDouble(sym, SYMBOL_ASK);
        double sl = bid * 0.99;
        double tp = ask * 1.02;
    
        // Ne modifier que si nécessaire (éviter les requêtes inutiles)
        if(MathAbs(PositionGetDouble(POSITION_SL) - sl) > _Point ||
           MathAbs(PositionGetDouble(POSITION_TP) - tp) > _Point)
        {
            if(!trade.PositionModify(ticket, sl, tp))
            {
                Print("❌ Erreur modification SL/TP pour ticket ", ticket);
            }
        }
    }
    

    }

    //+------------------------------------------------------------------+ //| Compte le nombre de positions ouvertes pour un symbole | //+------------------------------------------------------------------+ int CountPositions(string symbol) { int count = 0; for(int i = PositionsTotal() - 1; i >= 0; i--) { if(PositionSelectByIndex(i) && PositionGetInteger(POSITION_MAGIC) == MagicNumber && PositionGetString(POSITION_SYMBOL) == symbol) { count++; } } return count; }

    //+------------------------------------------------------------------+ //| Fonctions de rappel standard | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } void OnTimer() { } void OnTrade() { } void OnTradeTransaction(const MqlTradeTransaction& trans, const MqlTradeRequest& request, const MqlTradeResult& result) { } double OnTester() { return(0.0); } void OnTesterInit() { } void OnTesterPass() { } void OnTesterDeinit() { } void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) { } void OnBookEvent(const string& symbol) { }

  2. DeepSeek Assistant

    Analyse du code AGENT_DALOA

    Je vais analyser ce code MQL5 pour un EA de trading multi-symboles et multi-timeframes.

    Points forts du code

    1. Architecture multi-symboles/multi-timeframes : L'EA analyse plusieurs instruments (EURUSD, GBPUSD, etc.) sur différents timeframes (M1, H1, D1).

    2. Indicateurs techniques utilisés :

      • RSI (14 périodes)
      • MACD (12,26,9)
      • Ichimoku (9,26,52)
    3. Gestion des positions :

      • Limite le nombre de trades ouverts par symbole (MaxOpenTrades)
      • Option de fermeture automatique après 60 secondes
      • Mise à jour dynamique des SL/TP
    4. Bonnes pratiques :

      • Vérification des handles d'indicateurs
      • Gestion des erreurs avec messages de log
      • Magic number pour identifier les trades de l'EA

    Points d'amélioration

    1. Gestion des risques :

      • Le lot est fixe (0.01) - pourrait être dynamique en fonction du capital
      • SL/TP fixes (1% et 2%) - pas d'adaptation à la volatilité
    2. Optimisation des performances :

      • Les indicateurs sont recalculés à chaque tick - pourrait être optimisé
      • Beaucoup de boucles imbriquées qui pourraient être simplifiées
    3. Conditions de trading :

      • Stratégie uniquement basée sur des indicateurs - pourrait inclure l'analyse de prix
      • Pas de filtre de tendance globale
    4. Robustesse :

      • Pas de vérification des marges/disponibilité avant le trade
      • Pas de gestion des erreurs de marché (requotes, etc.)

    Conclusion

    Cet EA montre une bonne base pour un système multi-symboles, mais pourrait être amélioré avec :

    • Une meilleure gestion des risques
    • Des conditions de trading plus sophistiquées
    • Une optimisation des performances
    • Une gestion plus robuste des erreurs

    Voulez-vous que je développe plus précisément l'un de ces aspects d'amélioration ?

  3. User

    result of expression not used AGENT_DALOA.mq5 144 477 errors, 1 warnings 7 1

  4. DeepSeek Assistant

    The error "result of expression not used" typically occurs when you call a function but don't use its return value. In your code, this is happening at line 144 with the ObjectCreate() function.

    Fix for the Error

    The issue is that you're calling ObjectCreate() but not checking its return value. Here's how to fix it:

    // Replace this line:
    ObjectCreate(0, "Buy_"+symbole+"_"+(string)TimeCurrent(), OBJ_ARROW_BUY, 0, TimeCurrent(), price.ask);
    
    // With this:
    if(!ObjectCreate(0, "Buy_"+symbole+"_"+(string)TimeCurrent(), OBJ_ARROW_BUY, 0, TimeCurrent(), price.ask))
    {
        Print("Failed to create buy arrow for ", symbole);
    }
    

    Additional Recommendations

    1. Check all function returns:

      • Similar checks should be added for other functions like PositionSelectByIndex(), SymbolInfoTick(), etc.
    2. Error handling improvements:

    if(!SymbolInfoTick(symbole, price))
    {
        Print("Failed to get tick data for ", symbole);
        continue;
    }
    
    1. For the warning (likely unused functions):
      • Either implement the empty callback functions properly
      • Or remove them if not needed (like OnTimer() if you're not using timers)

    Complete Fixed Section Example

    if(trade.Buy(LotSize, symbole, price.ask, sl, tp, "AGENT_DALOA"))
    {
        Print("✅ Achat sur ", symbole, " | TF: ", EnumToString(tf_curr));
        if(!ObjectCreate(0, "Buy_"+symbole+"_"+(string)TimeCurrent(), OBJ_ARROW_BUY, 0, TimeCurrent(), price.ask))
        {
            Print("❌ Failed to create buy arrow for ", symbole);
        }
    }
    else
    {
        Print("❌ Buy failed on ", symbole, " | Error: ", GetLastError());
    }
    

    This change will:

    1. Eliminate the "result not used" error
    2. Provide better error logging
    3. Make your code more robust

    Would you like me to review any other specific parts of the code for similar issues?

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.