Skip to content
TheChatArchiveThe Chat Archive
o4-mini-2025-04-16· OpenAIHugging Face LMArena Human Preference 140K

Proszę o napisanie w całości poprawionego kodu

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with MiniMaxminimax-m1’s answer.
  1. User

    Proszę o napisanie w całości poprawionego kodu

  2. Assistant
    //+------------------------------------------------------------------+
    //|                                    SymbolsScanner_MT5.mq5        |
    //|                                Poprawiony kod z obsługą sesji   |
    //+------------------------------------------------------------------+
    #property copyright "AI Assistant"
    #property link      ""
    #property version   "1.00"
    #property strict
    
    #include <Trade\SymbolInfo.mqh>  // Dla ENUM_DAY_OF_WEEK
    
    //--- inputy
    input int           EMA_Short_Period = 55;
    input int           EMA_Fast_Period  = 21;
    input int           EMA_Slow_Period  = 144;
    input ENUM_TIMEFRAMES TF             = PERIOD_H4;
    input int           TimerInterval    = 60;   // Interwał timera w sekundach
    
    //--- etykiety (prefiksy) dla obiektów
    string label_long  = "SYMBOLS_LONG_";
    string label_short = "SYMBOLS_SHORT_";
    
    //+------------------------------------------------------------------+
    //| Sprawdza, czy obecnie jest otwarta sesja notowań dla symbolu     |
    //+------------------------------------------------------------------+
    bool IsSessionActive(const string symbol)
      {
       // Pobieramy czas otwarcia i zamknięcia sesji kwotowań (w minutach od 0:00) dla bieżącego dnia tygodnia
       int start_min=0, end_min=0;
       ENUM_DAY_OF_WEEK dow=(ENUM_DAY_OF_WEEK)TimeDayOfWeek(TimeCurrent());
       if(!SymbolInfoSessionQuote(symbol, dow, start_min, end_min))
          return(true); // brak danych sesyjnych → zakładamy aktywną sesję
    
       int cur_h=TimeHour(TimeCurrent());
       int cur_m=TimeMinute(TimeCurrent());
       int cur_min=cur_h*60+cur_m;
       // Sesja aktywna, gdy bieżący czas mieści się w przedziale [start_min, end_min]
       return(cur_min>=start_min && cur_min<=end_min);
      }
    
    //+------------------------------------------------------------------+
    //| Sprawdza warunki LONG/SHORT dla danego symbolu                   |
    //+------------------------------------------------------------------+
    void CheckConditions(const string symbol, bool &long_condition, bool &short_condition)
      {
       long_condition  = false;
       short_condition = false;
    
       const int bars_needed = 2;
       const int start_pos   = 1; // bar 1 = ostatni zamknięty
    
       // Pobieramy ceny
       MqlRates rates[];
       if(CopyRates(symbol, TF, start_pos, bars_needed, rates)!=bars_needed)
         {
          //Print("CopyRates failed for ",symbol);
          return;
         }
    
       // Handle wskaźników EMA
       int h_short = iMA(symbol, TF, EMA_Short_Period, 0, MODE_EMA, PRICE_CLOSE);
       int h_fast  = iMA(symbol, TF, EMA_Fast_Period,  0, MODE_EMA, PRICE_CLOSE);
       int h_slow  = iMA(symbol, TF, EMA_Slow_Period,  0, MODE_EMA, PRICE_CLOSE);
       if(h_short==INVALID_HANDLE||h_fast==INVALID_HANDLE||h_slow==INVALID_HANDLE)
         {
          if(h_short!=INVALID_HANDLE) IndicatorRelease(h_short);
          if(h_fast !=INVALID_HANDLE) IndicatorRelease(h_fast);
          if(h_slow !=INVALID_HANDLE) IndicatorRelease(h_slow);
          return;
         }
    
       // Bufory EMA
       double ema_short[], ema_fast[], ema_slow[];
       bool ok=true;
       ok&=(CopyBuffer(h_short,0,start_pos,bars_needed,ema_short)==bars_needed);
       ok&=(CopyBuffer(h_fast, 0,start_pos,bars_needed,ema_fast )==bars_needed);
       ok&=(CopyBuffer(h_slow, 0,start_pos,bars_needed,ema_slow )==bars_needed);
       // Zwolnienie handle'i
       IndicatorRelease(h_short);
       IndicatorRelease(h_fast);
       IndicatorRelease(h_slow);
       if(!ok) return;
    
       // Indeksy: 0=poprzedni zamknięty, 1=aktualny zamknięty
       const int prev_bar=0, curr_bar=1;
    
       // WARUNKI LONG
       bool cross_up    = (rates[prev_bar].close<ema_fast[prev_bar]) &&
                          (rates[curr_bar].close>ema_fast[curr_bar]);
       bool fast_above  = (ema_fast[curr_bar]>ema_short[curr_bar]) &&
                          (ema_fast[curr_bar]>ema_slow[curr_bar]);
       long_condition   = cross_up && fast_above;
    
       // WARUNKI SHORT
       bool cross_down  = (rates[prev_bar].close>ema_fast[prev_bar]) &&
                          (rates[curr_bar].close<ema_fast[curr_bar]);
       bool fast_below  = (ema_fast[curr_bar]<ema_short[curr_bar]) &&
                          (ema_fast[curr_bar]<ema_slow[curr_bar]);
       short_condition  = cross_down && fast_below;
      }
    
    //+------------------------------------------------------------------+
    //| Rysuje listę symboli w wielu wierszach                           |
    //+------------------------------------------------------------------+
    void DrawSymbolsListMultiline(const string base_label,
                                  const string header,
                                  string &symbols[],
                                  int y_offset,
                                  color clr)
      {
       const int chart_id = 0;
       string prefix     = base_label + IntegerToString(ChartID());
    
       // Usuń poprzednie obiekty
       for(int i=0;i<200;i++)
          ObjectDelete(chart_id, prefix + "_" + IntegerToString(i));
       ObjectDelete(chart_id, prefix + "_header");
    
       // Nagłówek
       string hdr = prefix + "_header";
       ObjectCreate(chart_id, hdr, OBJ_LABEL, 0, 0, 0);
       ObjectSetInteger(chart_id, hdr, OBJPROP_CORNER, CORNER_LEFT_UPPER);
       ObjectSetInteger(chart_id, hdr, OBJPROP_XDISTANCE,10);
       ObjectSetInteger(chart_id, hdr, OBJPROP_YDISTANCE,y_offset);
       ObjectSetInteger(chart_id, hdr, OBJPROP_COLOR,   clr);
       ObjectSetInteger(chart_id, hdr, OBJPROP_FONTSIZE,10);
       ObjectSetString (chart_id, hdr, OBJPROP_TEXT,     header);
    
       // Lista symboli
       int cnt=ArraySize(symbols);
       if(cnt<=0) cnt=1;  // co najmniej jedna linia
       for(int i=0;i<cnt;i++)
         {
          string txt = (i<ArraySize(symbols) ? symbols[i] : "Brak sygnałów");
          string obj = prefix + "_" + IntegerToString(i);
          ObjectCreate(chart_id, obj, OBJ_LABEL, 0, 0, 0);
          ObjectSetInteger(chart_id, obj, OBJPROP_CORNER, CORNER_LEFT_UPPER);
          ObjectSetInteger(chart_id, obj, OBJPROP_XDISTANCE,10);
          ObjectSetInteger(chart_id, obj, OBJPROP_YDISTANCE,y_offset + 20 + i*15);
          ObjectSetInteger(chart_id, obj, OBJPROP_COLOR,   clr);
          ObjectSetInteger(chart_id, obj, OBJPROP_FONTSIZE,10);
          ObjectSetString (chart_id, obj, OBJPROP_TEXT,     txt);
         }
      }
    
    //+------------------------------------------------------------------+
    //| Timer: co TimerInterval sekund                                    |
    //+------------------------------------------------------------------+
    void OnTimer()
      {
       int total = SymbolsTotal(false);
       string symbols_long[], symbols_short[];
       ArrayResize(symbols_long, total);
       ArrayResize(symbols_short,total);
       int idxL=0, idxS=0;
    
       for(int i=0;i<total;i++)
         {
          string sym = SymbolName(i,false);
          if(!SymbolSelect(sym,true)) continue;
    
          // Pomijamy, gdy sesja zamknięta
          if(!IsSessionActive(sym)) continue;
    
          bool lc=false, sc=false;
          CheckConditions(sym, lc, sc);
          if(lc) symbols_long [idxL++] = sym;
          if(sc) symbols_short[idxS++] = sym;
         }
    
       // Dostosuj rozmiar tablic
       ArrayResize(symbols_long, idxL>0 ? idxL : 0);
       ArrayResize(symbols_short,idxS>0 ? idxS : 0);
    
       // Rysuj na wykresie
       DrawSymbolsListMultiline(label_long,
                                "LONG ("+EnumToString(TF)+"):",
                                symbols_long,
                                30,
                                clrDarkGreen);
       DrawSymbolsListMultiline(label_short,
                                "SHORT("+EnumToString(TF)+"):",
                                symbols_short,
                                350,
                                clrDarkRed);
      }
    
    //+------------------------------------------------------------------+
    //| Inicjalizacja                                                   |
    //+------------------------------------------------------------------+
    int OnInit()
      {
       EventSetTimer(TimerInterval);
       return(INIT_SUCCEEDED);
      }
    
    //+------------------------------------------------------------------+
    //| Deinitializacja                                                 |
    //+------------------------------------------------------------------+
    void OnDeinit(const int reason)
      {
       // Usuń wszystkie obiekty
       for(int i=0;i<200;i++)
         {
          ObjectDelete(0, label_long  + IntegerToString(ChartID()) + "_" + IntegerToString(i));
          ObjectDelete(0, label_short + IntegerToString(ChartID()) + "_" + IntegerToString(i));
         }
       ObjectDelete(0, label_long  + IntegerToString(ChartID()) + "_header");
       ObjectDelete(0, label_short + IntegerToString(ChartID()) + "_header");
       EventKillTimer();
      }
    
    //+------------------------------------------------------------------+
    //| OnTick (puste, bo pracujemy na timerze)                          |
    //+------------------------------------------------------------------+
    void OnTick()
      {
      }
    //+------------------------------------------------------------------+
    

    Wyjaśnienie zmian:

    1. Dodano funkcję IsSessionActive(), która używa SymbolInfoSessionQuote() i TimeCurrent() do weryfikacji, czy dany symbol jest notowany w bieżącym momencie.
    2. W OnTimer() pomijamy symbole, których sesja jest zamknięta.
    3. Poprawiono użycie prefiksów label_long / label_short w DrawSymbolsListMultiline(), aby obiekty były poprawnie czyszczone i odświeżane.
    4. Zmieniono interwał timera na 60 s (parametr TimerInterval), aby zmniejszyć obciążenie.

    Kod ten zapewni, że sygnały LONG/SHORT będą wyszukiwane tylko wtedy, gdy sesja notowań jest otwarta, a lista na wykresie będzie zawsze odświeżona.

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