Errors, bugs, questions - page 1525

 
Yuri Evseenkov:

MT4. Once again I would like to draw your attention to the peculiarities of the initialisation of global program variables.

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

Slawa, 2016.02.24 07:34

Queue. The application is only two hours old.

In general, such questions should be asked on the forum. Because many may be affected. I'll take the liberty of quoting you and immediately answering

This is planned behaviour. In fact, it is explicitly described in the documentation

Upload and download involve a complete reinitialization of everything.

In five, as you've rightly noticed, the situation is similar.

It's true, it was historically in four, and we changed this behavior at first when changing to new MQL4 (to have it behave like in experts, i.e. as you expect). But a lot of questions arose with the old indicators, that were based on this initialization. We were forced to return

In the five, this was the case immediately because of the architecture. When you change the parameters, the old indicator with the old parameters is destroyed and a new indicator with changed parameters is created.


 
Alexey Kozitsyn:

Thanks. Conclusion - a quote from documentation: "... predefined function OnInit(), the purpose of which is correct initialization of all global and static variables of the program."

So zero or default all global variables or arrays toOnInit().

События клиентского терминала - Программы MQL4 - Справочник MQL4
События клиентского терминала - Программы MQL4 - Справочник MQL4
  • docs.mql4.com
События клиентского терминала - Программы MQL4 - Справочник MQL4
 

1. I create an array of the form:

CArrayString list[5];

2. I try to call method list via <Ctrl+Space>.

list[0].
The list of methods doesn't appear. Is it supposed to be like this?
 
Andrey Voytenko:

1. I create an array of the form:

2. I try to call the list of methods in the code via <Ctrl+Space>.

The list of methods does not appear. Is it supposed to be like this?

Let me try to make a guess. If there are other errors in the code besides the fact that the method/member is not specified, the list will not always appear.

Tried it. No, wrong assumption. But a few repeated presses of the combination helped.

 

Alexey Kozitsyn:

But a few repeated presses of the combination helped.

Unfortunately, your recipe doesn't work for me.
 
Andrey Voytenko:
Unfortunately your recipe doesn't work for me.
No, that's right, if there's an error in the code, the list of open members/methods doesn't appear. But if there is no error... then trouble.
 

1. Simple code:

uint a=50;
int b=-20;
Print(fmax(a,b));

result: 50

2. Adding modifier input:

input uint  a=50;
int b=-20;
Print(fmax(a,b));

result: 4294967276

Expected a result of 50. Where am I wrong?

 
Andrey Voytenko:

1. Simple code:

result: 50

2. We add a modifier input:

result: 4294967276

I was expecting a result of 50. Where am I wrong?

fmax compares two double numbers. So it goes like this:

//+------------------------------------------------------------------+
//|                                                         Test.mq5 |
//|                        Copyright 2016, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.01"
#property script_show_inputs
//---
input uint a=50;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//uint a=50;
   int b=-20;
   Print("\"uint a=50\" as double:",DoubleToString((double)a,8));
   Print("\"int b=-20\" as double:",DoubleToString((double)b,8));
   Print(DoubleToString(fmax((double)b,(double)a),8));
  }
//+------------------------------------------------------------------+

and the result:

2016.03.03 16:00:24.821 Test (EURUSD,D1)        "uint a=50" as double:50.00000000
2016.03.03 16:00:24.821 Test (EURUSD,D1)        "int b=-20" as double:-20.00000000
2016.03.03 16:00:24.821 Test (EURUSD,D1)        50.00000000
Files:
Test.mq5  2 kb
 
Karputov Vladimir:

fmax compares two double numbers. So it goes like this:

In MQL, an implicit type conversion is declared and performed. In particular uint -> double.

The question is why it does not work correctly with input variables.

 
Andrey Voytenko:

1. Simple code:

result: 50

2. Adding the input modifier:

result: 4294967276.

I was expecting a result of 50. Where am I wrong?

Please give me the full code.

There are 2 possibilities here and both are wrong.

1. The code is executed outside any functions.

2. input variable is declared inside the function

Reason: