Errors, bugs, questions - page 951

 
Is it possible to write a function with variable number of parameters in MQL5? For example, as in StringConcatenate(...) or Print(...)?
 
skteks:

I have tested the standard ExpertMACD Expert Advisor in the strategy tester, which is delivered together with MT5, it generates errors:

2013.03.30 19:18:09 Core 2 genetic pass (0, 15) tested with error "OnInit failed" in 46 ms

2013.03.30 19:18:08 Core 1 genetic pass (0, 13) tested with error "OnInit failed" in 32 ms

2013.03.30 19:18:07 Core 2 genetic pass (0, 5) tested with error "OnInit failed" in 0 ms

I found out by searching that the error is in the module: "SignalMACD" when optimizing Fast and Slow MACD periods (when ticking the boxes in the strategy tester parameters).

Has anyone encountered such a problem and how to deal with it? (when there is only one tick it somehow works, but there are errors as soon as you check two ticks)

Set a different range of changes Slow and Fast. The error will disappear. You can just ignore it.

 
w1sp:
Is it possible to write a function with variable number of parameters in MQL5? For example, like in StringConcatenate(...) or Print(...)?
Yes, you can, it's called function overloading.
 
w1sp:
Is it possible to write in MQL5 a function with a variable number of parameters? For example, as in StringConcatenate(...) or Print(...)?

For example, you can make an array whose size will be equal to the number of your parameters as a parameter.

 
I'm interested in a variable number of parameters as in StringConcatenate. Like this: string Concatenate(string s, ...); Is this possible?
 
w1sp:
I'm interested in a variable number of parameters like in StringConcatenate. Something like this: string Concatenate(string s, ...); Is it possible?

Similar is possible. Up to 64 parameters can be passed to a function.

void OnStart()
  {
string s1=Foo("5");
string s2=Foo("5","t");

// string s=Foo(,"5"); // Ошибка
   
  }
//+------------------------------------------------------------------+
string Foo(string i0="", string i1="", string i2="")
{

string rez=i0+i1+i2;

return rez;
} 
 
Snaf:

Similar is possible. Up to 64 parameters can be passed to a function.

And we can get arbitrary types for all the arguments only by overloading? That is, not only string, but also double can be passed to a function, for example. string s = Concatenate("abc",2.0, "def");

 
w1sp:

And arbitrary types for all arguments can be achieved only by overloading? That is, not only string, but also double can be passed to the function, for example. string s = Concatenate("abc",2.0, "def");

void OnStart()
  {
//string s1=Foo("5");  // Это теперь ошибка. Компилятор не знаек какой функцией из двух пользоваться
string s2=Foo("5",3.0);

// string s=Foo(,"5"); // Ошибка
   
  }
//+------------------------------------------------------------------+
string Foo(string i0="", string i1="", string i2="")
{

string rez=i0+i1+i2;

return rez;
}

string Foo(string i0="", double i1=2.0, string i2="")
{
string rez;
if (i1>2.0) {rez=i0+i2;} else rez=i0+"99"+i2;

return rez;
}  
 
Snaf:
Thank you. Got it. It's enough to make a function with 64 arguments of type string and add default value to all except the first one.
Документация по MQL5: Основы языка / Типы данных / Тип string
Документация по MQL5: Основы языка / Типы данных / Тип string
  • www.mql5.com
Основы языка / Типы данных / Тип string - Документация по MQL5
 
Hello. After upgrading the MT5 build, the indicator is no longer displayed normally in the tester, in the terminal itself it is displayed normally. The indicator is quite complex and resource intensive (ZUP), I translate it from MT4 to MT5. In the tester, Bild 756 ZigZag line is displayed normally, in the tester after Bild 770 - ZigZag price values are correct, but the timeframe is not correct (shifted, not evenly) ZigZag - output buffer. At the same time, the graphical objects (triangles, lines, etc., which incidentally are based on output buffers data (ZigZag as well)) are displayed normally. Please help me to understand this.
Reason: