Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 566

 

How do I declare my optimization criterion in 610 build, on my old EA?

The Expert Advisor is running on the 610 build.

For example, on MQL5 the code is as follows:

double OnTester()
{
double prof=0.0;
prof=TesterStatistics(STAT_PROFIT);

  return(prof);
}

If I place it on Expert Advisor before it starts, Custom column does not appear.

And the second question: Old EAs show a yellow message during compilation: function must return a value.

Example line.

if(Work==false){Alert("Критическая ошибка. Эксперт не работает.");return;}
 
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

//--- параметры для записи данных в файл
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
string             InpFileName="";
int t=0;
int file_handle=-2;
double mass[];
int OnInit()
  {
   Comment("Start");
   InpFileName=StringConcatenate(WindowExpertName(),".csv");      // Имя файла  
 
   ResetLastError();
   file_handle=FileOpen(WindowExpertName()+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV);   
   return(INIT_SUCCEEDED);
  }
void OnTick()
  {
   Comment(t);
   if(file_handle!=INVALID_HANDLE)
     {
      t++;
      ArrayResize(mass,t+1,10000);
      mass[t]=Ask;
      //--- запишем время сигналов и их значения в файл
      for(int i=0; i<ArraySize(mass); i++)
       FileWrite(file_handle,mass[t]);
      //--- закрываем файл
      FileClose(file_handle);
     }
   else
      PrintFormat("Не удалось открыть файл %s, Код ошибки = %d",InpFileName,GetLastError());
  }
//+------------------------------------------------------------------+

I can't figure out how to write to the next line...

I'm trying to write each quote on a new line and it's not working ....

 

I am testing an EA with a custom indicator. Sometimes trades are opened in accordance with the conditions, and other times it is not clear on what principle. I start visualization, the indicator is drawn as it should be, but deals do not always coincide with the indicator. I tried to check the problematic areas with the alerts, but the indicator in the Expert Advisor shows zeros as well. I do not understand what the problem is, if the indicator is drawn correctly when testing, where are the indicator values passed to the EA?

The code is in the Expert Advisor:
double line=iCustom(NULL,0,"Ttest3",Period_MA_1,p2,p3,p4,1,1);

if (line >0){Opn_B=true;}
if (line <=0){Cls_B=true;}
 
VOLDEMAR:

I can't figure out how to write to the next line...

I'm trying to write each quote on a new line and it's not working ....


FileSeek
 
Forexman77:

I am testing an EA with a custom indicator. Sometimes trades are opened in accordance with the conditions, and other times it is not clear on what principle. I start visualization, the indicator is drawn as it should be, but deals do not always coincide with the indicator. I tried to check the problematic areas with the alerts, but the indicator in the Expert Advisor shows zeros as well. I do not understand what the problem is, if the indicator is drawn correctly during the test, where are the indicator values passed to the Expert Advisor?

The code is in the Expert Advisor:

maybe the problem is in the EA?
 
Vladon:

maybe the problem is with the advisor?
I honestly don't know myself. I run a single visual test indicator above zero, in a percentage of seven, a trade opens, in the rest it does not.
 

An error has occurred that I don't understand:

'li_cnt' - undeclared identifier

in the line:

    return (li_cnt);

this line is in the function:

// 1.9 Инициализация рабочего массива. ====================================================================================================
int fInit_ArrayINT (int& fia_INT[],                                              // Инициализируемый массив
                    string fs_List,                                              // Инициализируемые значения в строке
                    int fi_Range,                                                // Размер массива
                    double fd_Factor = 1.0,                                      // множитель
                    string fs_NameArray = "",                                    // имя возвращаемого массива
                    string fs_Delimiter = ",")                                   // Разделитель значений в строке
{
//----
    //---- Ищем в строке разделитель - признак наличия в строке > 1 параметра
    if (StringFind (fs_List, fs_Delimiter) == -1) return (1);
    else
    {
        string lsa_TMP[];
        int li_cnt = fGet_StrArrayFromLine (fs_List, lsa_TMP, ",");
  
        if (fi_Range > 0)
        {
            if (li_cnt != fi_Range)
            {
                Print (fs_NameArray, ": не соотвествие в размерности массива !!!");
                li_cnt = fi_Range;
            }
        }
        fCreat_StrToInt (lsa_TMP, fia_INT, li_cnt, fd_Factor, fs_NameArray);
    }
//----
    return (li_cnt);
}
Variable li_cnt is declared as seen. The compiler swears that it's not declared. What does this mean?
 
hoz:

An error has occurred that I don't understand:

in the line:

this line is in the function:

Variable li_cnt is declared as seen. The compiler swears that it's not declared. What does this mean?


Because your variable is declared inside if else
 
hoz:

An error has occurred that I don't understand:

in the line:

this line is in the function:

Variable li_cnt is declared as seen. The compiler swears that it's not declared. What does this mean?

// 1.9 Инициализация рабочего массива. ====================================================================================================
int fInit_ArrayINT (int& fia_INT[],                                              // Инициализируемый массив
                    string fs_List,                                              // Инициализируемые значения в строке
                    int fi_Range,                                                // Размер массива
                    double fd_Factor = 1.0,                                      // множитель
                    string fs_NameArray = "",                                    // имя возвращаемого массива
                    string fs_Delimiter = ",")                                   // Разделитель значений в строке
{
//----
int li_cnt=0;
    //---- Ищем в строке разделитель - признак наличия в строке > 1 параметра
    if (StringFind (fs_List, fs_Delimiter) == -1) return (1);
    else
    {
        string lsa_TMP[];
        li_cnt = fGet_StrArrayFromLine (fs_List, lsa_TMP, ",");
  
        if (fi_Range > 0)
        {
            if (li_cnt != fi_Range)
            {
                Print (fs_NameArray, ": не соотвествие в размерности массива !!!");
                li_cnt = fi_Range;
            }
        }
        fCreat_StrToInt (lsa_TMP, fia_INT, li_cnt, fd_Factor, fs_NameArray);
    }
//----
    return (li_cnt);
}

 

AlexeyVik, Vladon,

Yes, as is usually the case, it's quite obvious. It's either my inattention or overwork. Thanks for the tip.

Another error has occurred, not even an error, but a warning in the function:

// 1.5 Возвращает массив INT из элементов массива STRING. =================================================================================
void fCreat_StrToInt (string& fsa_Value[],                                     // Массив элементов string
                      int& fia_OUT[],                                          // Возвращаемый массив int
                      int fi_IND,                                              // Количество ячеек в массиве
                      int fi_Factor = 1,                                       // Множитель
                      string fs_NameArray = "")                                // Имя возвращаемого массива
{
    int    li_size = ArraySize (fsa_Value);
    string ls_row = "";
//----
    ArrayResize (fia_OUT, fi_IND);
    
    for (int li_int = 0; li_int < fi_IND; li_int++)
    {
        if (li_int < li_size)
        {
            fia_OUT[li_int] = StrToInteger (fsa_Value[li_int]) * fi_Factor;
        }
        else
        {
            fia_OUT[li_int] = StrToDouble (fsa_Value[li_size - 1]) * fi_Factor;
        }
        ls_row = StringConcatenate (ls_row, fs_NameArray, "[", li_int, "] = ", fia_OUT[li_int], "; ");
    }
    
    if (fs_NameArray != "") Print (ls_row);
//----
}

On the line:

            fia_OUT[li_int] = StrToDouble (fsa_Value[li_size - 1]) * fi_Factor;
The code seems to be fine. Should these warnings be ignored?