Errors, bugs, questions - page 1647

 
Vasiliy Sokolov:

Please explain the following behaviour:

Is it stable and at all times or on the first tick of the running indicator?

The _LastError value is missing in the wotch window

 
Alexey Navoykov:

Are you sure?

and at the same timeHow do you figure that? If the first is equal, the second will be equal.
Example for both platforms
// MQL4&5-code

#ifdef __MQL5__
  #define show_inputs script_show_inputs
#endif

#property show_inputs
#property strict

sinput double Price1 = 1.234566;
sinput double Price2 = 1.234574;

void NormToConsole( const double Price, const int digits, const string Str )
{
  Print("NormalizeDouble(" + Str + "(=" + DoubleToString(Price, digits + 1) +
        "), " + (string)digits + ") = " + DoubleToString(NormalizeDouble(Price, digits), digits));
}

#define  NORM2CONSOLE(PRICE) NormToConsole(PRICE, 5, #PRICE);

void OnStart()
{  
  NORM2CONSOLE(Price1);
  NORM2CONSOLE(Price2);
  NORM2CONSOLE(Price2 - Price1);    
}
Result
NormalizeDouble(Price1(=1.234566), 5) = 1.23457
NormalizeDouble(Price2(=1.234574), 5) = 1.23457
NormalizeDouble(Price2-Price1(=0.000008), 5) = 0.00001
 

Compilation error

void f( int& i ){ Print( i ); }
void OnStart()
{
        int a, b;
        f( a = 5 ); //error: '=' - parameter passed as reference, variable expected
        f( b = a ); //error: '=' - parameter passed as reference, variable expected
}
 
A100:

Compilation error

void f( int& i ){ Print( i ); }
void OnStart()
{
        int a, b;
        f( a == 5 ); //error: '=' - parameter passed as reference, variable expected
        f( b == a ); //error: '=' - parameter passed as reference, variable expected
}
 
Vitalii Ananev:
In your example the error is justified, my case is different
 
A100:
In your example the error is justified, in my case it is different

I didn't read the code carefully and automatically thought that you have a conditional if statement, but you just have a function called f.

You should pass a variable or some pre-calculated value to the function, not an expression.

void f( int& i ){ Print( i ); }
void OnStart()
{
        int a = 5;
        int b = a;
        f(a); //error: '=' - parameter passed as reference, variable expected
        f(b); //error: '=' - parameter passed as reference, variable expected
}
 
Vitalii Ananev:

You have to pass a variable or some pre-calculated value into the function, not an expression.

What is the difference?

//1.mq5
         a = 5;
         f( a );
//2.mq5
         f( a = 5 );
 
A100:

What is the difference?

In the first case, a variable is passed, in the second, the result of the operation. And who knows what's contrived there for inta

In fact, this reference error has been annoying for a very long time, and it shouldn't be there at all.

 
A100:

What's the difference?

The difference is that in the first case there is no error :)
 

There are some suggestions about ArrayResize function. We need to add possibility to setreserve_size parameterto -1, which would mean using previous set value. Then we wouldn't have to store or carry this value around. It would be enough to firstly resize it with required reserve, and then not to worry about it anymore .Otherwise, it's a constant inconvenience, when you pass an array to some function, which resizes it, but knows nothing about preset reserve on it, and as a result runs it down, leading to unnecessary memory reallocations later. After all, I suppose, this value is stored somewhere for an array. Or is it not?